|
From: lawrence m. <we...@gm...> - 2004-01-14 17:44:57
|
All over erc, I see stuff like:
(let ((ob (current-buffer))
(buffer (process-buffer buffer)))
(when buffer
(set-buffer buffer)
(do-stuff-in buffer)
...
(set-buffer ob)))
This has a few problems. It seems rather low level, it would be
nicer to have some kind of macrology to wrap the whole thing up.
It's not very safe, in the case of an error, we might well be
left in BUFFER, rather than back in OB.
What do people think of installing something like this:
(defmacro with-existing-buffer (buffer &rest body)
"Execute the forms BODY in BUFFER if it exists.
See also `with-current-buffer'."
(let ((tmp (make-symbol "TMP-BUF")))
`(let ((,tmp ,buffer))
(when (and ,tmp
(bufferp ,tmp))
(with-current-buffer ,tmp
,@body)))))
--
lawrence mitchell <we...@gm...>
|