我的.emacs.d中有以下defun's:
;;; http://emacswiki.org/emacs/ParenthesisMatching
(defun goto-match-paren (arg)
"Go to the matching if on (){}[], similar to vi style of % "
(interactive "p")
;; first, check for "outside of bracket" positions expected by forward-sexp, etc.
(cond ((looking-at "[\[\(\{]") (forward-sexp))
((looking-back "[\]\)\}]" 1) (backward-sexp))
;; now, try to succeed from inside of a bracket
((looking-at "[\]\)\}]") (forward-char) (backward-sexp))
((looking-back "[\[\(\{]" 1) (backward-char) (forward-sexp))
(t nil)))
(defun select-in-parens ()
(interactive)
(goto-match-paren 1)
(set-mark (point)))
我最初只有第一个功能。然后我添加了第二个,我打算选择一个完整的s表达式。现在,我将其中一个绑定到M- [,另一个绑定到M-]。当我去paren并点击“goto”键时,它会按照我想要的方式 - 跳到另一个。如果我之后点击“选择”键...它会做同样的事情,没有标记区域,并在之后反复点击它使它在parens之间跳跃。但是如果我在那之后“转到”,那么会标记该区域,然后反复击中它并将其取消标记。
所以基本上我有我想要的功能......但是反过来了,我不知道为什么。有人可以解释这里发生了什么,也许可以提供解决方案吗?
答案 0 :(得分:2)
在移动点之前可能是set-mark?
(defun select-in-parens ()
(interactive)
(set-mark (point))
(goto-match-paren 1))