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

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

Re: `last-message' variable ?


From: Tim X
Subject: Re: `last-message' variable ?
Date: Tue, 16 May 2006 21:58:55 +1000
User-agent: Gnus/5.110004 (No Gnus v0.4) Emacs/22.0.50 (gnu/linux)

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 via email to

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