bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#17871: 24.4.50; (elisp) `Core Advising Primitives': interactive spec


From: Štěpán Němec
Subject: bug#17871: 24.4.50; (elisp) `Core Advising Primitives': interactive spec as function?
Date: Sun, 18 Aug 2019 15:32:43 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

On Sun, 18 Aug 2019 14:26:38 +0200
Michael Heerdegen wrote:

>> > (2) Enhance a command to accept an additional argument.  The interactive
>> > form of the :around advice will reuse the interactive form of the
>> > original command to read in the arguments the original command accepts,
>> > read in the additional argument, and return the combined list.
>>
>> I think an example along these lines would be very nice for the manual.
>
> Štěpán, any nice idea which command I could use to write the example?

Well, the closest I see in my init is this (in fact I have been doing it
differently and more uglily, but now I see this is simpler):

(defun my-compose-mail-advice (orig &rest args)
  "Read From: address interactively."
  (interactive (lambda (spec)
                 (let* ((user-mail-address
                         (completing-read "From: " '("address@hidden"
                                                     "address@hidden")))
                        (from (message-make-from user-full-name
                                                 user-mail-address))
                        (spec (advice-eval-interactive-spec spec)))
                   ;; notmuch doesn't understand "From", it has to be a symbol
                   (push (cons 'From from) (nth 2 spec))
                   spec)))
  (apply orig args))

(advice-add 'compose-mail :around #'my-compose-mail-advice)

One might argue that, given the simple nature of `compose-mail' original
interactive spec (no actual user interaction), constructing a plain list
disregarding the original would suffice here, but it would really be
almost the same.

I'm sure one could come up with better examples, but I can't think of
anything off the top of my head.

-- 
Štěpán





reply via email to

[Prev in Thread] Current Thread [Next in Thread]