unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* `last-message' variable ?
@ 2006-05-15 22:06 Bastien
  2006-05-16  8:45 ` Magnus Henoch
       [not found] ` <mailman.1884.1147769158.9609.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 9+ messages in thread
From: Bastien @ 2006-05-15 22:06 UTC (permalink / raw)


Just guessing, i thought Emacs would have a `last-message' variable,
in case we want to fetch the last message quickly.  Apparently, this
is not the case.

How do i get the last message string ?

What about implementing this ?

-- 
Bastien

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: `last-message' variable ?
  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>
  1 sibling, 0 replies; 9+ messages in thread
From: Magnus Henoch @ 2006-05-16  8:45 UTC (permalink / raw)


Bastien <bastien@xxx.fr> writes:

> Just guessing, i thought Emacs would have a `last-message' variable,
> in case we want to fetch the last message quickly.  Apparently, this
> is not the case.
>
> How do i get the last message string ?
>
> What about implementing this ?

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)))))))

Magnus

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: `last-message' variable ?
       [not found] ` <mailman.1884.1147769158.9609.help-gnu-emacs@gnu.org>
@ 2006-05-16 10:31   ` Bastien
  2006-05-16 11:58     ` Tim X
  0 siblings, 1 reply; 9+ messages in thread
From: Bastien @ 2006-05-16 10:31 UTC (permalink / raw)


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.

-- 
Bastien

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: `last-message' variable ?
  2006-05-16 10:31   ` Bastien
@ 2006-05-16 11:58     ` Tim X
  2006-05-16 12:44       ` Bastien
  0 siblings, 1 reply; 9+ messages in thread
From: Tim X @ 2006-05-16 11:58 UTC (permalink / raw)


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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: `last-message' variable ?
  2006-05-16 11:58     ` Tim X
@ 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>
  0 siblings, 2 replies; 9+ messages in thread
From: Bastien @ 2006-05-16 12:44 UTC (permalink / raw)


Tim X <timx@nospam.dev.null> writes:

> 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))

Works great, thanks!  And this is *really* more elegant.  I should
think the defadvice-way more often.

Regards,

-- 
Bastien

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: `last-message' variable ?
  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>
  1 sibling, 0 replies; 9+ messages in thread
From: Kim F. Storm @ 2006-05-16 14:57 UTC (permalink / raw)


Bastien <bastien@xxx.fr> writes:

> Tim X <timx@nospam.dev.null> writes:
>
>> 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))
>
> Works great, thanks!  And this is *really* more elegant.  I should
> think the defadvice-way more often.

I don't think it works for messages printed by the emacs core (C-level).

-- 
Kim F. Storm  http://www.cua.dk

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: `last-message' variable ?
       [not found]         ` <mailman.1900.1147791985.9609.help-gnu-emacs@gnu.org>
@ 2006-05-16 15:23           ` Bastien
  2006-05-16 15:51             ` Drew Adams
  0 siblings, 1 reply; 9+ messages in thread
From: Bastien @ 2006-05-16 15:23 UTC (permalink / raw)


no-spam@cua.dk (Kim F. Storm) writes:

>> Works great, thanks!  And this is *really* more elegant.  I should
>> think the defadvice-way more often.
>
> I don't think it works for messages printed by the emacs core
> (C-level).

That's why it would be nice to have such a functionnality implemented
at a low level: a ring for (nth) last messages and another one for
(nth) last warnings.

I don't have any idea whether it seems useful to other people.

BTW, i come to need this while using a function that converts the
current URL into a tiny URL.  See: 
<http://www.emacswiki.org/cgi-bin/wiki/tinyurl.el>

`get-metamark' displays a message in the minibuffer and it's more
handy to get this URL by evaluating `last-message'.

-- 
Bastien

^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: `last-message' variable ?
  2006-05-16 15:23           ` Bastien
@ 2006-05-16 15:51             ` Drew Adams
  0 siblings, 0 replies; 9+ messages in thread
From: Drew Adams @ 2006-05-16 15:51 UTC (permalink / raw)


    > I don't think it works for messages printed by the emacs core
    > (C-level).

    That's why it would be nice to have such a functionnality implemented
    at a low level: a ring for (nth) last messages and another one for
    (nth) last warnings.

    I don't have any idea whether it seems useful to other people.

Why not? Why not let the messages list be treated as a history (ring, if you
like), with access via completion and search-with-completion (a la
minibuffer histories)?

Of course, nothing prevents one from visiting buffer *Messages* and...

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: `last-message' variable ?
       [not found] <mailman.1905.1147794706.9609.help-gnu-emacs@gnu.org>
@ 2006-05-16 16:13 ` Bastien
  0 siblings, 0 replies; 9+ messages in thread
From: Bastien @ 2006-05-16 16:13 UTC (permalink / raw)


"Drew Adams" <drew.adams@oracle.com> writes:

> Why not? Why not let the messages list be treated as a history
> (ring, if you like), with access via completion and
> search-with-completion (a la minibuffer histories)?

Indeed.  That would be fairly neat!

-- 
Bastien

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2006-05-16 16:13 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

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).