3

我正在使用绑定到的键盘快捷键:

er/expand-region, which is an interactive Lisp function in `expand-region-core.el'.

扩大区域。

例如,当我想选择一个函数并移动它时。

我的问题是,如果我想选择任何功能,比如:

;; some comment related to the function
(defn foo [x]
  ...)

我不能“扩展”以包括“;;一些评论”。一旦我扩展的功能超过了函数(没有注释),它就会消耗整个缓冲区。

虽然我希望它首先扩展以包含函数和注释,然后是完整的缓冲区。

这让我非常困扰,以至于我暂时将其作为一种解决方法:

(defn foo [x]
  ;; some comment
  ...)

如何修改 er/expand-region (或其他函数),以便在扩展为完整函数后,在扩展为整个缓冲区之前扩展函数正上方的注释?

4

2 回答 2

3

From Magnar Sveen, the creator of the package expand-region, taken from his github:

Example:

Let's say you want expand-region to also mark paragraphs and pages in text-mode. Incidentally Emacs already comes with mark-paragraph and mark-page. To add it to the try-list, do this:

 (defun er/add-text-mode-expansions ()   (make-variable-buffer-local
 'er/try-expand-list)   (setq er/try-expand-list (append
                             er/try-expand-list
                             '(mark-paragraph
                               mark-page))))

(add-hook 'text-mode-hook 'er/add-text-mode-expansions)

Add that to its own file, and add it to the expand-region.el-file, where it says "Mode-specific expansions"

Warning: Badly written expansions might slow down expand-region dramatically. Remember to exit quickly before you start traversing the entire document looking for constructs to mark.

I would say you could add "er/mark-paragraph" to the expand-region list, that should do it.

于 2013-01-25T20:58:55.133 回答
1

按照用户Dualinity 的建议,我在clojure-mode-expansions.el中添加了以下内容(当然,可以为 Clojure 以外的其他模式完成):

;; added this line at the beginning of the file
(require 'org-mode-expansions)

然后我将 er/mark-paragraph 行添加到方法内的展开列表中er/add-clojure-mode-expansions

(defun er/add-clojure-mode-expansions ()
  "Adds clojure-specific expansions for buffers in clojure-mode"
  (set (make-local-variable 'er/try-expand-list) (append
                                                  er/try-expand-list
                                                  '(er/mark-clj-word
                                                    er/mark-clj-regexp-literal
                                                    er/mark-paragraph ; added this line
                                                    er/mark-clj-function-literal))))

我重新启动了 Emacs(不太确定需要什么来确保它被考虑在内,所以我重新启动了整个事情)。

就是这样:现在扩展也选择了“外部”函数注释。

于 2013-01-25T21:28:39.307 回答