启动选择代替Emacs的前进字 [英] Initiating selection in replacement for Emacs' forward-word

查看:140
本文介绍了启动选择代替Emacs的前进字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想替换Emacs的默认转发单词和反向词来操作更像Visual Studio,我觉得更适合于Perl编程。我第一次尝试黑客的语法表,没有达到我想要的效果。然后我想出了以下内容:

I want to replace Emacs' default forward-word and backward-word to operate more like Visual Studio's - which I find better suited to Perl programming. I first tried hacking the syntax table, without achieving the effect I wanted. Then I came up with the following:

(defconst perl-movement-stop-chars "a-zA-Z$@%_0-9'")
(defconst perl-movement-stop-pattern (concat "[" perl-movement-stop-chars "]"))
(defconst non-perl-movement-stop-pattern (concat "[^" perl-movement-stop-chars "]"))

(defun perl-forward-word ()
  (interactive)
  (if (looking-at perl-movement-stop-pattern)
      (progn
        (if (re-search-forward non-perl-movement-stop-pattern nil t)
            (backward-char)))
    (if (re-search-forward perl-movement-stop-pattern nil t)
        (backward-char))))

(defun perl-backward-word ()
  (interactive)
  (backward-char)
  (if (looking-at perl-movement-stop-pattern)
      (progn
        (if (re-search-backward non-perl-movement-stop-pattern nil t)
            (forward-char)))
    (if (re-search-backward perl-movement-stop-pattern nil t)
        (forward-char))))

(add-hook 'cperl-mode-hook
          (lambda()
            (local-set-key [C-right] 'perl-forward-word)
            (local-set-key [C-left] 'perl-backward-word)
            linum-mode))

做我想要的 - 几乎:我仍然需要处理从缓冲区内的第一个单词内向后移动的情况。但是这不是我的问题。

This does what I want - nearly: I still have to handle the case when moving backward from inside the first word in the buffer. But that is not my question.

这个问题是,当我键入CS-right时,选择不会启动,因为当我的钩子没有安装时或其他模式)。如果我开始选择(例如通过击中第一个S-right),我的功能会扩展它。

The problem with this is that the selection is not started when I type C-S-right, as it is when my hook is not installed (or in other modes). If I initiate the selection though (e.g. by hitting first S-right) my functions do extend it.

我非常非常非常的了解elisp编程,我只是猜测我的方式在这里我会感谢一点帮助。谢谢...

I know very, very little about elisp programming and I am just guessing my way here. I would appreciate a bit of help. Thanks...

推荐答案

获取 shift-select-mode 您需要使用(交互式^)。尝试 Ch f interactive RET

To get shift-select-mode working, you'll need to use (interactive "^"). Try C-h f interactive RET.

BTW,您可以大大简化代码:向前移动,只需(re-search-forward.\\(\\_< \\ | \\_> \\)nil t)并向后移动,使用(re-search-backward\\(\\_< \\ | \\_> \\)。 )

BTW, you can simplify your code considerably: to move forward, just (re-search-forward ".\\(\\_<\\|\\_>\\)" nil t) and to move backward, use (re-search-backward "\\(\\_<\\|\\_>\\)." nil t).

这篇关于启动选择代替Emacs的前进字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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