我首选的方法是用三个星号表示文档中需要注意的位置***
。当需要使用shift+right-word
or选择包含三个星号的区域时shift+left-word
,这些函数会跳过三个星号并移动到下一个单词。当我窥视内部bindings.el
时,我发现left-word
and是andright-word
的改编版本,可以追溯到 C 源代码中的内置函数。本质上,我正在寻找并且包括三个星号之类的符号。forward-word
backward-word
left-word
right-word
***
任何人都可以建议一种方法,使其具有向左跳转一个单词或符号,向右跳转一个单词或符号的功能。该函数的行为需要类似于左词和右词,以便在多次按下箭头键时我可以选择多个词——例如,left-word-or-symbols
和right-word-or-symbols
。
以下是基于以下有用答案的自定义函数:
(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 "_()")))))