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 /.config/emacs/editing.el | |
parent | 215af6916738fffc1d88d237b91d2f5746deb07f (diff) |
emacs: Add mm-search-forward-char and mm-search-backward-char
Diffstat (limited to '.config/emacs/editing.el')
-rw-r--r-- | .config/emacs/editing.el | 27 |
1 files changed, 27 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) |