Hot answers tagged

60 votes

How do I switch buffers quickly?

I've recently started using C-x <left> and C-x <right>. Those are both standard Emacs bindings—nothing to configure. Left takes you back to the previous buffer (initially the same as C-x b ...
user avatar
56 votes
Accepted

How to view diff when emacs suggests to recover this file?

After running recover-this-file and accepting the autosave version, you'll have a modified buffer containing the autosave contents. At this point you can use M-x diff-buffer-with-file RET to see the ...
user avatar
  • 43.1k
55 votes

How do I switch buffers quickly?

There is ido mode that should help. EDIT: put this in your init file, to activate ido mode by default: (ido-mode 1) Now, C-x b will show you a list of candidates. Put this in your init file, if ...
user avatar
  • 5,981
48 votes
Accepted

What's the difference between a buffer, a file, a window, and a frame?

Emacs predates contemporary window-based operating systems, so its terminology also predates the current terms. Unfortunately, it means that new users and experienced users sometimes have trouble ...
user avatar
  • 31k
44 votes

How do I switch buffers quickly?

You could use Helm. In my setup, I have switched C-x b for M-l. This allied with helm-buffers-list, makes the process pretty fast, at least for me.
user avatar
43 votes
Accepted

Re-open *scratch* buffer

Just re-create the buffer by switching to it: C-x b *scratch* RET. Since Emacs 21.2, if you create a buffer called *scratch*, it's automatically put in Lisp Interaction mode.
user avatar
43 votes

How do I find text across many open buffers?

Sticking to built-in Emacs commands, you can use multi-occur or multi-occur-in-matching-buffers (M-x multi-occur- TAB RET). multi-occur gives you fine control by prompting for each buffer to use, but ...
user avatar
37 votes
Accepted

Close all dired buffers

You could do the following: M-x ibuffer * / to mark buffers in dired mode. D to delete them.
user avatar
34 votes
Accepted

How can I see the changes made to a modified buffer since the last save?

You want the command M-x diff-buffer-with-file. See the manual: diff-buffer-with-file is an interactive autoloaded compiled Lisp function in `diff.el'. (diff-buffer-with-file &optional BUFFER) ...
user avatar
  • 9,993
32 votes
Accepted

How to auto-save buffers when Emacs loses focus?

Unfortunately, this exact behavior isn't possible in Emacs <= 24.3, but you can save on window/buffer change using defadvice (as detailed on bbatsov's blog): (defadvice switch-to-buffer (before ...
user avatar
  • 4,950
30 votes
Accepted

Get content of a buffer

A lot of things in Emacs operate on the current buffer. You need to change the current buffer and restore it when you're done. Use with-current-buffer for simple cases where you just need to do ...
user avatar
29 votes
Accepted

How do I clear a buffer completely with elisp?

Have you tried erase-buffer? erase-buffer is an interactive built-in function in `C source code'. (erase-buffer) Delete the entire contents of the current buffer. Any narrowing restriction in ...
user avatar
  • 69.2k
28 votes
Accepted

How to reopen just killed buffer, like C-S-t in Firefox Browser?

Here's another, simple alternative that doesn't require recentf. Hooking the first function into kill-buffer-hook will push the filename associated with the buffer onto a list. (Note that, if you ...
user avatar
  • 31k
28 votes
Accepted

Why is (point-min) much more popular than 1?

How do you know that the buffer is not narrowed? Unless you have widened it right before you called the function, you cannot be sure. Moreover, "great software" is often defined as "being used in ...
user avatar
  • 5,427
26 votes
Accepted

How to know my buffer's visible/focused status?

window-buffer returns the buffer currently displayed by a given window. get-buffer-window, on the contrary, returns a window currently displaying the given buffer (or nil if there is no such window; ...
user avatar
21 votes
Accepted

How can I prevent a command from using specific windows?

I second @Nsukami's suggestion to use dedicated windows. Since it is a function, not a command, using set-window-dedicated-p directly can be cumbersome. With the following command and associated key ...
user avatar
  • 14.2k
20 votes
Accepted

Disable minor mode in all open buffers

This does require a custom elisp function unless the minor mode has a (global-*-mode) function attached to it. Luckily, it is a pretty simple function: (defun global-disable-mode (mode-fn) "...
user avatar
20 votes
Accepted

How to save a copy of a buffer to a file?

Just select the entire buffer (C-x h) and use write-region.
user avatar
  • 867
19 votes
Accepted

Set column widths in `ibuffer`

As @Sigma's answer mentions, you need to customize ibuffer-formats. The docstring gives a lot of details about how to modify it by hand, and also notes that you can use the customize machinery to ...
user avatar
  • 31k
19 votes
Accepted

How do I force a specific buffer to open in a new window?

It is possible to configure how a buffer opens (in the same frame/window or a different frame/window) using display-buffer-alist. Refer to the references below to learn more about this variable. ...
user avatar
  • 24.2k
19 votes
Accepted

Why use indirect buffers?

To see and edit multiple locations of the same buffer. So, you don't have to scroll a long buffer but simply switch window to visible region. Each cloned buffer also has different mark ring, narrowing ...
user avatar
  • 6,652
18 votes

How can I set different font sizes for buffers and for the mode-line?

Try replacing the code for setting the font size with this: (set-face-attribute 'default nil :font "DejaVu Sans Mono-14") (set-face-attribute 'mode-line nil :font "DejaVu Sans Mono-10") Of course, ...
user avatar
  • 14.2k
18 votes

How can I see the changes made to a modified buffer since the last save?

Command ediff-current-file: ediff-current-file is an interactive autoloaded Lisp function in `ediff.el'. (ediff-current-file) Start ediff between current buffer and its file on disk. This command ...
user avatar
  • 69.2k
18 votes

Why is (point-min) much more popular than 1?

To complement sds's answer (with which I fully agree), despite appearances, (point-min) can be more efficient than 1. In terms of execution speed, my tests don't see any measurable difference, but in ...
user avatar
  • 25.2k
17 votes
Accepted

Switch window split orientation, fastest way

Here's a defun that would do what you are looking for: (defun toggle-window-split () (interactive) (if (= (count-windows) 2) (let* ((this-win-buffer (window-buffer)) (next-win-...
user avatar
  • 1,344
17 votes
Accepted

Kill process buffer without confirmation?

Remove the corresponding function from the relevant variable : (setq kill-buffer-query-functions (delq 'process-kill-buffer-query-function kill-buffer-query-functions)) How did I find this ? kill-...
user avatar
  • 3,331
15 votes
Accepted

How to modify-face for a specific buffer?

As noted by @phils in the comment below, the Emacs manual suggests not modifying the face-remapping-alist directly due to possible unintended side effects: . . .to avoid trampling on remappings ...
user avatar
  • 17.6k
14 votes
Accepted

What is the significance of Emacs buffers having names with *earmuffs*?

By convention, those special names are used for buffers that are not associated directly to a file, but are used to provide the user with a view of some activity that happens in Emacs. Amongst other ...
user avatar
  • 4,440
14 votes

How do I find text across many open buffers?

swiper-all from the swiper package provides a tool for doing this. It's even incremental, so it updates as you type.
user avatar
14 votes
Accepted

How to check whether a buffer is visiting a file?

I'd argue that your usage is idiomatic elisp, since the buffer's name is a perfectly appropriate boolean value in its own right. Quoting from the manual: There is an important aspect to the truth ...
user avatar

Only top scored, non community-wiki answers of a minimum length are eligible