unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Clemens <clemera@posteo.net>
Cc: emacs-devel@gnu.org
Subject: Re: A different way to interactively pass options to commands
Date: Wed, 17 Feb 2021 15:07:39 -0500	[thread overview]
Message-ID: <jwvtuqaea3a.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <e329f68a-21d2-6c1a-5528-44c4e8513091@posteo.net> (Clemens's message of "Wed, 17 Feb 2021 20:50:02 +0100")

> 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	other threads:[~2021-02-17 20:07 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-17 19:50 A different way to interactively pass options to commands Clemens
2021-02-17 20:07 ` Stefan Monnier [this message]
2021-02-17 20:20   ` Lars Ingebrigtsen
2021-02-17 22:05     ` Stefan Monnier
2021-02-19  5:41   ` Richard Stallman
2021-02-19 14:30     ` Stefan Monnier
2021-02-17 20:09 ` Lars Ingebrigtsen
2021-02-17 20:32   ` Clemens
2021-02-17 20:42     ` Lars Ingebrigtsen
2021-02-17 20:58       ` Clemens
2021-02-17 21:24       ` Clemens
2021-02-17 22:15         ` Stefan Monnier
2021-02-17 21:48   ` Óscar Fuentes
2021-02-17 22:23     ` Stefan Monnier
2021-02-17 22:47       ` Óscar Fuentes
2021-02-17 23:52         ` Clemens
2021-02-17 22:24     ` Lars Ingebrigtsen
2021-02-17 23:18       ` Óscar Fuentes
2021-02-18 10:09         ` Lars Ingebrigtsen
2021-02-18  1:16       ` Doug Davis
2021-02-18 10:03         ` Lars Ingebrigtsen
2021-02-18 10:39           ` Kévin Le Gouguec
2021-02-18 10:52             ` Lars Ingebrigtsen
2021-02-18 12:13               ` Dmitry Gutov
2021-02-18 17:45                 ` Stefan Kangas
2021-02-18 17:55                   ` Dmitry Gutov
2021-02-18 18:32                     ` Stefan Kangas
2021-02-19 11:59                       ` Lars Ingebrigtsen
2021-02-18 16:11               ` Óscar Fuentes
2021-02-18 15:40             ` Stefan Monnier
2021-02-18 16:28               ` Development snapshots on GNU ELPA (was: A different way to interactively pass options to commands) Kévin Le Gouguec
2021-02-19 12:01               ` A different way to interactively pass options to commands Lars Ingebrigtsen
2021-02-19 14:32                 ` Stefan Monnier
2021-02-21 14:55                   ` GNU-devel and NonGNU-devel (was: A different way to interactively pass options to commands) Basil L. Contovounesios
2021-02-21 20:25                     ` GNU-devel and NonGNU-devel Stefan Monnier
2021-02-25  2:19                       ` Basil L. Contovounesios
2021-02-19 15:44               ` A different way to interactively pass options to commands Jonas Bernoulli
2021-02-19 18:23                 ` Clemens
2021-02-22  0:18                   ` Jonas Bernoulli
2021-02-22  2:39                     ` T.V Raman
2021-02-22  9:17                     ` Questions about transient (was: Re: A different way to interactively pass options to commands) Joost Kremers
2021-02-22 15:08                       ` Jonas Bernoulli
2021-02-22 21:06                         ` Joost Kremers
2021-02-22 16:25                       ` [External] : " Drew Adams
2021-02-23 12:15                     ` A different way to interactively pass options to commands Stephen Leake
2021-02-23 19:06                       ` Jonas Bernoulli
2021-02-19  5:42     ` Richard Stallman
2021-02-19  6:32       ` Stefan Kangas
2021-02-21 10:28   ` Phil Sainty

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwvtuqaea3a.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=clemera@posteo.net \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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