unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* 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

* Re: Macro for defining a lineup of commands
  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
  1 sibling, 1 reply; 4+ messages in thread
From: Emanuel Berg @ 2017-06-26  9:30 UTC (permalink / raw)
  To: help-gnu-emacs

Narendra Joshi wrote:

> (message (format "-> %s" next-command))

Complicated code, as always with macros.

The only thing I can see from skimming the code
is this line, which can drop the `format' IINM.

Good work!

-- 
underground experts united
http://user.it.uu.se/~embe8573




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Macro for defining a lineup of commands
  2017-06-26  9:30 ` Emanuel Berg
@ 2017-06-26 10:02   ` Narendra Joshi
  0 siblings, 0 replies; 4+ messages in thread
From: Narendra Joshi @ 2017-06-26 10:02 UTC (permalink / raw)
  To: help-gnu-emacs

Emanuel Berg <moasen@zoho.com> writes:

> Narendra Joshi wrote:
>
>> (message (format "-> %s" next-command))
>
> Complicated code, as always with macros.
>
> The only thing I can see from skimming the code
> is this line, which can drop the `format' IINM.
Yes, you are right! :) `format' is redundant here. 

> Good work!
Thanks! :)

-- 
Narendra Joshi



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Macro for defining a lineup of commands
  2017-06-26  8:59 Macro for defining a lineup of commands Narendra Joshi
  2017-06-26  9:30 ` Emanuel Berg
@ 2017-07-01 16:07 ` John Ankarström
  1 sibling, 0 replies; 4+ messages in thread
From: John Ankarström @ 2017-07-01 16:07 UTC (permalink / raw)
  To: help-gnu-emacs

Narendra Joshi <narendraj9@gmail.com> writes:

> 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. :)

It looks very good! Great idea and execution. The only thing you
might want to do is to make the docstring optional, like it is
for functions. Otherwise really nice!

- John



^ 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).