From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jeremy Bryant Newsgroups: gmane.emacs.bugs Subject: bug#65511: [PATCH] copy-next-command-output suggestion Date: Thu, 24 Aug 2023 22:46:28 +0100 Message-ID: <87ttsoqfbn.fsf@jeremybryant.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="18002"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.8.13; emacs 29.1 To: 65511@debbugs.gnu.org, monnier@iro.umontreal.ca Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Aug 24 23:53:14 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qZIGQ-0004TL-Gp for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 24 Aug 2023 23:53:14 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qZIGB-0005HR-R5; Thu, 24 Aug 2023 17:52:59 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qZIGA-0005Gx-4e for bug-gnu-emacs@gnu.org; Thu, 24 Aug 2023 17:52:58 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qZIG9-00023V-SW for bug-gnu-emacs@gnu.org; Thu, 24 Aug 2023 17:52:57 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qZIGE-0005xG-1L for bug-gnu-emacs@gnu.org; Thu, 24 Aug 2023 17:53:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Jeremy Bryant Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 24 Aug 2023 21:53:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 65511 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org, Stefan Monnier Original-Received: via spool by submit@debbugs.gnu.org id=B.169291392222814 (code B ref -1); Thu, 24 Aug 2023 21:53:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 24 Aug 2023 21:52:02 +0000 Original-Received: from localhost ([127.0.0.1]:38792 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qZIFG-0005vt-4I for submit@debbugs.gnu.org; Thu, 24 Aug 2023 17:52:02 -0400 Original-Received: from lists.gnu.org ([2001:470:142::17]:49568) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qZIFE-0005vM-HB for submit@debbugs.gnu.org; Thu, 24 Aug 2023 17:52:01 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qZIF5-0005AK-1F for bug-gnu-emacs@gnu.org; Thu, 24 Aug 2023 17:51:51 -0400 Original-Received: from p3plsmtp26-03-2.prod.phx3.secureserver.net ([216.69.139.28] helo=p3plwbeout26-03.prod.phx3.secureserver.net) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qZIF2-0001r0-IK for bug-gnu-emacs@gnu.org; Thu, 24 Aug 2023 17:51:50 -0400 Original-Received: from mailex.mailcore.me ([94.136.40.142]) by :WBEOUT: with ESMTP id ZIEvqU55QxrDfZIEwqBRil; Thu, 24 Aug 2023 14:51:42 -0700 X-CMAE-Analysis: v=2.4 cv=Sawyytdu c=1 sm=1 tr=0 ts=64e7d0ee a=s1hRAmXuQnGNrIj+3lWWVA==:117 a=nzDM7VRi/FXkTBRroS9HBg==:17 a=yM0T0u6Ik-0A:10 a=UttIx32zK-AA:10 a=GDFeYmemqq2GeCUdHdoA:9 a=4ZrrpnpWAAAA:8 a=UMla8V_BtvULFz0MKFEA:9 a=1Cd5MWGGBJJ9eP861nmr:22 X-SECURESERVER-ACCT: jb@jeremybryant.net X-SID: ZIEvqU55QxrDf Original-Received: from [152.37.91.204] (helo=hexa3.local.com) by smtp13.mailcore.me with esmtpa (Exim 4.94.2) (envelope-from ) id 1qZIEy-0002zi-GH; Thu, 24 Aug 2023 22:51:44 +0100 X-Mailcore-Auth: 278589627 X-Mailcore-Domain: 1689493 X-123-reg-Authenticated: jb@jeremybryant.net X-Originating-IP: 152.37.91.204 X-CMAE-Envelope: MS4xfDLhtM6Ax++75Dh7xSNYGkDlVndqEyYk2cVQ0Md9iHy1nahYKCePuPQmpUkBV/5cQeCeeaDv9tpw0MXhvRvHWtvnzYd9fjcOk2WQXw0HTe5Xx8FQm2lu jdZwxddPjhpu8kVIveaPaEr1PNIE8Sl1lryLfu3TfLPcqo07nKvd4IofigAmjolcMnGO2HPr34dM6rpl1W0xwf1BtYPpsHKmmoc= Received-SPF: pass client-ip=216.69.139.28; envelope-from=jb@jeremybryant.net; helo=p3plwbeout26-03.prod.phx3.secureserver.net X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:268370 Archived-At: --=-=-= Content-Type: text/plain 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 --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Add-output-of-next-command-to-the-kill-ring.patch Content-Description: patch >From 4b797454bbf09556bfb23cbd01cae3e424da29d7 Mon Sep 17 00:00:00 2001 From: Jeremy Bryant 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 --=-=-=--