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: tomas
Subject: Re: Is there a way to get the last message?
Date: Sun, 28 May 2017 13:51:39 +0200
User-agent: Mutt/1.5.21 (2010-09-15)

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Sun, May 28, 2017 at 12:50:12PM +0200, Marcin Borkowski 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.

This might get you started:

  (defun parrot ()
    (interactive)
    (save-excursion
      (with-current-buffer (messages-buffer)
        ;; *Messages* seems to have a newline at end
        (goto-char (- (point-max) 1))
        (message "last message was '%S'"
                 (buffer-substring-no-properties
                  (line-beginning-position)
                  (line-end-position))))))

A couple of notes:

 - it seems that messages not always end up in the *Messages* buffer
 - the function (messages-buffer) is the recommended was to retrieve
   the messages buffer, which (most of the time? always?) is called
   *Messages*
 - you might want to double check the strategy for fetching the last
   line (i.e. going to point-max - 1
 - I put the thing into a message with (buffer-substring ...), you
   might want to dump it directly into the kill ring, of course

In the meantime, Stephen's reply seems to have addressed most of the
above points, anyway; but the recommended way to access *Messages*
might still be helpful.

Cheers
- -- t
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)

iEYEARECAAYFAlkqucsACgkQBcgs9XrR2kaxRQCcD6/D1RasdLi1xPNaqb3GI8TU
1CoAn3ieUdT4cRp8gXOVzyYxZXUYJJr3
=pAqo
-----END PGP SIGNATURE-----



reply via email to

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