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.
592 questions
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?
16
votes
2 answers

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

I searched accross all Emacs Lisp files in Emacs Git repo, and found (goto-char (point-min)) occurs 3621 times and (goto-char 1) occurs 31 times. Personally, I see lots of (point-min) but none 1, even in many cases, it's 100% sure that the region is…
xuchunyang
  • 14,527
  • 1
  • 19
  • 39
14
votes
3 answers

make `previous-buffer` and `next-buffer` to ignore some buffers

in Helm I ignore some buffers from showing when using C-x b, I'm looking for a way to make the commands previous-buffer and next-buffer behave the same ignoring some buffers.
shackra
  • 2,782
  • 19
  • 49
11
votes
1 answer

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

There are a number of Emacs buffers where their names have "earmuffs", i.e. they have names like *scratch* *R* *ESS* *helm-mode-circe* What is the significance of the earmuffs, and is there a reason for users creating buffers to use them?
Eric Brown
  • 3,222
  • 4
  • 17
  • 20
8
votes
1 answer

Clone a buffer to see the same contents in an other mode

Suppose I'm working on a file in org-mode or enriched-mode or html-mode ..., and I wanted to see the same contents in an other window with an other mode, say text-mode, how to do that? I tried to clone the buffer using C-x 4 c, but when I change the…
Bite Bytes
  • 291
  • 1
  • 8
7
votes
3 answers

How can I run a command on several buffers / files?

I'm working on some code that is spread across several files. I keep finding myself doing whitespace-cleanup and indent-region (on the whole file), and having to do it on each of the six files. Any way to say: 'do tidying up on all .c and .h files…
6
votes
1 answer

Function like save excursion for restoring buffers?

When I want to do something in another buffer and then restore the original, I currently do this: (let ((this-buffer (current-buffer))) (switch-to-buffer (other-buffer)) (insert "I was here!") (switch-to-buffer this-buffer)) Is there a less…
6
votes
5 answers

Create a buffer for a new file without naming the file

The typical workflow in other text editors is that you are presented with a blank window, to start typing into, and then when you exit the editor (or kill the buffer if applicable, close the window in some editors - in general any action that would…
Random832
  • 578
  • 3
  • 11
5
votes
1 answer

How to skip some buffers when use prev-buffer/next-buffer?

windows 10, emacs 26.1 Suppose I open 10 buffers. If I can use prev-buffer (C-x left) / next-buffer (C-x right) to go to prev/next buffers. It's very comfortable. But I need when I do this to skip some buffers. E.g. buffers whose names start with…
a_subscriber
  • 4,062
  • 1
  • 18
  • 56
5
votes
2 answers

Something like save-excursion that saves the complete buffer state?

[This question is related to, but not a duplicate of, the question copy contents of current buffer in a temp buffer and operate on that. Besides other incidental things (e.g., the question itself is different), none of the solutions offered both (1)…
Carl
  • 81
  • 5
5
votes
2 answers

Checking if there exists a buffer whose name starting with a particular string

According to the documentation the function get-buffer checks if there is a buffer with a specific name. More precisely (get-buffer name) Return the buffer named name (a string). If there is no live buffer named name, return nil. See the related…
Name
  • 7,849
  • 4
  • 41
  • 87
4
votes
1 answer

Disaable the prompts to save files

Every time, I save files, it prompts that save files ..? (y, n !) There are few cases that saving files are mistake operations. How could disable the confirmation prompts?
Wizard
  • 1,251
  • 6
  • 17
4
votes
1 answer

How to revert a buffer without changing active modes?

M-x revert-buffer resets the active minor modes to the defaults for the underlying file. How can I preserve the minor modes active while reverting the buffer? My attempt so far: (defun revert () (interactive) (let ((active-modes…
4
votes
1 answer

How to empty a buffer before it gets to0 large

I'm browsing with erc to some channels which are mainly used by bot request. Therefore the buffer size will scale up very fast. Since It's a read-only buffer I cannot empty it by hand. Is there a way to tell Emacs to empty a buffer if it reaches a…
xetra11
  • 167
  • 7
4
votes
1 answer

Create a "dismissable" buffer

I am writing a simple package for myself to try and learn some elisp - and to begin extending Emacs for my own personal workflow. This function processes the current buffer contents with a command line utility and pipes the output into a temporary…
sunwukung
  • 227
  • 3
  • 10
1
2 3 4 5