为什么re-search-backward在python模式下给出不同的结果? [英] Why does re-search-backward give different result in python-mode?

查看:150
本文介绍了为什么re-search-backward在python模式下给出不同的结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用python模式很长一段时间。而且我总是用subword模式。但是subword模式在python模式下表现得很奇怪。例如, M-b 运动。如果有一个名为 test_varialbe 的变量,我将光标放在此变量的末尾,在python模式 Mb 将使光标指向 t ,而在其他模式下,它将转到 v



所以我研究了子字模式的来源,发现了以下功能:

 (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
((和(match-end 3))
(< 1( - (match-end 3) )))
(not(eq(point)(match-end 3))))
(1-(match-end 3 ))
(t
(1+(match-beginning 0)))))
(反向字1)))
/ pre>

进行一些测试后,我发现 re-search-backward 在不同的模式下给出不同的结果。如果我在python-mode中的 eval-expression (let ...)表达式,光标将跳转到 test_varialbe 之前的空格,而在其他模式中,它将跳转到 -



为什么是这样?导致 re-search-backward 的行为不同?

解决方案

原因是_的语法表定义有差异。



在Python模式中,_具有单词的语法定义,而在其他情况下它被定义为符号。看看 Elisp手册:语法表


I have been using python-mode for a long time. And I always use subword-mode. But subword-mode behave strangely in python-mode. For example, the M-b movement. If there is a variable named test_varialbe and I put the cursor at the end of this variable, in python-mode M-b will make the cursor point to t while in other modes it will go to v.

So I looked into the source of subword-mode and found the following function:

(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)))

After making some tests, I found re-search-backward is giving different result in different modes. If I eval-expression the (let ...) expression in python-mode, the cursor will jump to the space before test_varialbe, and in other modes it will jump to -.

Why is this? What has caused re-search-backward to behave differently?

解决方案

The reason is that there are differences in the Syntax table definition of '_'.

In Python mode '_' has a syntax definition of "word" whereas in other cases it is defined as "symbol". Look at Elisp manual: Syntax tables

这篇关于为什么re-search-backward在python模式下给出不同的结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆