* Macro for defining a lineup of commands
@ 2017-06-26 8:59 Narendra Joshi
2017-06-26 9:30 ` Emanuel Berg
2017-07-01 16:07 ` John Ankarström
0 siblings, 2 replies; 4+ messages in thread
From: Narendra Joshi @ 2017-06-26 8:59 UTC (permalink / raw)
To: help-gnu-emacs
Hi,
I want to share a macro that I wrote recently. I really like it. I would
like to have suggestions to improve it and new use cases. :)
If there are better and more general alternatives to this, it would be
great to know. :)
,----
| (defmacro def-lineup (command docstring &rest commands)
| "Make a COMMAND with DOCSTRING to run COMMANDS in order on repeated usage.
| Currently works for commands that need no interactive input. It
| automatically makes the sequence a circular sequence
| logically. That's because `(car nil)' equals nil.
|
| Argument DOCSTRING would serve as the docstring for COMMAND.
|
| Example usage:
| \(def-lineup fill-unfill
| \"Cycle between filling a line, filling a para and unfill.\"
| #'auto-fill-current-line #'fill-paragraph #'unfill-paragraph)
|
| This would define a new command with the name fill-unfill that
| would run commands in '(auto-fill-current-line fill-paragraph unfill-paragraph)
| one after the other in a circular fashion, when called repeatedly."
| `(defun ,command () ,docstring
| (interactive)
| (let* ((command-sequence
| (if-let ((cseq (get this-command 'command-sequence))
| (_ (eq last-command this-command)))
| cseq
| (list ,@commands)))
| (next-command (car command-sequence)))
| (message (format "-> %s" next-command))
| (call-interactively next-command)
| (put this-command 'command-sequence (cdr command-sequence)))))
`----
Best,
--
Narendra Joshi
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-07-01 16:07 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-06-26 8:59 Macro for defining a lineup of commands Narendra Joshi
2017-06-26 9:30 ` Emanuel Berg
2017-06-26 10:02 ` Narendra Joshi
2017-07-01 16:07 ` John Ankarström
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).