[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to automatically write *Messages" buffer to a file?
From: |
Joe Corneli |
Subject: |
Re: How to automatically write *Messages" buffer to a file? |
Date: |
Wed, 24 Nov 2004 13:01:05 -0600 |
> From: Pascal Bourguignon <spam@mouse-potato.com>
> Date: 24 Nov 2004 15:06:38 +0100
>
> Brad Collins <brad@chenla.org> writes:
>
> > Is there is a simple way of getting Emacs to automatically append
> > messages in the message buffer to a file so messages work as a log file?
> >
> > I've been looking around and it seems this should be dead easy but I
> > can't figure it out?
>
> The best I can figure is that the simple way to do it would be to
> modify the C source of emacs. message is a buit-in function.
How about an after-change function that'd do this only for the
*Messages* buffer?
If you want a faithful account of what is actually in the *Messages*
buffer, that would definitely be better than defadvising `message' --
because a significant amount of stuff that is written to the
*Messages* buffer is not put there by `message'.
> I know of no way from emacs lisp to append a line to a file.
??? What's wrong with append-to-file?
Something fairly minor... namely that it adds text to the *Messages*
buffer (not through the `message' mechanism), so one has to delicately
advise it to shut up (for use in this application).
Here is a little code that *does not work as desired* but I think it
is pretty close. I'd be happy if someone could point out the bug(s).
(defvar messaging-on t
"Control whether or not messages will be printed.
By default, they are.")
(defadvice write-region (around no-wrote-file activate)
"Turn off the printout associated with writing files.
This is necessary to add as a supplement to `nomessage' because
the \"Wrote file\" or \"Added to file\" message is not printed
through the `message' mechanism. The observed effect of this
piece of advice is that neither `save-buffer' nor `write-file'
will print anything out when they run."
(if messaging-on
ad-do-it
(set-buffer-modified-p nil)
(ad-set-arg 4 t)
(ad-set-arg 6 nil)
ad-do-it))
(defun turn-on-logging-advice ()
(ad-enable-advice 'write-region 'around 'no-wrote-file)
(ad-activate 'write-region))
(defun turn-off-logging-advice ()
(ad-disable-advice 'write-region 'around 'no-wrote-file)
(ad-activate 'write-region))
(turn-off-logging-advice)
;;
(defun setup-logging ()
(interactive)
(message "begin logging")
(set-buffer "*Messages*")
(make-variable-buffer-local 'after-change-functions)
;; be less destructive if you care
(setq after-change-functions
'(log-message))
(turn-on-logging-advice))
(defun stop-logging ()
(interactive)
(message "stop logging")
;; see prev comment
(setq after-change-functions nil)
(turn-off-logging-advice))
(defun log-message (beg end range)
(let ((messaging-on nil))
(append-to-file beg end "~/LOG")))
(defun test-message ()
(interactive)
(message "hi"))
- How to automatically write *Messages" buffer to a file?, Brad Collins, 2004/11/23
- Re: How to automatically write *Messages" buffer to a file?, Pascal Bourguignon, 2004/11/24
- Re: How to automatically write *Messages" buffer to a file?, Eli Zaretskii, 2004/11/24
- Re: How to automatically write *Messages" buffer to a file?,
Joe Corneli <=
- Message not available
- Re: How to automatically write *Messages" buffer to a file?, Stefan Monnier, 2004/11/24
- Re: How to automatically write *Messages" buffer to a file?, Joe Corneli, 2004/11/24
- Message not available
- Re: How to automatically write *Messages" buffer to a file?, Stefan Monnier, 2004/11/24
- Re: How to automatically write *Messages" buffer to a file?, Joe Corneli, 2004/11/24
- RE: How to automatically write *Messages" buffer to a file?, Drew Adams, 2004/11/24
- Re: How to automatically write *Messages" buffer to a file?, Joe Corneli, 2004/11/25
- Message not available
- Re: How to automatically write *Messages" buffer to a file?, Stefan Monnier, 2004/11/25
- Message not available
- Re: How to automatically write *Messages" buffer to a file?, Thien-Thi Nguyen, 2004/11/24
- Re: How to automatically write *Messages" buffer to a file?, Joe Corneli, 2004/11/25