Questions tagged [buffers]

The text you are editing in Emacs resides in an object called a buffer. Each time you visit a file, a buffer is used to hold the file's text. Each time you invoke Dired, a buffer is used to hold the directory listing.

The text you are editing in Emacs resides in an object called a buffer. Each time you visit a file, a buffer is used to hold the file's text. Each time you invoke Dired, a buffer is used to hold the directory listing. If you send a message with C-xm, a buffer is used to hold the text of the message. When you ask for a command's documentation, that appears in a buffer named *Help*.


Each buffer has a unique name, which can be of any length. When a buffer is displayed in a window, its name is shown in the mode line (see Mode Line). The distinction between upper and lower case matters in buffer names. Most buffers are made by visiting files, and their names are derived from the files' names; however, you can also create an empty buffer with any name you want. A newly started Emacs has several buffers, including one named *scratch*, which can be used for evaluating Lisp expressions and is not associated with any file (see Lisp Interaction).

At any time, one and only one buffer is selected; we call it the current buffer. We sometimes say that a command operates on “the buffer”; this really means that it operates on the current buffer. When there is only one Emacs window, the buffer displayed in that window is current. When there are multiple windows, the buffer displayed in the selected window is current. See Windows.

Aside from its textual contents, each buffer records several pieces of information, such as what file it is visiting (if any), whether it is modified, and what major mode and minor modes are in effect (see Modes). These are stored in buffer-local variables—variables that can have a different value in each buffer. See Locals.

A buffer's size cannot be larger than some maximum, which is defined by the largest buffer position representable by Emacs integers. This is because Emacs tracks buffer positions using that data type. For typical 64-bit machines, this maximum buffer size is 2^61 - 2 bytes, or about 2 EiB. For typical 32-bit machines, the maximum is usually 2^29 - 2 bytes, or about 512 MiB. Buffer sizes are also limited by the amount of memory in the system.

  • Select Buffer: Creating a new buffer or reselecting an old one.
  • List Buffers: Getting a list of buffers that exist.
  • Misc Buffer: Renaming; changing read-only status; copying text.
  • Kill Buffer: Killing buffers you no longer need.
  • Several Buffers: How to go through the list of all buffers and operate variously on several of them.
  • Indirect Buffers: An indirect buffer shares the text of another buffer.
  • Buffer Convenience: Convenience and customization features for buffer handling.
572 questions
88
votes
25 answers

How do I switch buffers quickly?

In vanilla Emacs, I have to do C-x b and then manually type out the buffer name to switch. If I forget the name of the buffer, I have to hit TAB to list possible completions. Is there anything I can do to make this process faster?
nixeagle
  • 2,407
  • 3
  • 17
  • 14
58
votes
1 answer

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

Sometimes it happens: emacs prompts you about recovering unsaved changes to a file, but you cannot remember if you want those changes or not. Starting at the recover-this-file buffer, is there a way to view a diff or otherwise directly see the…
Sparx
  • 1,111
  • 9
  • 20
55
votes
9 answers

How do I find text across many open buffers?

Lets say I have 10 buffers open, and I want to find all occurrences of blah in all 10 buffers. How would I do this?
nixeagle
  • 2,407
  • 3
  • 17
  • 14
44
votes
5 answers

Re-open *scratch* buffer

If I accidentally closed the scratch buffer in Emacs, how do I create a new scratch buffer?
programking
  • 7,064
  • 9
  • 41
  • 62
44
votes
2 answers

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

When posing questions on this site, people sometimes talk about "windows" when they mean "frames," and "buffers" or "files" when they mean "windows." So: Q: What is the difference between a buffer, a file, a window, and a frame? (I'm posing this…
Dan
  • 32,584
  • 6
  • 98
  • 168
38
votes
6 answers

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

Sometimes I accidentally kill a buffer and want to reopen it, just like C-S-t to undo closed tab in Firefox, but there is no built-in command in Emacs, the defun undo-kill-buffer in http://www.emacswiki.org/RecentFiles : (defun undo-kill-buffer…
CodyChan
  • 2,599
  • 1
  • 19
  • 33
35
votes
2 answers

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

Given a modified buffer, how can I diff it with the file backing it on disk to see what I've changed?
nosefrog
  • 795
  • 6
  • 9
29
votes
4 answers

How to auto-save buffers when Emacs loses focus?

I recently had a Sublime Text user try out Emacs for a while, and he was interested in getting the same auto-save behavior in Emacs. Basically, he wanted all buffers to be saved whenever the frame lost focus (really saved, not just backed-up). This…
b4hand
  • 1,995
  • 1
  • 19
  • 31
26
votes
8 answers

Close all dired buffers

Sometimes my buffer list has 10+ dired windows, and I end up using buffer-menu to manually mark and kill all of them. Is there a faster way to close all open dired windows?
nispio
  • 8,175
  • 2
  • 35
  • 73
26
votes
3 answers

How do I clear a buffer completely with elisp?

If I want to delete everything in a buffer with elisp, how do I do that?
22
votes
1 answer

Get content of a buffer

So buffer-string gets the content of the current buffer. But it doesn't allow specifying other buffers. How can I get around that? Do I need something like save-window-excursion to make it work?
Maciej Goszczycki
  • 1,777
  • 13
  • 18
21
votes
3 answers

Set column widths in `ibuffer`

Is there a way to customize the widths of the columns in ibuffer? Specifically, I want to widen the Name column to be able to read more of the buffer names before they get truncated. I have tried Buffer-menu-name-width, but it seems that the…
nispio
  • 8,175
  • 2
  • 35
  • 73
19
votes
1 answer

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

I'm writing an extension that talks to an outside process, so it is a given to lower the amount of 'hey whats up' requests when my buffer isn't focused. So, what is the best way to recognize: When my buffer is visible and focused When my buffer is…
Łukasz Gruner
  • 1,008
  • 8
  • 16
19
votes
5 answers

Kill process buffer without confirmation?

I have C-x C-k bound to kill-this-buffer. But when I enter into a buffer which is running a process like Python or MySQL, if I do C-x C-k it asks Buffer "*Python*" has a running process; kill it (y or n)? How can I kill process buffers without…
Chillar Anand
  • 4,042
  • 1
  • 23
  • 52
19
votes
3 answers

Why use indirect buffers?

What are the benefits of using indirect buffers? Under what circumstances are they useful?
SabreWolfy
  • 1,378
  • 1
  • 13
  • 26
1
2 3
38 39