My preferred method of indicating a location within a document that requires attention is with three asterisks ***
. When it comes time to select the region containing the three asterisks using shift+right-word
or shift+left-word
, those functions skip over the three asterisks and move along to the next word. When I peeked inside bindings.el
, I saw that left-word
and right-word
are adaptations of forward-word
and backward-word
, that are traceable to built-in functions in the C source code. Essentially, I'm looking for left-word
and right-word
that includes symbols such as three asterisks ***
.
Can anyone please suggest a way to have a function that jumps a word or symbols to the left, and a word or symbols to the right. The function would need to behave similar to left-word and right-word so that I could select more than one word if the arrow keys are pressed more than one time -- e.g., left-word-or-symbols
and right-word-or-symbols
.
The following is a custom function based upon the helpful answer of below:
(defvar lawlist-movement-syntax-table
(let ((st (make-syntax-table)))
;; ` default = punctuation
;; ' default = punctuation
;; , default = punctuation
;; ; default = punctuation
(modify-syntax-entry ?{ "." st) ;; { = punctuation
(modify-syntax-entry ?} "." st) ;; } = punctuation
(modify-syntax-entry ?\" "." st) ;; " = punctuation
(modify-syntax-entry ?\\ "_" st) ;; \ = symbol
(modify-syntax-entry ?\$ "_" st) ;; $ = symbol
(modify-syntax-entry ?\% "_" st) ;; % = symbol
st)
"Syntax table used while executing custom movement functions.")
(defun lawlist-forward-entity ()
"http://stackoverflow.com/q/18675201/2112489"
(interactive "^")
(with-syntax-table lawlist-movement-syntax-table
(cond
((eolp)
(forward-char))
((and
(save-excursion (< 0 (skip-chars-forward " \t")))
(not (region-active-p)))
(skip-chars-forward " \t"))
((and
(save-excursion (< 0 (skip-chars-forward " \t")))
(region-active-p))
(skip-chars-forward " \t")
(cond
((save-excursion (< 0 (skip-syntax-forward "w")))
(skip-syntax-forward "w"))
((save-excursion (< 0 (skip-syntax-forward ".")))
(skip-syntax-forward "."))
((save-excursion (< 0 (skip-syntax-forward "_()")))
(skip-syntax-forward "_()"))))
((save-excursion (< 0 (skip-syntax-forward "w")))
(skip-syntax-forward "w")
(if (and
(not (region-active-p))
(save-excursion (< 0 (skip-chars-forward " \t"))))
(skip-chars-forward " \t")))
((save-excursion (< 0 (skip-syntax-forward ".")))
(skip-syntax-forward ".")
(if (and
(not (region-active-p))
(save-excursion (< 0 (skip-chars-forward " \t"))))
(skip-chars-forward " \t")))
((save-excursion (< 0 (skip-syntax-forward "_()")))
(skip-syntax-forward "_()")
(if (and
(not (region-active-p))
(save-excursion (< 0 (skip-chars-forward " \t"))))
(skip-chars-forward " \t"))))))
(defun lawlist-backward-entity ()
"http://stackoverflow.com/q/18675201/2112489"
(interactive "^")
(with-syntax-table lawlist-movement-syntax-table
(cond
((bolp)
(backward-char))
((save-excursion (> 0 (skip-chars-backward " \t")) (bolp))
(skip-chars-backward " \t"))
((save-excursion (> 0 (skip-chars-backward " \t")) (> 0 (skip-syntax-backward "w")))
(skip-chars-backward " \t")
(skip-syntax-backward "w"))
((save-excursion (> 0 (skip-syntax-backward "w")))
(skip-syntax-backward "w"))
((save-excursion (> 0 (skip-syntax-backward ".")))
(skip-syntax-backward "."))
((save-excursion (> 0 (skip-chars-backward " \t")) (> 0 (skip-syntax-backward ".")))
(skip-chars-backward " \t")
(skip-syntax-backward "."))
((save-excursion (> 0 (skip-syntax-backward "_()")))
(skip-syntax-backward "_()"))
((save-excursion (> 0 (skip-chars-backward " \t")) (> 0 (skip-syntax-backward "_()")))
(skip-chars-backward " \t")
(skip-syntax-backward "_()")))))