First, I'm not much used to XEmacs, but rather to Emacs... There might be differences. But I can reproduce your problem with Emacs, so I hope the Emacs solution will also work for XEmacs.
Emacs doesn't redisplay the UI during command execution, which means hitting F5 runs command myClear
, then redraws the display while waiting for another input, then myMake
is executed when you hit F6.
On the other hand, when you hit F7, the entire cycle myClear
-myMake
is executed, without any redisplay, making erase-buffer
effects invisible. You eed to force a redisplay
after erase-buffer
to see its effects.
Below is a working example based on the code which you provided.
(defun myClear ()
"Clears console output buffer (F5)"
(interactive)
(with-current-buffer "*Shell Command Output*"
(erase-buffer)))
(defun myMake ()
"Executes make (F6)"
(interactive)
(shell-command "sleep 2; echo Hello World"))
(defun myClearMake ()
"Clears console output buffer before executing make (F7)"
(interactive)
(myClear)
(redisplay)
(myMake))
(global-set-key (kbd "<f5>") 'myClear)
(global-set-key (kbd "<f6>") 'myMake)
(global-set-key (kbd "<f7>") 'myClearMake)
Note that I had to do minor adjustments (maybe due to Emacs/XEmacs differences?)
Also note that a better way to do things like running make consists in using M-xcompile
RET. In particular, this will take care of erasing the buffer for you, run processes in the background (without hanging Emacs like your example does), and process the output to detect error/warning messages.