Move cp-editing, cp-lily, cp-lisp into init.org

This commit is contained in:
contrapunctus 2022-01-13 21:10:16 +05:30
parent 3ae8385c70
commit 9b9c28b542
4 changed files with 612 additions and 603 deletions

View File

@ -1,290 +0,0 @@
;;;; Editing improvements
;; fix Emacs' definition of a sentence
(setq sentence-end-double-space nil)
;; the utter basics
(general-define-key
"C-h" 'backward-delete-char
"C-w" 'backward-kill-word
"C-u" 'cp-kill-line-0
;; A better solution would be to hack kill-line/kill-visual-line to
;; kill the region if a region is active. The flexibility of those
;; functions is very desirable - you can delete from point to line
;; end, clear a line to enter some other text on it (C-a C-k/"a k"),
;; or delete one or more whole lines (C-1 C-k/"1 k" or C-<num>
;; C-k/"<num> k").
;; "C-y" 'whole-line-or-region-yank
"C-S-k" 'whole-line-or-region-kill-region
"C-," 'backward-paragraph
"C-." 'forward-paragraph
"C-<" 'beginning-of-buffer
"C->" 'end-of-buffer)
(define-key isearch-mode-map (kbd "C-h") 'isearch-delete-char)
(defun cp-kill-line-0 ()
(interactive)
(kill-line 0))
(global-unset-key (kbd "C-x C-r"))
(general-define-key
:prefix "C-x C-r"
"C-i" 'string-insert-rectangle
"C-r" 'replace-rectangle
"C-k" 'kill-rectangle)
(defun cp/downcase-dwim (arg)
"Like `downcase-word', but if region is active, run
`downcase-region' instead. Unlike `downcase-region', rectangular
regions are handled correctly as well.")
;; open-line should always move to the beginning of the current line
;; first, so one can run it anywhere. I also want it to indent it to
;; the next or the previous line...
;; These affect org-meta-return and org-insert-heading-respect-content
;;
;; (defadvice open-line
;; (before open-line-bol activate)
;; (beginning-of-visual-line))
;; (defadvice open-line
;; (after open-line-indent activate)
;; (if (not (looking-at "\\** "))
;; (indent-for-tab-command)))
;; (global-set-key (kbd "C-o") 'open-line)
(defun cp/open-line ()
"The opposite of `cp/open-line-before'. Start a new line below
the current line, regardless of where point is in the current
line. Will not affect the content of the current line. Applies
the correct indentation according to the mode."
(interactive)
(progn
(end-of-line)
(electric-indent-just-newline t)
(indent-according-to-mode)))
(defun cp/open-line-before (arg)
"Like `open-line' but a bit more sane.
In org-mode, run org-open-line.
In other modes, insert a newline above the current line,
regardless of where point is in current line. Will not affect
content of current line. Applies the correct indentation
according to the mode."
(interactive "p")
(if (and (equal major-mode 'org-mode)
(org-at-table-p))
(org-open-line arg)
(progn
(beginning-of-line)
(electric-indent-just-newline t)
(forward-char -1)
(indent-according-to-mode))))
(global-set-key (kbd "C-o") 'cp/open-line-before)
;; I wish you could press e.g. S-o in god-mode to get C-S-o.
;; 10/10 would make life better.
(global-set-key (kbd "C-S-o") 'cp/open-line)
(setq dired-bind-jump nil)
(global-set-key (kbd "C-x C-j") 'join-line)
;; C-z (suspend-frame) is utterly useless and disruptive - good place to put universal-argument
(global-unset-key (kbd "C-z"))
(global-set-key (kbd "C-z") 'universal-argument)
(global-set-key (kbd "C-x C-z") 'repeat)
(global-set-key (kbd "C-x C-;") 'repeat-complex-command)
;; (defun cp-kill-line (&optional arg)
;; (interactive)
;; (if arg
;; (if mark-active
;; (kill-region arg)
;; (kill-line arg))
;; (if mark-active
;; (kill-region)
;; (kill-line))))
;; (global-set-key (kbd "C-k") 'cp-kill-line)
;; Chris Done (god-mode) recommends this, but Emacs' repeat command is almost useless...
;; (global-set-key (kbd "C-.") 'repeat)
;;;; I like the transpose commands
(global-unset-key (kbd "C-t"))
(general-define-key
:prefix "C-t"
"C-t C-c" 'transpose-chars
"C-t C-w" 'transpose-words
"C-t C-l" 'transpose-lines
"C-t C-s" 'transpose-sentences
"C-t C-e" 'transpose-sexps
"C-t C-p" 'transpose-paragraphs)
(defun cp/delete-trailing-whitespace ()
(unless (derived-mode-p 'markdown-mode)
(delete-trailing-whitespace)))
(add-hook 'before-save-hook 'cp/delete-trailing-whitespace)
(require 'flex-isearch)
(flex-isearch-mode 1)
(general-define-key
"C-M-s" 'flex-isearch-forward
"C-M-r" 'flex-isearch-backward)
(use-package iedit
:bind (("C-;" . iedit-mode)
("C-:" . iedit-mode-toggle-on-function)
(:map iedit-mode-keymap
("C-h" . backward-delete-char))))
(with-eval-after-load 'markdown-mode
(defun cp/copy-md-link (prefix-arg)
"Copy address of Markdown link after point in the current line.
If there is no link in the current line, or if the region is
active, or with a prefix arg - call
whole-line-or-region-kill-ring-save instead."
(interactive "P")
(save-excursion
(if (or (use-region-p)
prefix-arg
(not (cp/re-search-line
;; 2018-03-21T22:47:55+0530 - fix bug where a line with parenthesized text would not be copied
;; "\("
;; 2018-07-22T10:20:03+0530
;; "\\[.*?\\](.*?)"
"\\[.*?\\]("
)))
(whole-line-or-region-kill-ring-save prefix-arg)
(let ((point-a (point)))
(forward-char -1)
(forward-sexp)
(copy-region-as-kill point-a (- (point) 1))))))
(cp-set-keys
:keymap markdown-mode-map
:bindings
`((,(kbd "M-w") cp/copy-md-link)
(,(kbd "TAB") markdown-cycle)
(,(kbd "C-c C-.") markdown-demote)
(,(kbd "C-c C-,") markdown-promote)
(,(kbd "C-c C-l") markdown-insert-link))))
(defun cp/copy-bus-entry ()
"For personal use, when working between Markdown and the OSM wiki."
(interactive)
(let ((point-a (region-beginning))
(point-b (region-end))
(point-b-line (line-number-at-pos)))
(query-replace "[ ]" "" nil point-a point-b)
(query-replace "[x]" "" nil point-a point-b)
(query-replace-regexp "^[\\*-] " "::" nil point-a point-b)
(query-replace-regexp "^### " ":" nil point-a point-b)
(goto-char (point-min))
(forward-line (- point-b-line 1))
(copy-region-as-kill point-a (point-at-bol))))
;; 2018-08-21T03:41:47+0530
(defun cp/copy-md-link (prefix-arg)
"Copy address of Markdown link after point in the current line.
If there is no link in the current line, or if the region is
active, or with a prefix arg - call
whole-line-or-region-kill-ring-save instead."
(interactive "P")
(save-excursion
(cond
((or (use-region-p) prefix-arg)
(whole-line-or-region-kill-ring-save prefix-arg))
((cp/re-search-line "\\[.*?\\](")
(let ((point-a (point)))
(forward-char -1)
(forward-sexp)
(copy-region-as-kill point-a (- (point) 1))))
((cp/re-search-line "http")
(kill-new (thing-at-point 'url)))
(t (whole-line-or-region-kill-ring-save prefix-arg)))))
;; 2018-08-28T22:50:43+0530
(defun cp/copy-buffer ()
(interactive)
(copy-region-as-kill (point-min) (point-max)))
(use-package multiple-cursors
:bind (("C-M-l" . #'mc/mark-previous-like-this-symbol)
("C-M-;" . #'mc/mark-next-like-this-symbol)
("C-M-'" . #'mc/mark-all-symbols-like-this)
("C-M-," . #'mc/mark-previous-word-like-this)
("C-M-." . #'mc/mark-next-word-like-this)
("C-M-/" . #'mc/mark-all-words-like-this)
("C-M-<" . #'mc/unmark-previous-like-this)
("C-M->" . #'mc/unmark-next-like-this)
("C-M-]" . #'mc-hide-unmatched-lines-mode)))
(defun cp/marked-files->markup-links-org (filenames)
(mapcar (lambda (filename)
(let ((link-pre "[[file:")
(link-post "][]]\n"))
(concat link-pre filename link-post)))
filenames))
(defun cp/marked-files->markup-links-md (filenames)
(mapcar (lambda (filename)
(if (member (downcase
(file-name-extension filename))
image-file-name-extensions)
(let ((link-pre "![](")
(link-post ")\n"))
(concat link-pre filename link-post))
(let ((link-pre "[](")
(link-post ")\n"))
(concat link-pre filename link-post))))
filenames))
;; BUG - (dired-get-marked-files) returns file name at point if none are marked
;; BUG - (dired-get-marked-files) always returns an alphabetically-sorted list, even when the Dired buffer is sorted by date
(defun cp/marked-files->markup-links ()
"From a Dired buffer, insert the file at point or marked files
as links into an Org or Markdown document."
(interactive)
(if (derived-mode-p 'dired-mode)
(let* ((filenames (dired-get-marked-files 'no-dir))
(other-buffer (->> (window-list)
(cadr)
(window-buffer)))
(other-buffer-mode (with-current-buffer other-buffer major-mode))
(two-window-op (and (= (length (window-list)) 2)
(member other-buffer-mode
'(org-mode markdown-mode))))
(output-buffer (if two-window-op
other-buffer
(read-buffer "Insert links in buffer: ")))
(output-mode (with-current-buffer output-buffer major-mode))
(output-text (cl-case output-mode
('org-mode
(cp/marked-files->markup-links-org filenames))
('markdown-mode
(cp/marked-files->markup-links-md filenames))
(t (error "Only Markdown and Org are currently supported.")))))
(if two-window-op
(other-window 1)
(switch-to-buffer output-buffer))
(mapc #'insert output-text))
(user-error "Run this command from a Dired buffer with some marked files."))
(when markdown-inline-image-overlays
(markdown-display-inline-images)))
(use-package adaptive-wrap
:hook (markdown-mode . adaptive-wrap-prefix-mode))
(use-package avy
:config
(setq avy-case-fold-search nil))
(provide 'cp-editing)

View File

@ -1,168 +0,0 @@
;;;; Hacks for Lilypond work
(use-package lilypond-mode
:load-path "elisp-git/lilypond/elisp"
:bind
(("C-c C-i" . LilyPond-info)
("M-]" . set-selective-display)
:map LilyPond-mode-map
("M-c" . cp-backward-def)
("M-r" . cp-forward-def)
("M-C" . cp-upper-level)
("M-R" . cp-lower-level)
("C-c C-w" . cp-ly-wrap-para))
:commands LilyPond-mode
:load-path "../user/"
:mode (("\\.ly$" . LilyPond-mode)
("\\.ily$" . LilyPond-mode))
:config
(--map (add-hook 'LilyPond-mode-hook it)
'(subword-mode
(lambda () (turn-on-font-lock))))
(defalias 'string-to-int #'string-to-number)
(defvar cp/ly-definition-rx
'(and bol
(1+ (any "a-z" "A-Z" "\\\\"))
(1+ (any "a-z" "A-Z" "\\\\" " "))
(any "{" "=" "#")))
(defun cp-backward-def ()
(interactive)
(unless (region-active-p)
(push-mark))
(re-search-backward (rx-to-string cp/ly-definition-rx)
nil t)
(beginning-of-line)
(recenter))
(defun cp-forward-def ()
(interactive)
(let* ((regex (rx-to-string cp/ly-definition-rx))
(count (if (looking-at-p regex) 2 1)))
(unless (region-active-p)
(push-mark))
;; (forward-char)
(if (not (re-search-forward regex nil t count))
(re-search-forward "^}" nil t))
;; (re-search-forward "^[\\a-zA-Z]" nil t)
(beginning-of-line)
(recenter)))
;; (defun cp-backward-def ()
;; (interactive)
;; (re-search-backward "\(^\\\\?[a-zA-Z]\|^ *\\[a-zA-Z]\)")
;; (beginning-of-line))
;; (defun cp-forward-def ()
;; (interactive)
;; (forward-char)
;; (re-search-forward "\(^\\\\?[a-zA-Z]\|^ *\\[a-zA-Z]\)")
;; (beginning-of-line))
(defun cp-upper-level ()
(interactive)
(re-search-backward "{"))
(defun cp-lower-level ()
(interactive)
(if (equal (string (char-after)) "{")
(forward-char))
(if (not (re-search-forward "{"))
(message "At deepest level."))
(backward-char))
;; (defun cp-lilypond-enclose-<< ()
;; (interactive)
;; (if (equal (string (char-after)) "\\")
;; (progn (insert "<< ")
;; (search-forward "{")
;; (backward-char)
;; (forward-sexp))))
;; if at a \new ... block - enclose expression
;; otherwise, enclose current position and after the first bar check
;; found
;; if region is active, enclose beginning and end
;; (defun cp-lilypond-enclose-<< ()
;; (interactive)
;; (if (equal (thing-at-point 'sexp)
;; "\\new")
;; (progn ;; (insert "<< ")
;; (newline-and-indent)
;; (search-forward "{")
;; (backward-char)
;; (forward-list)
;; ;; (forward-sexp))
;; )
;; ;; (let ((point1 (point)))
;; ;; (next-line)
;; ;; (goto-char point1))
;; ))
;; (define-key LilyPond-mode-map (kbd "<<")
;; 'cp-lilypond-enclose-<<)
;; If I change files, it's still main.ly that gets compiled; this is
;; good most of the time, but many times I want to compile a part-*
;; file instead. If we compile both main.ly and the respective part-*
;; file every time, it's wasteful. Having to select means giving up
;; the 'effortless-compilation' behaviour.
;; 2017-03-14T00:52:07+0530 - commented out, see cp/after-save
;; (defadvice LilyPond-save-buffer
;; (after lysb activate)
;; ;; (compile "make")
;; (cd (locate-dominating-file (buffer-file-name)
;; "main.ly"))
;; (compile (car compile-history)))
;;
;; (defadvice compile
;; (before compile activate)
;; (if (equal major-mode 'LilyPond-mode)
;; (cd (locate-dominating-file (buffer-file-name)
;; "main.ly"))))
;; TODO - refactor into one COND, with one case per operation.
;; TODO - operate on region as well.
(defun cp-ly-wrap-para (arg)
"Wrap current paragraph with -
\\relative c { ... } with no args,
\\repeat { ... } with universal argument,
and only braces - { ... } - with null argument.
Numeric arg wraps that many paragraphs.
TODO - wrap region if region active"
(interactive "P")
(let ((point-a (point)))
(beginning-of-line)
(unless (looking-at "[[:blank:]]*$")
;; go to start of paragraph or block, or previous blank line
(re-search-backward (rx (or (and bol (0+ blank) eol)
(and "{" eol))))
(end-of-line))
(newline-and-indent)
(insert (pcase arg
(`(,x) "\\repeat {")
(0 "{")
;; nil
(_ "\\relative c {")))
(let ((indent-start (point)))
(forward-paragraph (pcase arg
(`(,x) 1)
(_ (if (and arg (<= arg 0))
1 arg))))
(indent-region indent-start (point))
(insert "}")
(indent-for-tab-command)
(newline)
;; FIXME
(goto-char (pcase arg
(0 point-a)
(_ (- indent-start 2))))))))
;; TODO - cp-ly-new-var, bind to M-RET.
;; Exits current variable body, if in any, and inserts "| = \relative
;; c {\n\n \n}", where | is the cursor
(provide 'cp-lily)

View File

@ -1,71 +0,0 @@
(setq scheme-program-name "csi -:c")
(setq comint-prompt-read-only t)
(use-package geiser
:mode ("\\.scm\\'" . geiser-mode)
:commands (run-chicken run-guile geiser-mode))
;; (with-eval-after-load 'geiser-mode
;; (setq geiser-mode-smart-tab-p t)
;; (define-key geiser-mode-map (kbd "C-.") nil)
;; ;; (cp-set-keys
;; ;; :unset t
;; ;; :keymap geiser-mode-map
;; ;; :bindings
;; ;; `((,(kbd "C-."))))
;; )
(use-package scheme-mode
:mode ("\\.scm\\'" . scheme-mode)
:interpreter "csi")
(defun contrapunctus-lisp-copy (arg)
"Run `whole-line-or-region-copy-region-as-kill' if region is
active, else `sp-copy-sexp'."
(interactive "P")
(if (region-active-p)
(whole-line-or-region-copy-region-as-kill arg)
(sp-copy-sexp arg)))
(defun colorize-compilation-buffer ()
(ansi-color-apply-on-region compilation-filter-start
(point)))
(add-hook 'compilation-filter-hook 'colorize-compilation-buffer)
;; Stopped calling `exec-path-from-shell-initialize' on init, but
;; won't this keep running it excessively?
;; `exec-path-from-shell-copy-envs' (which it calls internally)
;; doesn't seem idempotent, either.
(use-package exec-path-from-shell
:hook
(compilation-mode . exec-path-from-shell-initialize)
(shell-mode-hook . exec-path-from-shell-initialize)
(minibuffer-setup-hook . exec-path-from-shell-initialize))
(use-package skeleton
:config
(define-skeleton cp-ql-quickload
"Insert a `(ql:quickload |)' form."
nil "(ql:quickload :" _ ")"))
(use-package abbrev
:hook (lisp-mode . abbrev-mode)
(slime-repl-mode . abbrev-mode)
:config
;; `slime-repl-mode' is defined as a function rather than using the
;; `define-derived-mode' macro, so there's no abbrev table created
;; for it. This is adapted from the macro expansion of
;; `geiser-repl-mode'.
(defvar slime-repl-mode-abbrev-table)
(put 'slime-repl-mode-abbrev-table 'definition-name 'slime-repl-mode)
(defvar slime-repl-mode-abbrev-table
(progn
(define-abbrev-table 'slime-repl-mode-abbrev-table
`(("qq" "" cp-ql-quickload))
"Abbrev table for SLIME REPLs.")
slime-repl-mode-abbrev-table))
(put 'slime-repl-mode-abbrev-table 'variable-documentation
(purecopy "Abbrev table for `slime-repl-mode'."))
(define-abbrev lisp-mode-abbrev-table "qq" "" 'cp-ql-quickload))
(provide 'cp-lisp)

686
init.org
View File

@ -355,6 +355,204 @@ Doesn't work in my current main browser (Tor Browser), and thus barely used of l
;; (if (not (server-running-p)) (server-start))
(server-start)
#+END_SRC
* Editing
:PROPERTIES:
:CREATED: 2022-01-13T20:48:58+0530
:END:
#+BEGIN_SRC emacs-lisp
;; fix Emacs' definition of a sentence
(setq sentence-end-double-space nil)
;; the utter basics
(general-define-key
"C-h" 'backward-delete-char
"C-w" 'backward-kill-word
"C-u" 'cp-kill-line-0
"C-," 'backward-paragraph
"C-." 'forward-paragraph
"C-<" 'beginning-of-buffer
"C->" 'end-of-buffer)
(define-key isearch-mode-map (kbd "C-h") 'isearch-delete-char)
(defun cp-kill-line-0 ()
(interactive)
(kill-line 0))
(global-unset-key (kbd "C-x C-r"))
(general-define-key
:prefix "C-x C-r"
"C-i" 'string-insert-rectangle
"C-r" 'replace-rectangle
"C-k" 'kill-rectangle)
(defun cp/downcase-dwim (arg)
"Like `downcase-word', but if region is active, run
`downcase-region' instead. Unlike `downcase-region', rectangular
regions are handled correctly as well.")
;; open-line should always move to the beginning of the current line
;; first, so one can run it anywhere. I also want it to indent it to
;; the next or the previous line...
;; These affect org-meta-return and org-insert-heading-respect-content
;;
;; (defadvice open-line
;; (before open-line-bol activate)
;; (beginning-of-visual-line))
;; (defadvice open-line
;; (after open-line-indent activate)
;; (if (not (looking-at "\\** "))
;; (indent-for-tab-command)))
;; (global-set-key (kbd "C-o") 'open-line)
(defun cp/open-line ()
"The opposite of `cp/open-line-before'. Start a new line below
the current line, regardless of where point is in the current
line. Will not affect the content of the current line. Applies
the correct indentation according to the mode."
(interactive)
(progn
(end-of-line)
(electric-indent-just-newline t)
(indent-according-to-mode)))
(defun cp/open-line-before (arg)
"Like `open-line' but a bit more sane.
In org-mode, run org-open-line.
In other modes, insert a newline above the current line,
regardless of where point is in current line. Will not affect
content of current line. Applies the correct indentation
according to the mode."
(interactive "p")
(if (and (equal major-mode 'org-mode)
(org-at-table-p))
(org-open-line arg)
(progn
(beginning-of-line)
(electric-indent-just-newline t)
(forward-char -1)
(indent-according-to-mode))))
(global-set-key (kbd "C-o") 'cp/open-line-before)
;; I wish you could press e.g. S-o in god-mode to get C-S-o.
;; 10/10 would make life better.
(global-set-key (kbd "C-S-o") 'cp/open-line)
(setq dired-bind-jump nil)
(global-set-key (kbd "C-x C-j") 'join-line)
;; C-z (suspend-frame) is utterly useless and disruptive - good place to put universal-argument
(global-unset-key (kbd "C-z"))
(global-set-key (kbd "C-z") 'universal-argument)
(global-set-key (kbd "C-x C-z") 'repeat)
(global-set-key (kbd "C-x C-;") 'repeat-complex-command)
;; (defun cp-kill-line (&optional arg)
;; (interactive)
;; (if arg
;; (if mark-active
;; (kill-region arg)
;; (kill-line arg))
;; (if mark-active
;; (kill-region)
;; (kill-line))))
;; (global-set-key (kbd "C-k") 'cp-kill-line)
;; Chris Done (god-mode) recommends this, but Emacs' repeat command is almost useless...
;; (global-set-key (kbd "C-.") 'repeat)
(defun cp/delete-trailing-whitespace ()
(unless (derived-mode-p 'markdown-mode)
(delete-trailing-whitespace)))
(add-hook 'before-save-hook 'cp/delete-trailing-whitespace)
;; BUG - (dired-get-marked-files) returns file name at point if none are marked
;; BUG - (dired-get-marked-files) always returns an alphabetically-sorted list, even when the Dired buffer is sorted by date
(defun cp/marked-files->markup-links ()
"From a Dired buffer, insert the file at point or marked files
as links into an Org or Markdown document."
(interactive)
(if (derived-mode-p 'dired-mode)
(let* ((filenames (dired-get-marked-files 'no-dir))
(other-buffer (->> (window-list)
(cadr)
(window-buffer)))
(other-buffer-mode (with-current-buffer other-buffer major-mode))
(two-window-op (and (= (length (window-list)) 2)
(member other-buffer-mode
'(org-mode markdown-mode))))
(output-buffer (if two-window-op
other-buffer
(read-buffer "Insert links in buffer: ")))
(output-mode (with-current-buffer output-buffer major-mode))
(output-text (cl-case output-mode
('org-mode
(cp/marked-files->markup-links-org filenames))
('markdown-mode
(cp/marked-files->markup-links-md filenames))
(t (error "Only Markdown and Org are currently supported.")))))
(if two-window-op
(other-window 1)
(switch-to-buffer output-buffer))
(mapc #'insert output-text))
(user-error "Run this command from a Dired buffer with some marked files."))
(when markdown-inline-image-overlays
(markdown-display-inline-images)))
#+END_SRC
** iedit
:PROPERTIES:
:CREATED: 2022-01-13T20:51:14+0530
:END:
#+BEGIN_SRC emacs-lisp
(use-package iedit
:bind (("C-;" . iedit-mode)
("C-:" . iedit-mode-toggle-on-function)
(:map iedit-mode-keymap
("C-h" . backward-delete-char))))
#+END_SRC
** multiple cursors
:PROPERTIES:
:CREATED: 2022-01-13T20:52:14+0530
:END:
#+BEGIN_SRC emacs-lisp
(use-package multiple-cursors
:bind (("C-M-l" . #'mc/mark-previous-like-this-symbol)
("C-M-;" . #'mc/mark-next-like-this-symbol)
("C-M-'" . #'mc/mark-all-symbols-like-this)
("C-M-," . #'mc/mark-previous-word-like-this)
("C-M-." . #'mc/mark-next-word-like-this)
("C-M-/" . #'mc/mark-all-words-like-this)
("C-M-<" . #'mc/unmark-previous-like-this)
("C-M->" . #'mc/unmark-next-like-this)
("C-M-]" . #'mc-hide-unmatched-lines-mode)))
#+END_SRC
** transpose commands
:PROPERTIES:
:CREATED: 2022-01-13T20:50:03+0530
:END:
#+BEGIN_SRC emacs-lisp
(global-unset-key (kbd "C-t"))
(general-define-key
:prefix "C-t"
"C-t C-c" 'transpose-chars
"C-t C-w" 'transpose-words
"C-t C-l" 'transpose-lines
"C-t C-s" 'transpose-sentences
"C-t C-e" 'transpose-sexps
"C-t C-p" 'transpose-paragraphs)
#+END_SRC
* modal editing
** active boon config
#+BEGIN_SRC emacs-lisp
@ -544,6 +742,7 @@ I'm pretty much using this to emulate `god-mode', which was great, but is no lon
;; (define-key helm-map (kbd "<escape>") 'god-local-mode)
(use-package god-mode-isearch
:disabled t
:bind
((:map isearch-mode-map
("<escape>" . god-mode-isearch-activate))
@ -645,6 +844,7 @@ choice.el is required by =chronometrist-key-values=
"Teaching" "Theatre" "Theory" "Transcription"
"Video editing" "Voice" "Wikisource" "Wiktionary" "Writing")))
#+END_SRC
**** activity-indicator
#+BEGIN_SRC emacs-lisp
(defun my-chronometrist-activity-indicator ()
@ -656,6 +856,7 @@ choice.el is required by =chronometrist-key-values=
(truncate it)
(chronometrist-format-duration it)))
#+END_SRC
**** find-two-files
#+BEGIN_SRC emacs-lisp
(defun contrapunctus-find-two-files (file-1 file-2)
@ -665,6 +866,7 @@ FILE-1 will appear above FILE-2."
(split-window-below)
(find-file file-1))
#+END_SRC
**** outline-open-heading
#+BEGIN_SRC emacs-lisp
(defun cp-outline-open-heading (n)
@ -1542,6 +1744,7 @@ Ask for confirmation before saving cookies. I'd rather just disallow them all th
jabber-account-list '(("contrapunctus@jabjab.de")))
(add-to-list 'jabber-post-connect-hooks 'jabber-enable-carbons))
#+END_SRC
** sxiv
#+BEGIN_SRC emacs-lisp
(use-package sxiv
@ -1554,21 +1757,15 @@ Ask for confirmation before saving cookies. I'd rather just disallow them all th
**
#+BEGIN_SRC emacs-lisp
;; (load "cp-adb")
#+END_SRC
**
#+BEGIN_SRC emacs-lisp
(require 'cp-editing)
(add-to-list 'load-path "~/.emacs.d/contrapunctus/")
;; (load "cp-evil")
(require 'cp-lily)
(require 'cp-sfz)
(require 'cp-lisp)
;; (ispell-change-dictionary "en")
(setq ispell-dictionary "en")
#+END_SRC
** TODO emacsshot
PR ideas
1. [ ] create directories in save path if they don't exist
@ -1864,16 +2061,13 @@ PR ideas
("M-r" . comint-next-matching-input-from-input)
("C-c C-s" . comint-next-prompt)
("C-c C-h" . comint-previous-prompt)))
#+END_SRC
* company-emoji
#+BEGIN_SRC emacs-lisp
(use-package company-emoji
:hook (text-mode . company-emoji-init)
:config (add-to-list 'company-backends 'company-emoji))
#+END_SRC
* counsel
* Completion
:PROPERTIES:
:CREATED: 2022-01-13T20:39:41+0530
:END:
** counsel
#+BEGIN_SRC emacs-lisp
(use-package counsel
:bind ("M-x" . counsel-M-x)
@ -1884,6 +2078,73 @@ PR ideas
;; :commands flycheck-elsa-setup)
#+END_SRC
** Ivy
#+BEGIN_SRC emacs-lisp
(use-package ivy
:commands ivy-mode
:init (ivy-rich-mode)
:bind (:map ivy-minibuffer-map
("C-h" . ivy-backward-delete-char)
("C-c" . previous-line)
("C-r" . next-line)
("M-c" . ivy-previous-history-element)
("M-r" . ivy-next-history-element))
:config
(setq ivy-re-builders-alist
'((t . ivy--regex-ignore-order))))
#+END_SRC
** ivy-xref
#+BEGIN_SRC emacs-lisp
(use-package ivy-xref
:config
(setq xref-show-definitions-function #'ivy-xref-show-defs))
#+END_SRC
** flx-ido :disabled:
#+BEGIN_SRC emacs-lisp
(use-package flx-ido
:disabled
:init (flx-ido-mode 1)
(setq ido-enable-flex-matching t
ido-use-faces nil))
#+END_SRC
** flx-isearch :disabled:
#+BEGIN_SRC emacs-lisp
(use-package flx-isearch
:disabled
:bind
("C-s" . #'flx-isearch-forward)
("C-r" . #'flx-isearch-backward))
;; (use-package flycheck
;; :init (global-flycheck-mode))
;; (use-package flycheck-elsa
;; :hook (emacs-lisp-mode . flycheck-elsa-setup))
#+END_SRC
** flex-isearch
:PROPERTIES:
:CREATED: 2022-01-13T20:50:41+0530
:END:
#+BEGIN_SRC emacs-lisp
(require 'flex-isearch)
(flex-isearch-mode 1)
(general-define-key
"C-M-s" 'flex-isearch-forward
"C-M-r" 'flex-isearch-backward)
#+END_SRC
** company-emoji
#+BEGIN_SRC emacs-lisp
(use-package company-emoji
:hook (text-mode . company-emoji-init)
:config (add-to-list 'company-backends 'company-emoji))
#+END_SRC
* misc keybindings
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "M-w") 'kill-ring-save)
@ -2408,46 +2669,22 @@ Don't try to check if there are files with a certain extension...it will lead to
("e" my-sql-eval-hydra/body "eval"))
#+END_SRC
* eshell
#+BEGIN_SRC emacs-lisp
(use-package eshell
:config (setq eshell-history-size 999))
#+END_SRC
* image-mode
#+BEGIN_SRC emacs-lisp
(use-package image-mode
:bind
(:map image-map
("o" . nil)
("r" . nil))
("c" . nil)
("r" . nil)
("o" . nil))
(:map image-mode-map
("c" . image-previous-file)
("r" . image-next-file)
("W" . image-transform-fit-to-width)
("H" . image-transform-fit-to-height)
("o" . nil)
("r" . nil)))
("R" . contrapunctus-rename-this-file)))
#+END_SRC
* flx-ido :disabled:
#+BEGIN_SRC emacs-lisp
(use-package flx-ido
:disabled
:init (flx-ido-mode 1)
(setq ido-enable-flex-matching t
ido-use-faces nil))
#+END_SRC
* flx-isearch :disabled:
#+BEGIN_SRC emacs-lisp
(use-package flx-isearch
:disabled
:bind
("C-s" . #'flx-isearch-forward)
("C-r" . #'flx-isearch-backward))
;; (use-package flycheck
;; :init (global-flycheck-mode))
;; (use-package flycheck-elsa
;; :hook (emacs-lisp-mode . flycheck-elsa-setup))
#+END_SRC
* environment variables
#+BEGIN_SRC emacs-lisp
@ -2524,6 +2761,8 @@ Don't try to check if there are files with a certain extension...it will lead to
(org-mode . visual-fill-column-mode)
(message-mode . visual-fill-column-mode))
(use-package adaptive-wrap
:hook (markdown-mode . adaptive-wrap-prefix-mode))
#+END_SRC
* Navigation
@ -2676,6 +2915,10 @@ Don't try to check if there are files with a certain extension...it will lead to
("x" . nil)
("<backspace>" . scroll-down-command)
("SPC" . scroll-up-command)))
(use-package avy
:config
(setq avy-case-fold-search nil))
#+END_SRC
** outline-minor-mode
@ -2984,6 +3227,7 @@ Suggestion by lampilelo for extending =iso-transl-ctl-x-8-map= (https://dpaste.c
(define-key map (kbd "C") [?Č])
(define-key iso-transl-ctl-x-8-map (kbd "v") map)))
#+END_SRC
* backup configuration
#+BEGIN_SRC emacs-lisp
(setq backup-by-copying t
@ -3009,28 +3253,6 @@ SLIME opens CLHS links in Firefox, but I'd rather open them in Tor Browser; Tor
(message "Copied %s to kill ring" url))
(setq browse-url-browser-function #'cp-copy-url))
#+END_SRC
* Ivy
#+BEGIN_SRC emacs-lisp
(use-package ivy
:commands ivy-mode
:init (ivy-mode)
:bind (:map ivy-minibuffer-map
("C-h" . ivy-backward-delete-char)
("C-c" . previous-line)
("C-r" . next-line)
("M-c" . ivy-previous-history-element)
("M-r" . ivy-next-history-element))
:config
(setq ivy-re-builders-alist
'((t . ivy--regex-ignore-order))))
#+END_SRC
** ivy-xref
#+BEGIN_SRC emacs-lisp
(use-package ivy-xref
:config
(setq xref-show-definitions-function #'ivy-xref-show-defs))
#+END_SRC
* TODO magit [0%]
1. [ ] It'd be really cool to =(recenter 3)= when you /open/ a section, and =(recenter)= when you close a section
@ -3283,6 +3505,12 @@ BUG - improper behaviour with checkboxes.
(mapconcat #'identity current-tags ",")
'org-tags-history)))))
(defun cp/marked-files->markup-links-org (filenames)
(mapcar (lambda (filename)
(let ((link-pre "[[file:")
(link-post "][]]\n"))
(concat link-pre filename link-post)))
filenames))
#+END_SRC
#+BEGIN_SRC emacs-lisp
@ -3397,6 +3625,86 @@ From https://emacs.stackexchange.com/questions/20577/org-babel-load-all-language
(cp/re-search-line "http")
(forward-char -4)
(kill-new (thing-at-point 'url))))))
(with-eval-after-load 'markdown-mode
(defun cp/copy-md-link (prefix-arg)
"Copy address of Markdown link after point in the current line.
If there is no link in the current line, or if the region is
active, or with a prefix arg - call
whole-line-or-region-kill-ring-save instead."
(interactive "P")
(save-excursion
(if (or (use-region-p)
prefix-arg
(not (cp/re-search-line
;; 2018-03-21T22:47:55+0530 - fix bug where a line with parenthesized text would not be copied
;; "\("
;; 2018-07-22T10:20:03+0530
;; "\\[.*?\\](.*?)"
"\\[.*?\\]("
)))
(whole-line-or-region-kill-ring-save prefix-arg)
(let ((point-a (point)))
(forward-char -1)
(forward-sexp)
(copy-region-as-kill point-a (- (point) 1))))))
(cp-set-keys
:keymap markdown-mode-map
:bindings
`((,(kbd "M-w") cp/copy-md-link)
(,(kbd "TAB") markdown-cycle)
(,(kbd "C-c C-.") markdown-demote)
(,(kbd "C-c C-,") markdown-promote)
(,(kbd "C-c C-l") markdown-insert-link))))
(defun cp/copy-bus-entry ()
"For personal use, when working between Markdown and the OSM wiki."
(interactive)
(let ((point-a (region-beginning))
(point-b (region-end))
(point-b-line (line-number-at-pos)))
(query-replace "[ ]" "☐" nil point-a point-b)
(query-replace "[x]" "☑" nil point-a point-b)
(query-replace-regexp "^[\\*-] " "::" nil point-a point-b)
(query-replace-regexp "^### " ":" nil point-a point-b)
(goto-char (point-min))
(forward-line (- point-b-line 1))
(copy-region-as-kill point-a (point-at-bol))))
;; 2018-08-21T03:41:47+0530
(defun cp/copy-md-link (prefix-arg)
"Copy address of Markdown link after point in the current line.
If there is no link in the current line, or if the region is
active, or with a prefix arg - call
whole-line-or-region-kill-ring-save instead."
(interactive "P")
(save-excursion
(cond
((or (use-region-p) prefix-arg)
(whole-line-or-region-kill-ring-save prefix-arg))
((cp/re-search-line "\\[.*?\\](")
(let ((point-a (point)))
(forward-char -1)
(forward-sexp)
(copy-region-as-kill point-a (- (point) 1))))
((cp/re-search-line "http")
(kill-new (thing-at-point 'url)))
(t (whole-line-or-region-kill-ring-save prefix-arg)))))
(defun cp/marked-files->markup-links-md (filenames)
(mapcar (lambda (filename)
(if (member (downcase
(file-name-extension filename))
image-file-name-extensions)
(let ((link-pre "![](")
(link-post ")\n"))
(concat link-pre filename link-post))
(let ((link-pre "[](")
(link-post ")\n"))
(concat link-pre filename link-post))))
filenames))
#+END_SRC
**
@ -3775,14 +4083,78 @@ Create advice for =lispy-pair= - if =lispy--in-string-or-comment-p= is true, sel
(("r" . next-line)
("c" . previous-line))))
#+END_SRC
*** orderless
:PROPERTIES:
:CREATED: 2022-01-13T17:31:53+0530
:END:
#+BEGIN_SRC emacs-lisp
(use-package orderless
:disabled t
:custom (completion-styles '(orderless))
:config (setq orderless-component-separator "[ \-]"))
#+END_SRC
** lisp
:PROPERTIES:
:CREATED: 2022-01-13T21:03:15+0530
:END:
#+BEGIN_SRC emacs-lisp
(setq scheme-program-name "csi -:c")
(setq comint-prompt-read-only t)
(use-package geiser
:mode ("\\.scm\\'" . geiser-mode)
:commands (run-chicken run-guile geiser-mode)
:custom (geiser-active-implementations '(chicken))
:config (setq geiser-scheme-implementation 'chicken))
;; (with-eval-after-load 'geiser-mode
;; (setq geiser-mode-smart-tab-p t)
;; (define-key geiser-mode-map (kbd "C-.") nil)
;; ;; (cp-set-keys
;; ;; :unset t
;; ;; :keymap geiser-mode-map
;; ;; :bindings
;; ;; `((,(kbd "C-."))))
;; )
(use-package scheme-mode
:mode ("\\.scm\\'" . scheme-mode)
:interpreter "csi")
(defun contrapunctus-lisp-copy (arg)
"Run `whole-line-or-region-copy-region-as-kill' if region is
active, else `sp-copy-sexp'."
(interactive "P")
(if (region-active-p)
(whole-line-or-region-copy-region-as-kill arg)
(sp-copy-sexp arg)))
(defun colorize-compilation-buffer ()
(ansi-color-apply-on-region compilation-filter-start
(point)))
(add-hook 'compilation-filter-hook 'colorize-compilation-buffer)
;; Stopped calling `exec-path-from-shell-initialize' on init, but
;; won't this keep running it excessively?
;; `exec-path-from-shell-copy-envs' (which it calls internally)
;; doesn't seem idempotent, either.
(use-package exec-path-from-shell
:hook
(compilation-mode . exec-path-from-shell-initialize)
(shell-mode-hook . exec-path-from-shell-initialize)
(minibuffer-setup-hook . exec-path-from-shell-initialize))
#+END_SRC
** Emacs Lisp
#+BEGIN_SRC emacs-lisp
(use-package elisp-mode
:diminish
:bind
(:map emacs-lisp-mode-map
("<tab>" . 'company-indent-or-complete-common)
("<C-tab>" . 'outline-toggle-children)
;; ("<tab>" . 'company-indent-or-complete-common)
;; ("<C-tab>" . 'outline-toggle-children)
("M-n" . 'outline-next-heading)
("M-p" . 'outline-previous-heading)
("M-m" . macrostep-expand))
@ -3951,13 +4323,179 @@ All COMMAND-SPECS should be a list in the form
*** CHICKEN Scheme
*** Guile
** Lilypond
#+BEGIN_SRC emacs-lisp
(use-package lilypond-mode
:load-path "elisp-git/lilypond/elisp"
:bind
(("M-]" . set-selective-display)
:map LilyPond-mode-map
("M-c" . cp-backward-def)
("M-r" . cp-forward-def)
("M-C" . cp-upper-level)
("M-R" . cp-lower-level)
("C-c C-w" . cp-ly-wrap-para))
:commands LilyPond-mode
:mode (("\\.ly$" . LilyPond-mode)
("\\.ily$" . LilyPond-mode))
:config
(--map (add-hook 'LilyPond-mode-hook it)
'(subword-mode
(lambda () (turn-on-font-lock))))
(defalias 'string-to-int #'string-to-number)
(defvar cp/ly-definition-rx
'(and bol
(1+ (any "a-z" "A-Z" "\\\\"))
(1+ (any "a-z" "A-Z" "\\\\" " "))
(any "{" "=" "#")))
(defun cp-backward-def ()
(interactive)
(unless (region-active-p)
(push-mark))
(re-search-backward (rx-to-string cp/ly-definition-rx)
nil t)
(beginning-of-line)
(recenter))
(defun cp-forward-def ()
(interactive)
(let* ((regex (rx-to-string cp/ly-definition-rx))
(count (if (looking-at-p regex) 2 1)))
(unless (region-active-p)
(push-mark))
;; (forward-char)
(if (not (re-search-forward regex nil t count))
(re-search-forward "^}" nil t))
;; (re-search-forward "^[\\a-zA-Z]" nil t)
(beginning-of-line)
(recenter)))
;; (defun cp-backward-def ()
;; (interactive)
;; (re-search-backward "\(^\\\\?[a-zA-Z]\|^ *\\[a-zA-Z]\)")
;; (beginning-of-line))
;; (defun cp-forward-def ()
;; (interactive)
;; (forward-char)
;; (re-search-forward "\(^\\\\?[a-zA-Z]\|^ *\\[a-zA-Z]\)")
;; (beginning-of-line))
(defun cp-upper-level ()
(interactive)
(re-search-backward "{"))
(defun cp-lower-level ()
(interactive)
(if (equal (string (char-after)) "{")
(forward-char))
(if (not (re-search-forward "{"))
(message "At deepest level."))
(backward-char))
;; (defun cp-lilypond-enclose-<< ()
;; (interactive)
;; (if (equal (string (char-after)) "\\")
;; (progn (insert "<< ")
;; (search-forward "{")
;; (backward-char)
;; (forward-sexp))))
;; if at a \new ... block - enclose expression
;; otherwise, enclose current position and after the first bar check
;; found
;; if region is active, enclose beginning and end
;; (defun cp-lilypond-enclose-<< ()
;; (interactive)
;; (if (equal (thing-at-point 'sexp)
;; "\\new")
;; (progn ;; (insert "<< ")
;; (newline-and-indent)
;; (search-forward "{")
;; (backward-char)
;; (forward-list)
;; ;; (forward-sexp))
;; )
;; ;; (let ((point1 (point)))
;; ;; (next-line)
;; ;; (goto-char point1))
;; ))
;; (define-key LilyPond-mode-map (kbd "<<")
;; 'cp-lilypond-enclose-<<)
;; If I change files, it's still main.ly that gets compiled; this is
;; good most of the time, but many times I want to compile a part-*
;; file instead. If we compile both main.ly and the respective part-*
;; file every time, it's wasteful. Having to select means giving up
;; the 'effortless-compilation' behaviour.
;; 2017-03-14T00:52:07+0530 - commented out, see cp/after-save
;; (defadvice LilyPond-save-buffer
;; (after lysb activate)
;; ;; (compile "make")
;; (cd (locate-dominating-file (buffer-file-name)
;; "main.ly"))
;; (compile (car compile-history)))
;;
;; (defadvice compile
;; (before compile activate)
;; (if (equal major-mode 'LilyPond-mode)
;; (cd (locate-dominating-file (buffer-file-name)
;; "main.ly"))))
;; TODO - refactor into one COND, with one case per operation.
;; TODO - operate on region as well.
(defun cp-ly-wrap-para (arg)
"Wrap current paragraph with -
\\relative c { ... } with no args,
\\repeat { ... } with universal argument,
and only braces - { ... } - with null argument.
Numeric arg wraps that many paragraphs.
TODO - wrap region if region active"
(interactive "P")
(let ((point-a (point)))
(beginning-of-line)
(unless (looking-at "[[:blank:]]*$")
;; go to start of paragraph or block, or previous blank line
(re-search-backward (rx (or (and bol (0+ blank) eol)
(and "{" eol))))
(end-of-line))
(newline-and-indent)
(insert (pcase arg
(`(,x) "\\repeat {")
(0 "{")
;; nil
(_ "\\relative c {")))
(let ((indent-start (point)))
(forward-paragraph (pcase arg
(`(,x) 1)
(_ (if (and arg (<= arg 0))
1 arg))))
(indent-region indent-start (point))
(insert "}")
(indent-for-tab-command)
(newline)
;; FIXME
(goto-char (pcase arg
(0 point-a)
(_ (- indent-start 2))))))))
;; TODO - cp-ly-new-var, bind to M-RET.
;; Exits current variable body, if in any, and inserts "| = \relative
;; c {\n\n \n}", where | is the cursor
#+END_SRC
** Prolog
#+BEGIN_SRC emacs-lisp
(use-package ediprolog
:commands ediprolog-dwim)
#+END_SRC
** c
** C
#+BEGIN_SRC emacs-lisp
(use-package cc-mode
:bind (:map c-mode-map
@ -3983,8 +4521,8 @@ All COMMAND-SPECS should be a list in the form
:bind
(:map c-mode-map
("<f2> <f2>" . rtags-find-symbol-at-point)))
#+END_SRC
** nodejs-repl :disabled:
#+BEGIN_SRC emacs-lisp
(use-package nodejs-repl