emacs-devel
[Top][All Lists]
Advanced

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

Re: master a30781399b3: * subr-x (eval-command-interactive-spec): New fu


From: Stefan Monnier
Subject: Re: master a30781399b3: * subr-x (eval-command-interactive-spec): New function.
Date: Wed, 14 Jun 2023 16:52:37 -0400
User-agent: Gnus/5.13 (Gnus v5.13)

>> AFAICT the functionality of `advice-eval-interactive-spec` is not used
>> often at all, so having a specialized version for the specific case when
>> it's applied to (cadr (interactive-form command)) seems hard to justify.
>>
>> Can you point to (potential) users?
>
> Here is something I have:
>
>     (defun spw/run-or-restore-gud (arg)
>       (interactive "P")
>       (if (or arg (not (and (bound-and-true-p gud-comint-buffer)
>                             (get-buffer-process gud-comint-buffer))))
>           ;; Start a new debugging session even if one already exists.
>           ;; Killing `gud-comint-buffer' is the documented way to quit an
>           ;; existing session.
>           (let* ((cmd (cl-case major-mode
>                         (c-mode 'gdb) (cperl-mode 'perldb) (python-mode 'pdb)
>                         (t (intern (completing-read "GUD command: "
>                                                     '(gdb perldb pdb) nil 
> t)))))
>                  (args (eval-command-interactive-spec cmd)))
>             (when (buffer-live-p gud-comint-buffer)
>               (when-let ((proc (get-buffer-process gud-comint-buffer)))
>                 (set-process-query-on-exit-flag proc nil))
>               (kill-buffer gud-comint-buffer))
>             (gdb-wait-for-pending (lambda () (apply cmd args))))
>         ;; Restore the session.
>         (cl-case (buffer-local-value 'gud-minor-mode gud-comint-buffer)
>           (gdbmi (gdb-restore-windows)
>                  ;; Try to ensure prompt is at the bottom of its window.
>                  (recenter (window-body-height)))
>           (t (pop-to-buffer gud-comint-buffer)))))
>
> I initially tried implementing this using :around advice, but found that
> worked less well in some respect that I can now not remember.
> But I definitely tried it :)

OK, so that's one example.  Any other?  Because, to me, a single
use-case doesn't seem to justify the definition of a one-liner helper
function.
[ Especially since that helper function is still not a faithful
  simulation of what happens in a "normal" execution of the command
  and fixing that wrinkle will likely require changing the API :-(  ]


        Stefan




reply via email to

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