Skip to content

Instantly share code, notes, and snippets.

@nicferrier
Created December 31, 2020 18:03
Show Gist options
  • Save nicferrier/ec338b7f1cc5f59b3925836f2c44631e to your computer and use it in GitHub Desktop.
Save nicferrier/ec338b7f1cc5f59b3925836f2c44631e to your computer and use it in GitHub Desktop.
(defun motionless-mark ()
"Do commands until a command.
Remember point and then read a key to end a sequence of commands.
The sequence is read (until you enter the key that is being matched
as the end marker) and executed and then, when the end command is
matched, point is moved back to the remembered location and
the end command is executed.
This can be useful for things like slurp."
(interactive)
(cl-flet ((read-action (&optional prompt)
(let ((key-seq (read-key-sequence-vector (or prompt "move mark:"))))
(list key-seq
(lookup-key (current-global-map) key-seq)))))
(let* ((l (list 1))
(last l)
(start (point))
(mark-set nil)
(original-action (read-action "end command"))
(action (read-action)))
(while (not (equal (cadr action) (cadr original-action)))
(let ((insertion (cons action nil)))
(setq last (setcdr last insertion))
(message "action: %s" action)
(if (equal (cadr action) 'isearch-forward)
(funcall (cadr action))
(call-interactively (cadr action) nil (car action)))
(unless mark-set
(set-mark (point))
(setq mark-set t))
(setq action (read-action))))
(goto-char start)
(call-interactively (cadr original-action)))))
@nicferrier
Copy link
Author

nicferrier commented Dec 31, 2020

I wrote this because I get frustrated with paredit and smartparens.

@Fuco1 did a really good job with smartparens... but it's a big depend that is pretty hard to carry around.

Emacs' electric-pair-mode on the other hand, does most things without any depends, but it does not have slurp, which I often need, or barf, which I need more rarely.

When I started to toy with implementing simple forms of these I started to hit on what I think should be more of a general principle. Being able to issue Emacs commands without moving, as it were. Perhaps this is just recursive edit. But I don't think it is quite.

I see being able to execute commands against multiple regions and being able to slurp into a pair, as the same sort of problem.

I think a related problem might be Emacs' location tracking. I have often wanted a ring buffer of the locations I move to and I wonder if that is just another way to deal with the slurp problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment