unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Tim X <timx@nospam.dev.null>
Subject: Re: `last-message' variable ?
Date: Tue, 16 May 2006 21:58:55 +1000	[thread overview]
Message-ID: <87bqty9o5c.fsf@tiger.rapttech.com.au> (raw)
In-Reply-To: 87fyjamfaz.fsf@tallis.ilo.ucl.ac.uk

Bastien <bastien@xxx.fr> writes:

> Magnus Henoch <mange@freemail.hu> writes:
>
>> I have worked around it like this:
>>
>> (defun last-message ()
>>   "Display last message from *Messages* buffer."
>>   (interactive)
>>   (with-current-buffer "*Messages*"
>>     (save-excursion
>>       (goto-char (point-max))
>>       (previous-line)
>>       (message "%s" (buffer-substring (point) (1- (point-max)))))))
>
> Thanks.  I would preferably call this function `repeat-last-message'
> and make `last-message' a variable storing the result.
>
> (defvar last-message nil
>  "The last message from *Message* buffer.")
>
> (defun repeat-last-message ()
>   "Display last message from *Messages* buffer.
> Store it in `last-message'."
>   (interactive)
>   (with-current-buffer "*Messages*"
>     (save-excursion
>       (goto-char (point-max))
>       (previous-line)
>       (message (setq last-message
>          (buffer-substring (point) (1- (point-max))))))))
>
> (Of course, the *real* last message is a repeat of the `last-message'
> value, which might first seem awkward.)
>
> I think Emacs could implement this i a more elegant way - like a
> message/warnings ring.

Another suggestion is to use defadvice on message. For example,

(defvar last-message nil)

(defadvice message (after my-message pre act)
  (setq last-message ad-return-value))

This is not tested and I'm going from memory. However, it should be
relatively simple to get working. I'm basing this on the premise
message returns the message it displays as its return value.

defadvice is an extremely powerful method for modifying the behavior
of existing functions. See the emacs lisp manual for more info. You
can use it to modify the environment prior to a function running,
before and after it runs (around) or after. You can modify function
arguments or return values etc. 

Tim

-- 
tcross (at) rapttech dot com dot au

  reply	other threads:[~2006-05-16 11:58 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-05-15 22:06 `last-message' variable ? Bastien
2006-05-16  8:45 ` Magnus Henoch
     [not found] ` <mailman.1884.1147769158.9609.help-gnu-emacs@gnu.org>
2006-05-16 10:31   ` Bastien
2006-05-16 11:58     ` Tim X [this message]
2006-05-16 12:44       ` Bastien
2006-05-16 14:57         ` Kim F. Storm
     [not found]         ` <mailman.1900.1147791985.9609.help-gnu-emacs@gnu.org>
2006-05-16 15:23           ` Bastien
2006-05-16 15:51             ` Drew Adams
     [not found] <mailman.1905.1147794706.9609.help-gnu-emacs@gnu.org>
2006-05-16 16:13 ` Bastien

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=87bqty9o5c.fsf@tiger.rapttech.com.au \
    --to=timx@nospam.dev.null \
    /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).