unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Stephen Berman <stephen.berman@gmx.net>
To: Marcin Borkowski <mbork@mbork.pl>
Cc: Help Gnu Emacs mailing list <help-gnu-emacs@gnu.org>
Subject: Re: Is there a way to get the last message?
Date: Sun, 28 May 2017 13:18:47 +0200	[thread overview]
Message-ID: <87lgphp6ug.fsf@rosalinde> (raw)
In-Reply-To: <87r2z92r2z.fsf@jane> (Marcin Borkowski's message of "Sun, 28 May 2017 12:50:12 +0200")

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	other threads:[~2017-05-28 11:18 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-28 10:50 Is there a way to get the last message? Marcin Borkowski
2017-05-28 11:18 ` Stephen Berman [this message]
2017-05-28 11:41   ` John Ankarström
2017-05-29 18:51     ` Emanuel Berg
2017-05-28 14:12   ` Marcin Borkowski
2017-05-28 22:11   ` Emanuel Berg
2017-05-28 11:51 ` tomas
2017-05-28 18:24 ` Emanuel Berg

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=87lgphp6ug.fsf@rosalinde \
    --to=stephen.berman@gmx.net \
    --cc=help-gnu-emacs@gnu.org \
    --cc=mbork@mbork.pl \
    /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.
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).