emacs-devel
[Top][All Lists]
Advanced

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

Re: A different way to interactively pass options to commands


From: Stefan Monnier
Subject: Re: A different way to interactively pass options to commands
Date: Wed, 17 Feb 2021 15:07:39 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

> The recent discussion around changing `interactive' made me think
> about ways to improve that. Magit has shown a real nice UI approach to
> pass options with its transient menus. Maybe a simpler but similar
> mechanism could be added which could also be configured via
> `interactive'. Any opinions on this?

Yes, maybe.

FWIW, there are other prefix commands than C-u.
There's `C-x RET c`.
In the `other-frame-window` GNU ELPA package there are such prefix
commands to force the use of "other frame" or "other window" (arguably
there could/should be one for "same window" as well).

I personally also use the one below.


        Stefan


(defun copy-next-command-output ()
  "Prefix command to add the output of the next command to the `kill-ring`."
  (interactive)
  (let ((md (minibuffer-depth))
        (marker (with-current-buffer "*Messages*"
                  (point-max-marker))))
    (cl-labels ((pre ()
                     (unless (> (minibuffer-depth) md)
                       (add-hook 'post-command-hook #'post)
                       (prepare)))
                (prepare ()
                         (with-current-buffer "*Messages*"
                           (move-marker marker (point-max))))
                (preserve ()
                          (unless (> (minibuffer-depth) md)
                            (remove-hook 'post-command-hook #'post)
                            (add-hook 'pre-command-hook #'pre)))
                (echo ()
                      (unless (> (minibuffer-depth) md)
                        "[copy-output]"))
                (post ()
                      (if (> (minibuffer-depth) md)
                          ;; Prepare, in case there's no pre-command-hook before
                          ;; the next post-command-hook.  E.g. in the case of
                          ;; execute-extended-command.
                          (prepare)
                        (remove-hook 'pre-command-hook #'pre)
                        (remove-hook 'post-command-hook #'post)
                        (remove-hook 'prefix-command-preserve-state-hook
                                     #'preserve)
                        (remove-hook 'prefix-command-echo-keystrokes-functions
                                     #'echo)
                        (prefix-command-update)
                        (with-current-buffer (marker-buffer marker)
                          (when (< marker (point-max))
                            (kill-new (buffer-substring marker (point-max)))))
                          (set-marker marker nil))))
      (add-hook 'prefix-command-preserve-state-hook #'preserve)
      (add-hook 'prefix-command-echo-keystrokes-functions #'echo)
      ;; (message "BEFORE: prefix-arg=%S current-prefix-arg=%S"
      ;;          prefix-arg current-prefix-arg)
      (prefix-command-preserve-state)
      ;; (message "AFTER: prefix-arg=%S current-prefix-arg=%S"
      ;;          prefix-arg current-prefix-arg)
      )))




reply via email to

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