Emacs disable *Messages* buffer - emacs

Is there a way to disable the Messages buffer? I know I can kill it, but it reappears. I know I can scroll through buffers without passing by Messages, but is there a way I can just disable the creation of it?
Thank you.

Based on the answer above, place this in your .emacs to completely disable the messages
;; Forces the messages to 0, and kills the *Messages* buffer - thus disabling it on startup.
(setq-default message-log-max nil)
(kill-buffer "*Messages*")
Also, if you're like me, this is how you remove the Completions buffer that appears when opening a new file from the buffer.
;; Disabled *Completions*
(add-hook 'minibuffer-exit-hook
'(lambda ()
(let ((buffer "*Completions*"))
(and (get-buffer buffer)
(kill-buffer buffer)))))

You can customize the variable message-log-max and give a value of nil to disable logging:
Maximum number of lines to keep in the message log buffer.
If nil, disable message logging. If t, log messages but don't truncate
the buffer when it becomes large.
I tried killing the *Messages* buffer, producing messages (that show on the minibuffer), and no new messages buffer appears.

Related

Want to view EMACS Messages buffer while EMACS loads

I use
(message "..some text...")
in my init file to send messages to the Message buffer while EMACS loads. This is a quick way for me to see where a change I have just made crashes the startup.
However, I have not been able to find a way view that buffer during the load and watch the messages scroll. I always have to switch to it after a loading failure to see where it occcured.
Is there anyway to view the messages being sent to the Messages buffer (not the echo line) while Emacs is processing the init file?
How about putting
(view-echo-area-messages)
at the beginning of your init.el?
Or if you instead want the messages buffer to take up the whole screen,
(with-current-buffer (messages-buffer)
(goto-char (point-max))
(switch-to-buffer (current-buffer)))
However, putting messages in your init-file is a crude workaround. You probably actually want to launch Emacs with the --debug-init option:
$ emacs --debug-init
This will halt on the error and present you with a backtrace.
Or alternatively, you could just M-x toggle-debug-on-error and reload your init-file (M-x load-file RET ~/.emacs.d/init.el RET).

How do I configure Emacs to dedicate the Calculator window?

I'm using emacs 24.3 from emacsformacosx.com on OS X 10.9 (Mavericks). The behavior is the same on emacs 23.4.1 on Debian Wheezy.
I want to automate applying set-window-dedicated-p so switching/opening a buffer won't use certain windows. For example, if I'm in the Calculator and manually use Meta-: and enter (set-window-dedicated-p (get-buffer-window) t) then it works great - my Calculator window doesn't get hijacked by other buffers. I want it to work like that automatically.
I put this in my .emacs file:
(add-hook 'calc-mode-hook
(lambda ()
(message "Dedicating %s" (buffer-name))
(set-window-dedicated-p (get-buffer-window) t)
(message "Dedication %s" (window-dedicated-p (get-buffer-window "*Calculator*")))))
Then I start up emacs, switch to the *Messages* window, and Meta-x calc. The *Messages* buffer shows
Dedicating *Calculator*
Dedication t
so I know my hook was called and what buffer it operated on. But the *Calculator* buffer is not dedicated - it doesn't behave properly and Meta-: (window-dedicated-p) returns nil. The *Messages* buffer is dedicated instead.
Why is the *Calculator* window shown as dedicated in the hook but not afterwards? What am I doing wrong here?
Unfortunately the *Calculator* buffer is not displayed in any window at the point your code runs.
Your 'validation' messages were misleading you. (buffer-name) is certainly the buffer you want, but it's not in any window, and so you're actually passing a nil argument for the window in all situations. i.e. You're setting the current window dedicated, and then confirming that it's dedicated (which it should indeed be).
I think after advice to calc is what you need here. e.g.:
(defadvice calc (after my-dedicated-calc-window)
"Make the *Calculator* window dedicated."
(let ((win (get-buffer-window "*Calculator*")))
(when win
(set-window-dedicated-p win t))))
(ad-activate 'calc)
n.b. I'm not sure exactly how the arguments to calc affect the window display, but I think with the test for the window wrapping the call to set-window-dedicated-p this code is probably fine in all cases.

How to follow the end of *Messages* buffer in Emacs? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
In emacs, can I set up the *Messages* buffer so that it tails?
I am playing with Elisp, and I find convenient to have the *Messages* buffer always open in a window in my frame.
I discovered recently that sometimes the buffer stops following the last line in the file. If I want to see the last appended lines in this buffer, I need to go in the buffer and jump to the end manually, with M->. Which quite annoying and disruptive.
I am trying to reproduce the "tail -f" command line, in a buffer. Of course 'auto-revert-tail-mode complains that the *Messages* is not a visited file... As a consequence, this mode does not want to work. But it gave me the idea to add a function hook when the buffer is modified. That function would jump to (point-max) each time that buffer is modified.
Here is my own attempt, invoked from *Messages* buffer, with M-::
(add-hook 'after-change-functions (lambda (s e l) (goto-char (point-max)) nil) nil t)
But it does not work. The (point) remains in the same place while I see the buffer is growing... The lambda function does not produce any error, otherwise it would have been removed from the 'after-change-functions hook and C-h k 'after-change-functions shows it is present.
Any better suggestions?
Modifying the point position from after-change-functions is very dangerous anyway because it can break some types of edit to the buffer (for example, Emacs compresses multiple consecutive messages with the same content). However, for your purposes the post-command-hook is more than sufficient and much safer, so you can just use this:
(add-hook 'post-command-hook
(lambda ()
(let ((messages (get-buffer "*Messages*")))
(unless (eq (current-buffer) messages)
(with-current-buffer messages
(goto-char (point-max)))))))
The hook will make sure the point in *Messages* is at the end of buffer after every command, unless you're currently editing the *Messages buffer itself.
Well I've made my own one with set-window-point.
(defun tail-f-msgs ()
"Go to the end of Messages buffer."
(let ((msg-window (get-buffer-window "*Messages*")))
(if msg-window
(with-current-buffer (window-buffer msg-window)
(set-window-point msg-window (point-max))))))
;; Make the Messages buffer stick to the end.
(add-hook 'post-command-hook 'tail-f-msgs)

Close all temporary buffers automatically in emacs

How can we close temporary buffers which are enclosed with * automatically. For e.g. messages, completions buffer needs to be closed. Killing all these buffers manually after use is painful.
Is there a way to close temporary buffers created by emacs (not by us)?
Do you really need to close those buffers? If you use a proper buffer switching method like iswitchb then you don't have to care about temporary or other buffers, because you can go directly to any buffer you want.
I'd second the suggestion you use ido or iswitchb to avoid being bothered by temporary buffers. The presence of those buffers is a natural consequence of using emacs, so don't try to swim upstream!
On the other hand, if you're irritated by the growing list of open buffers, you can use midnight.el to automatically close inactive buffers after a period of time, or you can use ibuffer to easily select and close unwanted buffers en masse.
Personally, I leave buffers open for a long time, I tidy them up occasionally using ibuffer, and I rely on ido to switch buffers quickly. In Emacs 24, you can set ido-use-virtual-buffers to t, and then ido will let you switch to closed files, reopening them as necessary.
To avoid having those buffers in your way, you could define key-bindings to cycle through «user buffers» and «useless buffers» :
http://ergoemacs.org/emacs/effective_emacs.html , section «Switching Next/Previous User Buffers»
but some useful buffers start with a *, like shells, compilation buffer, ielm, etc.
As user said, it would be better to use a smart buffer-switching package such as iswitchb and ido. iswitchb's iswitchb-buffer-ignore and ido's ido-ignore-buffers variables allow us to specify what buffers to ignore using regular expressions.
However, if you really want to kill those buffers, a program like this will be helpful to you:
(require 'cl)
(defvar kill-star-buffers-except
'("\\`\\*scratch\\*\\'"
"\\`\\*Messages\\*\\'"
"\\` \\*Minibuf-[[:digit:]]+\\*\\'"
"\\` \\*Echo Area [[:digit:]]+\\*\\'")
"Exception list for `kill-star-buffers'")
(defun kill-star-buffers ()
"Kill all star buffers except those in `kill-star-buffers-except'"
(interactive)
(mapc (lambda (buf)
(let ((buf-name (buffer-name buf)))
(when (and
;; if a buffer's name is enclosed by * with optional leading
;; space characters
(string-match-p "\\` *\\*.*\\*\\'" buf-name)
;; and the buffer is not associated with a process
;; (suggested by "sanityinc")
(null (get-buffer-process buf))
;; and the buffer's name is not in `kill-star-buffers-except'
(notany (lambda (except) (string-match-p except buf-name))
kill-star-buffers-except))
(kill-buffer buf))))
(buffer-list)))

kill the associated buffer when close the emacs-client frame by pressing Alt+F4

I get used to emacsclient for the speedy response like vim, by putting emacs into sever mode with command "emacs --daemon". But I found it quite annoying that lots of buffers kept alive when I viewed some files and then closed them by pressing Alt+F4. I have to kill the buffer explicitly before closing the frame.
I want to know, if there is a way to make emacsclient behave more like a lightweight GUI editor(e.g. vim) in this point?
I think you're asking for trouble, but you you could try this:
(add-hook 'delete-frame-functions
(lambda (frame)
(let* ((window (frame-selected-window frame))
(buffer (and window (window-buffer window))))
(when (and buffer (buffer-file-name buffer))
(kill-buffer buffer)))))
I suggest that you use the command quit-window which does precisely what you want (with the prefix argument); it is already the binding for q in special-mode (i.e., not self-insert) buffers. You can bind it to, say, C-f4, and it will kill the buffer and the frame when you type C-u C-f4.
Do something like the following:
(defun my-kill-buffer-and-frame ()
"kill the current buffer and the current frame"
(interactive)
(when (y-or-n-p "Are you sure you wish to delete the current frame?")
(kill-buffer)
(delete-frame)))
If you're sure you always wnt to do it, you can get rid of the prompt:
(defun my-kill-buffer-and-frame ()
"kill the current buffer and the current frame"
(interactive)
(kill-buffer)
(delete-frame))
Then bind it to a key of your choice, like so:
(global-set-key [(f5)] 'my-kill-buffer-and-frame)
Enjoy!