Emacs: Commands to Jump to Punctuations

Master emacs+lisp, benefit for life. Testimonials. Thank you for support.
, , …,

2 commands that let you fly to any punctuation in language source code.

(defvar xah-punctuations nil "list of punctuation chars.")
(setq xah-punctuations '("=" "*" "$" "#" "+" "\\" "&" "@" "%" "!" "?" "^" "`" "~") )

(defun xah-forward-punct (&optional number)
  "Move cursor to the next occurrence of punctuation.

The list of punctuations to jump to is defined by `xah-punctuations'"
  (interactive "p")
  (if (and number (> 0 number))
      (xah-backward-punct (- 0 number))
    (forward-char 1)
    (search-forward-regexp (eval-when-compile (regexp-opt xah-punctuations)) nil t number)
    (backward-char 1)))

(defun xah-backward-punct (&optional number)
  "Move cursor to the previous occurrence of punctuation.

The list of punctuations to jump to is defined by `xah-punctuations'"
  (interactive "p")
  (if (and number (> 0 number))
      (xah-forward-punct (- 0 number))
    (search-backward-regexp (eval-when-compile (regexp-opt xah-punctuations)) nil t number)))

you need to give them a easy key for this idea to work, such as {【Ctrl+7】, 【Ctrl+8】}. 〔☛ Emacs: How to Define Keys〕 (you'll need a key that can be held down to repeat, such as 【F8】, 【Ctrl+8】, and for example 【Ctrl+c c】 wouldn't work. 〔☛ Emacs: Fast-repeat vs Non-fast-repeat Commands & Keys〕)

this is a recent idea. Going to experiment with it for a while to see if it's worthwhile.

this is to be used together with Emacs: Commands to Move Cursor by Brackets, Quotes.

the jump to punctuation is inspired by ace-jump-mode: https://github.com/winterTTr by winterTTr.

i heard about ace-jump from jcs's blog years ago.

Like what you read?
Buy Xah Emacs Tutorial
or share some
blog comments powered by Disqus