unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Richard Copley <rcopley@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: Emacs Development <emacs-devel@gnu.org>
Subject: Re: A patch for `pwd' - copying the current directory to the kill ring
Date: Thu, 25 Jan 2018 23:05:54 +0000	[thread overview]
Message-ID: <CAPM58ojYdyogr5B3f8UKa_pafOXcFHtUTwqJgdwSAL1xQpxxNA@mail.gmail.com> (raw)
In-Reply-To: <jwvmv11y9xm.fsf-monnier+gmane.emacs.devel@gnu.org>

On 25 January 2018 at 20:13, Stefan Monnier <monnier@iro.umontreal.ca> 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
<C-backspace>    ;; 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.



  reply	other threads:[~2018-01-25 23:05 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-25 13:13 A patch for `pwd' - copying the current directory to the kill ring Marcin Borkowski
2018-01-25 13:44 ` Kaushal Modi
2018-01-25 14:36   ` Stefan Monnier
2018-01-25 20:13     ` Stefan Monnier
2018-01-25 23:05       ` Richard Copley [this message]
2018-01-25 23:23         ` Stefan Monnier
2018-02-01 21:11           ` Marcin Borkowski
2018-02-01 22:03             ` Alexis
2018-02-02  1:59             ` Stefan Monnier
2018-02-02  8:51               ` Eli Zaretskii
2018-02-02 17:29                 ` Stefan Monnier
2018-02-03  0:02                   ` Richard Copley
2018-02-02 23:59                 ` Richard Copley
2018-02-06 21:03               ` Marcin Borkowski
2018-01-26  7:55       ` Eli Zaretskii
2018-01-26 14:40         ` Stefan Monnier
2018-01-26 15:40           ` Eli Zaretskii
2018-02-01 21:09     ` Marcin Borkowski
2018-02-01 21:08   ` Marcin Borkowski
2018-01-25 15:47 ` Yuri Khan

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=CAPM58ojYdyogr5B3f8UKa_pafOXcFHtUTwqJgdwSAL1xQpxxNA@mail.gmail.com \
    --to=rcopley@gmail.com \
    --cc=emacs-devel@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).