这是我通常使用的。不知何故,杀死平衡的表达而不是复制对我来说更有用。如果我想要一个副本,我会先杀死,然后撤消。
如果该点在字符串内部,则此函数将终止一个字符串,否则为平衡表达式,即, ,()
或[]
语法
定义的任何内容。{}
<>
(defun kill-at-point ()
"Kill the quoted string or the list that includes the point"
(interactive)
(let ((p (nth 8 (syntax-ppss))))
(cond
;; string
((eq (char-after p) ?\")
(goto-char p)
(kill-sexp))
;; list
((ignore-errors (when (eq (char-after) ?\()
(forward-char))
(up-list)
t)
(let ((beg (point)))
(backward-list)
(kill-region beg (point)))))))
我还尝试为该点在注释内时添加一个特殊情况,但我找不到一种通用的方法来确定该点的注释范围。如果有人知道,请告诉我。
这个其他功能也可能是相关的。它标记而不是杀戮,就像前一个一样。每次调用它都会扩展区域,这是一件好事。我将第一个绑定到C-,,第二个绑定到
C-M-,.
(defun mark-at-point ()
"Mark the quoted string or the list that includes the point"
(interactive)
(let ((p (nth 8 (syntax-ppss))))
(if (eq (char-after p) ?\")
(progn
(goto-char p)
(set-mark (point))
(forward-sexp))
(progn
(when (eq (char-after) 40)
(forward-char))
(condition-case nil
(progn
(up-list)
(set-mark (point))
(let ((beg (point)))
(backward-list)
(exchange-point-and-mark)))
(error
(when (looking-back "}")
(exchange-point-and-mark)
;; assumes functions are separated by one empty line
(re-search-backward "^[^A-Z-a-z]" nil t)
(forward-char))))))))