我已经使用 python 模式很长时间了。我总是使用子字模式。但子字模式在 python 模式下表现得很奇怪。例如,M-b
移动。如果有一个名为test_varialbe
我将光标放在这个变量的末尾,在 python 模式下M-b
将使光标指向t
而在其他模式下它将转到v
.
所以我查看了 subword-mode 的源码,发现了以下函数:
(defun subword-backward-internal ()
(if (save-excursion
(let ((case-fold-search nil))
(re-search-backward
(concat
"\\(\\(\\W\\|[[:lower:][:digit:]]\\)\\([[:upper:]]+\\W*\\)"
"\\|\\W\\w+\\)")
nil t)))
(goto-char
(cond
((and (match-end 3)
(< 1 (- (match-end 3) (match-beginning 3)))
(not (eq (point) (match-end 3))))
(1- (match-end 3)))
(t
(1+ (match-beginning 0)))))
(backward-word 1)))
经过一些测试,我发现re-search-backward
在不同的模式下给出不同的结果。如果我eval-expression
the (let ...)
python模式下的表达式,光标会跳到前面的空格test_varialbe
,在其他模式下会跳转到-
.
为什么是这样?是什么原因造成的re-search-backward
表现不同?
原因是“_”的语法表定义存在差异。
在Python模式下,'_'具有“单词”的语法定义,而在其他情况下,它被定义为“符号”。看着Elisp 手册:语法表 http://www.gnu.org/software/emacs/manual/html_node/elisp/Syntax-Tables.html
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)