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 15:13:37 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

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




reply via email to

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