Call me an uncultured non-functional programmer (or call emacs-lisp and uncultured non-functional language), but when I code in elisp I tend to use the following pattern (Edit: As an alternative to
(let (variable1 variable2) (setq variable1 (some-function)) (setq variable2 (some-function))
I tend to find this more readable for my uncultured eyes.
Unfortunately, this means there is a lot of jumping back and forward between
Is there a way for me to quickly and easily insert a name into the surrounding
let as shown:
(let () ... CURSOR
(let (variable) ... CURSOR stays still
emr has some functions for emacs lisp refactoring. But not the one I want. The closest is extracting variables to let (together with assignment). I had a look at extending this but balked at the amount of code I would need to understand.
I had a brief look at erefactor, but relevant functionality wasn't there.
Code it myself This isn't hard, it's just I would prefer to use someone else's implementation should it exist. This feels like the sort of thing that should exist.
Edit: An example of why you might want to do this
Here is a function that sums numbers on the two previous lines and inserts the result.
(defun sum-lines () (let (a b) (previous-line 2) (setq a (string-to-int (thing-at-point 'line)) (forward-line 1) (setq b (string-to-int (thing-at-point 'line))) (forward-line 1) (insert (format "%S" (+ a b))))
Do you actaully want to write this as
(let* ( (a (save-excursion (previous-line 2) (thing-at-point 'line)) (b (save-excursion (previous-line 1) (thing-at-point 'line))
(let* ( (a (progn (previous-line 2) (thing-at-point 'line)) (b (progn (next-line 1) (thing-at-point 'line))
(defun line-at (n) (save-excursion (previous-line n) (string-to-int (thing-at-point 'line)) (insert (+ (line-at 2) (line-at 1)))