emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A patch for `pwd' - copying the current directory to the kill ring


From: Stefan Monnier
Subject: Re: A patch for `pwd' - copying the current directory to the kill ring
Date: Thu, 25 Jan 2018 09:36:30 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

> I wouldn't even mind copying the default-directory to kill ring by default.
> Then you don't need C-u C-u.
> - M-x pwd would show the pwd and *also copy it to kill-ring*.
> - C-u M-x pwd will only insert the pwd at point (as before).

I don't have an opinion on this change, but it gives me the impression
that we'd be better served by a more general solution, something like

    (defvar copy-next-command-output--marker nil)
    (defun copy-next-command-output ()
      "Add the output of the next command to the `kill-ring`."
      (interactive)
      (cl-labels ((pre ()
                       (remove-hook 'pre-command-hook #'pre)
                       (add-hook 'post-command-hook #'post)
                       (setq copy-next-command-output--marker
                             (with-current-buffer "*Messages*"
                               (point-max-marker))))
                  (post ()
                        (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)))

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


        Stefan




reply via email to

[Prev in Thread] Current Thread [Next in Thread]