用于包含符号的前向/后向字的替代方法 - 例如*** [英] Alternative to forward-word / backward-word to include symbols -- e.g., ***
问题描述
我希望在文档中指出需要注意的位置的首选方法是使用三个星号 ***
。当使用 shift + right-word
或 shift + left-word
选择包含三个星号的区域时,这些功能跳过三个星号并移动到下一个字。当我在 bindings.el
内偷看时,我看到左字
和右字
是适应于转发词
和向后词
在C源代码中的函数。本质上,我正在寻找左字
和右字
,其中包括诸如三个星号 ***
。
任何人都可以建议一种方法来将一个或多个符号跳到左边,一个字或符号在右边。该函数需要与左字和右字相似,以便如果箭头键被按下多次,我可以选择多个单词 - 例如, left-word-or-符号
和右字符或符号
。
以下是基于以下有用答案的自定义函数:
(defvar lawlist-movement-syntax-table
(let((st(make-syntax-table)))
;;`default =标点符号
;;'默认=标点符号
;;,default = punctuation
;;; default = punctuation
(modify-syntax-entry?{。st);; {= punctuation
(modify-syntax-entry ?\\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\_st);; \ = symbol
(modify-syntax-entry?\ $_st);; $ = symbol
(modify-syntax-entry?\ %=$ = $
st)
执行自定义运动功能时使用的语法表)
(defun lawlist-forward-entity()
http://stackoverflow.com/q/18675201/2112489
(interactive^)
(with-syntax-table lawlist-movement-syntax-table
(cond
((eolp)
(forward-char))
((和
(save-excursion(< 0(skip-chars-forward\t)))
(not(region-active-p)))
(skip-chars-forward\t))
((
(save-excursion(< 0(skip-chars-forward)\t)))
(region-active-p))
(skip-chars - $$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ 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-forwardw)
(if(和
(not(region-active-p) )
(save-excursion(< 0(skip-chars-forward\t))))
(skip-chars-forward\t)))
((save-excursion(< 0(skip-syntax-forw ard))
(skip-syntax-forward。)
(if(和
(not(region-active-p))
(save-偏移(< 0(skip-chars-forward\t))))
(skip-chars-forward\t)))
((save-excursion(< 0(skip-语法转发_())))
(skip-syntax-forward_())
(if(和
(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-语法表lawlist-movement-syntax-table
(cond
((bolp)
(backward-char))
((save-excursion(> chars-backward\t))(bolp))
(skip-chars-backward\t))
((save-excursion(> 0(skip-chars-backward \t))(> 0(skip-syntax-backwardw)))
(skip-chars-backward\t)
(skip-syntax-backward w))
((save-excursion(> 0(skip-syntax-backw ardw)))
(skip-syntax-backwardw))
((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_())))))
添加到模式的模式挂钩,您正在编辑文本:
(modify-syntax-entry?*w)
阅读> 了解更多信息。
请注意,这将使其他乐趣手势会像星号一样对待星号(尽管如此,你可能会想要它,因为你很快就会发现运动命令不仅与你想要的那样相反)。
另外一种只重载这些特定命令的方法是用 defadvice
来建议他们,并在函数的持续时间内暂时改变语法表。 / p>
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 "_()")))))
Add to the mode hook of the mode, where you are editing the text:
(modify-syntax-entry ?* "w")
Read here for more info.
Note that this will make other functions treat asterisks as if they were word constituent (though, you'd probably want it, as you'd soon discover that not only the motion command behave contrary to how you want them to).
Another way to overload only these particular commands would be to advise them with defadvice
and to temporarily alter the syntax table just for the duration of the function.
这篇关于用于包含符号的前向/后向字的替代方法 - 例如***的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!