diff options
author | Thomas Voss <mail@thomasvoss.com> | 2024-10-31 14:44:12 +0100 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2024-10-31 14:44:12 +0100 |
commit | 3b28f538d9b90b7a2584046a3050115c5500b141 (patch) | |
tree | 2b3cb88a2b9bf3fcc992eb75e3d44e1954ce3a6f | |
parent | 215af6916738fffc1d88d237b91d2f5746deb07f (diff) |
emacs: Add mm-search-forward-char and mm-search-backward-char
-rw-r--r-- | .config/emacs/editing.el | 27 | ||||
-rw-r--r-- | .config/emacs/modules/mm-keybindings.el | 3 |
2 files changed, 30 insertions, 0 deletions
diff --git a/.config/emacs/editing.el b/.config/emacs/editing.el index 064793d..95160f8 100644 --- a/.config/emacs/editing.el +++ b/.config/emacs/editing.el @@ -221,4 +221,31 @@ If `consult' is available than this command instead calls (t (call-interactively #'yank-from-kill-ring))))) +(defun mm-search-forward-char (char &optional n) + "Search forwards to the Nth occurance of CHAR. +If called interactively CHAR is read from the minibuffer and N is given +by the prefix argument. + +If N is negative then this function searches backwards. + +When searching forwards point is left before CHAR while when searching +backwards point is left after CHAR." + (interactive + (list (read-char) + (prefix-numeric-value current-prefix-arg))) + (when (and (> n 0) (= char (char-after (point)))) + (forward-char)) + (search-forward (char-to-string char) nil nil n) + (when (> n 0) + (backward-char))) + +(defun mm-search-backward-char (char &optional n) + "Search backwards to the Nth occurance of CHAR. +This function is identical to `mm-search-forward-char' with N negated." + (declare (interactive-only t)) + (interactive + (list (read-char) + (prefix-numeric-value current-prefix-arg))) + (mm-search-forward-char char (- n))) + (provide 'editing) diff --git a/.config/emacs/modules/mm-keybindings.el b/.config/emacs/modules/mm-keybindings.el index a025a82..746d95c 100644 --- a/.config/emacs/modules/mm-keybindings.el +++ b/.config/emacs/modules/mm-keybindings.el @@ -115,6 +115,9 @@ the first command is remapped to the second command." "C-^" #'e/split-line "C-/" #'e/mark-line-dwim + "C-]" #'mm-search-forward-char + "M-]" #'mm-search-backward-char + "C-c d" #'duplicate-dwim "C-c t a" #'e/align-regexp "C-c t f" #'fill-paragraph |