Selection Function Notes when Expanding in Lisp Modes

I am using the keyboard shortcut associated with:

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

      

to expand the area.

For example, when I want to select a function and move it.

My problem is that if I want to select any function like:

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

      

I can't "expand" to include ";; some comment". As soon as I expand the function (no comment), it expands the full buffer.

For now, I would like it to expand first to include the function and comment and then the full buffer.

This worries me so much that I temporarily do this as a workaround:

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

      

How do I change the er / expand-region (or other function) so that after expanding to a full function, it expands comments right above the function before it expands to the entire buffer?

+3


source to share


2 answers


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

Example:

Let's say you want the extension area to also mark paragraphs and pages in text mode. By the way, Emacs already comes with paragraph and page markup. To add it to the list of attempts, do the following:

 (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-expand-extensions)

Add this to its own file and add it to the expand-region.el file where it says "Miscellaneous Extensions"

Warning. Poorly written extensions can slow down area expansion dramatically. Be sure to exit quickly before you start your entire document looking for labels to mark.

I would say that you can add "er / mark-paragraph" to the list of extension scopes that should do this.

+3


source


Following advice from Dualinity user, I added the following to clojure -mode-expansions.el (can be done for modes other than Clojure, of course):

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

      

Then I added the er / mark-paragraph line to the spread list inside the method 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))))

      

I restarted Emacs (not too sure what it takes to be sure it was taken into account, so I restarted the whole thing).

And what it is: now the extension also selects comments from "external" functions.

+1


source







All Articles