Emacs - 向前和向后标记这个词 [英] Emacs - mark the word forward and backward

查看:120
本文介绍了Emacs - 向前和向后标记这个词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上我问的是vim的vb(bbww ...)和vw(wwbb ...)的等效功能:



我想绑定我的meta-j和meta-k来标记当前点之前和之后的单词。 Simple.el提供了我绑定到meta-k的标记词功能。我改变了标记字的功能:

 (defun mark-backward(& optional arg allow-extend) ; 
(交互式P \\\
p)
(cond((和allow-extend
(或(和(最后一个命令this-command)(标记t))
(和transient-mark-mode mark-active)))
(setq arg(if arg(prefix-numeric-value arg)
(if(<(mark)(point)) -
(set-mark
(save-excursion
(goto-char(mark))
(forward-word arg)
(point) ))
(t(push-mark
(save-excursion
(backward-word(prefix-numeric-value arg))
(point))nil t) )
(全局设置键(kbdMk)'标记字)
(全局设置键(kbdMj)'标记 - 后退)

这种工作。我想撤消一些标记使用另一个键,我该怎么办? (即在我用Mk标记一些单词后,我想使用Mj取消标记一些单词,目前,当我打Mj时,emacs继续向前标记)。

解决方案

 (defun my-mark-word(N)
(interactivep)
(if(and
(not(eq last-command this-command))
(not(eq last-command'my-mark-word-backward)))
(set-mark(point)))
(转发词N))


(defun my-mark-word-backward(N)
(interactivep)
(和
(not(eq last-command this-command))
(not(eq last-command'my-mark-word)))
(set-mark(point)) )
(后退字N))

(本地设置键(kbdMk)'我的标记字)

(local- set-key(kbdMj)'my-mark-word-backward)

VIM的行为(当然还有其他按键)。



备注: Mj 默认绑定到 indent-new-comment-line 在源代码中写入注释块时非常方便。 M-k 默认绑定到 kill-sentence


Basically what I am asking is the equivalent function to vim's vb(bbww...) and vw(wwbb...):

I want to bind my meta-j and meta-k to mark the word before and after current point. Simple.el provided the mark-word function, which I bind to meta-k. And I changed the mark-word function a bit to:

 (defun mark-backward (&optional arg   allow-extend) ;   
      (interactive "P\np")
      (cond ((and allow-extend
               (or (and (eq last-command this-command) (mark t))
                   (and transient-mark-mode mark-active)))
      (setq arg (if arg (prefix-numeric-value arg)
               (if (< (mark) (point)) -1 1)))
                   (set-mark
                       (save-excursion
                           (goto-char (mark))
                           (forward-word arg)
                           (point))))   
      (t   (push-mark  
        (save-excursion
        (backward-word (prefix-numeric-value arg))
        (point))      nil t)))) 
(global-set-key (kbd "M-k") 'mark-word) 
(global-set-key (kbd "M-j") 'mark-backward)

This kinda worked. I want to undo some marking use the other key, how can I do that? (i.e. after I marked some word with M-k, I want to use M-j to unmark some word to left. Currently, when I hit M-j, emacs continue to mark forward).

解决方案

(defun my-mark-word (N)
  (interactive "p")
  (if (and 
       (not (eq last-command this-command))
       (not (eq last-command 'my-mark-word-backward)))
      (set-mark (point)))
  (forward-word N))


(defun my-mark-word-backward (N)
  (interactive "p")
  (if (and
       (not (eq last-command this-command))
       (not (eq last-command 'my-mark-word)))
      (set-mark (point)))
  (backward-word N))

(local-set-key (kbd "M-k") 'my-mark-word)

(local-set-key (kbd "M-j") 'my-mark-word-backward)

This should emulate VIMs behaviour (with other keystrokes, of course).

Remark: M-j is by default bound to indent-new-comment-line which is quite handy when writing commented blocks in source code. M-k is by default bound to kill-sentence.

这篇关于Emacs - 向前和向后标记这个词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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