help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: Is there a way to get the last message?


From: Stephen Berman
Subject: Re: Is there a way to get the last message?
Date: Sun, 28 May 2017 13:18:47 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux)

On Sun, 28 May 2017 12:50:12 +0200 Marcin Borkowski <mbork@mbork.pl> wrote:

> Hi all,
>
> I know about (current-message).  However, this won't work:
>
> (defun get-last-message ()
>   "Try to get the last message."
>   (interactive)
>   (with-temp-buffer
>     (insert (or (current-message) ""))
>     (clipboard-kill-ring-save (point-min) (point-max))))
>
> M-x get-last-message puts the empty string into the clipboard and kill
> ring.
>
> Apparently `current-message' is cleared before this command has a chance
> to get it.  This makes sense, but there is no `previous-message' command.
>
> Is there any way to get the last thing displayed in the echo area (from
> `message' or possibly from `error', too)?  This would be quite useful:
> one could then paste it to a search engine to look up the internet for
> some hints about the error/message.

What about this:

(defun get-last-message ()
  "Try to get the last message."
  (interactive)
  (with-current-buffer "*Messages*"
    (goto-char (point-max))
    (forward-line -1)
    (clipboard-kill-ring-save (line-beginning-position) (line-end-position))))

(add-hook 'post-command-hook 'get-last-message)

Steve Berman



reply via email to

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