From: Jeremy Bryant <jb@jeremybryant.net>
To: 65511@debbugs.gnu.org, monnier@iro.umontreal.ca
Subject: bug#65511: [PATCH] copy-next-command-output suggestion
Date: Thu, 24 Aug 2023 22:46:28 +0100 [thread overview]
Message-ID: <87ttsoqfbn.fsf@jeremybryant.net> (raw)
[-- Attachment #1: Type: text/plain, Size: 575 bytes --]
Hello, Emacs maintainers.
The command copy-next-command-output copies the output of the next
command, and having used it for several months, I would like to suggest
this for Emacs core. It doesn't appear to be part of Emacs. I
typically bind this C-c u.
This code was provided by Stefan on this list or emacs-devel, so the
author should be changed accordingly (I haven't modified Stefan's code,
just used it).
Thoughts welcome as this is my first patch suggestion. It could also be
put in a package in ELPA. I have signed the paperwork.
Thanks in advance
Jeremy
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch --]
[-- Type: text/x-diff, Size: 2822 bytes --]
From 4b797454bbf09556bfb23cbd01cae3e424da29d7 Mon Sep 17 00:00:00 2001
From: Jeremy Bryant <jb@jeremybryant.net>
Date: Thu, 24 Aug 2023 22:42:29 +0100
Subject: [PATCH] Add output of next command to the kill ring
---
lisp/misc.el | 47 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 47 insertions(+)
diff --git a/lisp/misc.el b/lisp/misc.el
index e8b38fad42e..5bd3c720206 100644
--- a/lisp/misc.el
+++ b/lisp/misc.el
@@ -327,6 +327,53 @@ list-dynamic-libraries
(display-buffer buffer)
nil)
+(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)
+ )))
+
+
(provide 'misc)
;;; misc.el ends here
--
2.40.1
next reply other threads:[~2023-08-24 21:46 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-24 21:46 Jeremy Bryant [this message]
2023-08-25 6:05 ` bug#65511: [PATCH] copy-next-command-output suggestion Eli Zaretskii
2023-09-04 22:17 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-05 11:14 ` Eli Zaretskii
2023-09-05 13:10 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-05 18:33 ` Jeremy Bryant
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=87ttsoqfbn.fsf@jeremybryant.net \
--to=jb@jeremybryant.net \
--cc=65511@debbugs.gnu.org \
--cc=monnier@iro.umontreal.ca \
/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).