From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Richard Copley Newsgroups: gmane.emacs.devel Subject: Re: A patch for `pwd' - copying the current directory to the kill ring Date: Thu, 25 Jan 2018 23:05:54 +0000 Message-ID: References: <871sieozdg.fsf@mbork.pl> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" X-Trace: blaine.gmane.org 1516921533 18783 195.159.176.226 (25 Jan 2018 23:05:33 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 25 Jan 2018 23:05:33 +0000 (UTC) Cc: Emacs Development To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Jan 26 00:05:29 2018 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eeqZw-0003N0-TU for ged-emacs-devel@m.gmane.org; Fri, 26 Jan 2018 00:05:09 +0100 Original-Received: from localhost ([::1]:42744 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eeqbv-0005Ry-Rm for ged-emacs-devel@m.gmane.org; Thu, 25 Jan 2018 18:07:11 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:35271) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eeqbE-0005Rl-0V for emacs-devel@gnu.org; Thu, 25 Jan 2018 18:06:29 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eeqbC-0004vc-W5 for emacs-devel@gnu.org; Thu, 25 Jan 2018 18:06:27 -0500 Original-Received: from mail-ot0-x235.google.com ([2607:f8b0:4003:c0f::235]:33507) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eeqbC-0004tk-R3 for emacs-devel@gnu.org; Thu, 25 Jan 2018 18:06:26 -0500 Original-Received: by mail-ot0-x235.google.com with SMTP id d7so8591970oti.0 for ; Thu, 25 Jan 2018 15:06:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=QwCO9QastciEhdWP0Lj3KONYP5DwJPMGuFyAyRY9JKc=; b=LrqEG6DHM/pFNmeV/+Xj0+TajsZwA6ZwkxOm6rixYfhtcvOi/xmTDo+0VzMEmH60sz QZzC6EucVO4Dpw4OmjLGWJomJLGkWJoIcRTbXgPXglbPdiiq3nMtDXd2a7MopI4/CEDv FD8/upzAcxhoURqGi7/z1Mw1JaWgJDQY71rO7pv7RkmlqkQVucxrOgosrH8v9p+dwUX2 sUSVjXEPuvd9IsemAJvV22v08iRvcjyVa/HpCGalw0cE1MEE3M/WUZG7EA4eKa8WKR8T +lwQVO5brrb4hcpHRfwP/bfbyklVmkW/vaV+IN+EhKTUBW1F2yPp+VYqmDGsQSI9vbM/ 6WCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=QwCO9QastciEhdWP0Lj3KONYP5DwJPMGuFyAyRY9JKc=; b=tAcLRB2IdxBRZc/BQuHlFvJx+iITPPXHIqf/zfWbQppiBi2gAKnBiDr82qMjCdgLAF rH4jsn3Gcu9w1ly4qqFfdr3zaKGpHC/4VZ5GVOyJyzE46fXIkNXoaf4QiJeJoxoMIkXo Z9rGeOagRR4Nawy1RbO3x1jm4D1RjQ3UFnYOsKFueCZT9JtE+bfHFkBWQf85+Rddsju0 Erzc7qjH5N8mbx50QnUZCeu/tLR8rVPR87mgxzn404C4Ofe+6KB1be2thMfOBM97JeCW V4n8sVp3fhKDz/X92jnWENr9c9GDtVXyI0iTtwkfPQv1JYOHUvV9/uDH5ifMRjG1p9Dq sz2A== X-Gm-Message-State: AKwxyte2saCra1Rt2VaZHtQr6vjZp6R6chtyWBhWM4ZmHlXKS2ud+NFn SYEi3uY/Zl48abjbHpt/kQ5rndCEWnINWw5456o= X-Google-Smtp-Source: AH8x225gC331iSi8Hoq7OTHvwc1lve6C92J+41LMsv6ZrO+Cq0dHMlUkc/sSztvhgndLz088zJ11DbmPN3ES5FBF27s= X-Received: by 10.157.19.46 with SMTP id f43mr12780512ote.139.1516921585676; Thu, 25 Jan 2018 15:06:25 -0800 (PST) Original-Received: by 10.157.74.83 with HTTP; Thu, 25 Jan 2018 15:05:54 -0800 (PST) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4003:c0f::235 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:222243 Archived-At: On 25 January 2018 at 20:13, Stefan Monnier wrote: >> Except making it work with M-x (the above will grab the "output" of the >> M-x itself (i.e. no output), rather than the output of the command Emacs >> runs after running the commands bound to M-x, p, w, d, and RET). > > The version below seems to work (tested with M-: and M-x) > > > Stefan > > > (defvar copy-next-command-output--marker nil) > (defun copy-next-command-output () > "Prefix command to add the output of the next command to the `kill-ring`." > (interactive) > (let ((ml (minibuffer-depth))) > (cl-labels ((pre () > (add-hook 'post-command-hook #'post) > (setq copy-next-command-output--marker > (with-current-buffer "*Messages*" > (point-max-marker)))) > (post () > (unless (> (minibuffer-depth) ml) > (remove-hook 'pre-command-hook #'pre) > (remove-hook 'post-command-hook #'post) > (when copy-next-command-output--marker > (with-current-buffer > (marker-buffer copy-next-command-output--marker) > (when (< copy-next-command-output--marker > (point-max)) > (kill-new (buffer-substring > copy-next-command-output--marker > (point-max))))) > (setq copy-next-command-output--marker nil))))) > (add-hook 'pre-command-hook #'pre)))) I evaluated those two forms, and this one: (global-set-key [?\C-c ?p] #'copy-next-command-output) Then in an empty buffer, ;; Put "x" on the kill ring x ;; backward-kill-word ;; Test the new prefix command on "M-x pwd" C-c p M-x pwd RET C-y ;; yank The result is "x" (in emacs-26 -Q). Where did I go wrong? The interactive message output of a command (in this case, e.g., "Directory C:/Users/Buster") is not usually going to be useful as a building block. I think the generalisation is unwarranted in this case anyway. I bind C-c f to a command that puts the pwd on the kill ring, with a few tweaks to make it more useful to me (it optionally replaces "/" with "\", and if called in a buffer visiting a file, returns the file's name). It's more specialised, not more general. I use it a lot.