Hot answers tagged

53

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 differences between the modified buffer and the saved file. The key I've bound for this actually runs a custom function, in order to produce a unified diff, and ...


52

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 you prefer the items being displayed vertically: (setq ido-separator "\n") Courtesy of ergoemacs Let me also suggest this post talking about switch to ...


48

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 RET) but doing it again takes you to the 3rd most recently visited buffer. If you're popping back and forth between 3 or 4 buffers a lot then I find it a lot ...


40

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.


37

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 it's tedious. multi-occur-in-matching-buffers lets you enter a regexp to match file names (it only searches in buffers that are visiting files); enter . as the ...


36

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 making themselves understood to each other, since they're using the terms in different ways. In brief: "Frames" are to Emacs what "windows" are to everything ...


33

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


32

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.


31

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 save-buffer-now activate) (when (and buffer-file-name (buffer-modified-p)) (save-buffer))) (defadvice other-window (before other-window-now activate) (when (...


29

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 ways the author has never envisioned" - so one should always be prepared for the unusual use of one's code. Code readability is King When you write (goto-char 1),...


28

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) View the differences between BUFFER and its associated file. This requires the external program diff to be in your exec-path. You may also be ...


26

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; play with the optional 2nd argument to tell it how to behave in cases where you have multiple frames). With these two ingredients, you should be able to ...


26

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 kill a buffer that's not visiting a file, it's gone for good.) The latter function pops that file off of the list and visits it: (defvar killed-file-list nil "...


25

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 something in another buffer, and save-current-buffer for more complex cases where you need to navigate between several buffers. (defun buffer-string* (buffer) (...


25

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 effect (see `narrow-to-region') is removed, so the buffer is truly empty after this. How to find such a function? M-x apropos buffer erase


19

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) "Disable `MODE-FN' in ALL buffers." (interactive "a") (dolist (buffer (buffer-list)) (with-current-buffer buffer (funcall mode-fn -1)))) To use (for ...


19

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 terms of size: ELISP> (byte-compile '(lambda () (goto-char (point-min)))) #[nil "eb\207" [] 1] ELISP> (byte-compile '(lambda () (goto-char 1))) #[nil "\...


18

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 binding, you can toggle "dedicatedness" of any window by pressing C-c t: (defun toggle-window-dedicated () "Control whether or not Emacs is allowed to display ...


18

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. Solution We need to tell emacs to always open buffers ending with COMMIT_EDITMSG in a window but not in the same (*magit ..*) window. Add the following snippet to ...


18

Just select the entire buffer (C-x h) and use write-region.


17

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 tinker with it. If you prefer the elisp approach, you can adapt the default settings to your taste, with the numbers after the name component of the list ...


17

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 and other buffer properties. If you don't use indirect buffer but create another window of the same buffer, then everything is shared and you cannot perform ...


17

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-this-buffer uses kill-buffer internally, which references the variable kill-buffer-query-functions.


16

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-buffer (window-buffer (next-window))) (this-win-edges (window-edges (selected-window))) (next-win-edges (window-edges (next-window))) ...


16

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 can be used instead of `revert-buffer'. If there is nothing to revert then this command fails.


14

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, you'll want to change the sizes (14 and 10) to values of your liking. If you want to customize a specific face and don't know the name of it, try doing M-x ...


13

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 things this includes: emacs-lisp evaluation buffers buffers for interaction with sub-processes network-related buffers (IRC, messages, ...) buffers that ...


13

Running the command ibuffer-auto-mode in an Ibuffer buffer makes it refresh the display after each interactive command. There doesn't appear to be a direct way of activating it automatically. You can put this in your init file: (add-hook 'ibuffer-mode-hook (lambda () (ibuffer-auto-mode 1)))


12

This can be done with helm via the command helm-multi-occur. You can install helm from melpa and then call the command as follows: M-x helm-multi-occur RET M-a RET This will open helm-multi-occur and then select all buffers. Instead of using M-a to mark all buffers, you can optionally select the buffers of interest one at a time. Navigate up and down the ...


12

In addition to what others have mentioned - here are two other resources for this. M-x multi-isearch-buffers or M-x multi-isearch-buffers-regexp (vanilla Emacs) - Incremental search across multiple buffers. If you use Icicles then you can use icicle-search (or icicle-occur, or any number of other icicle-search specializations) to search across multiple ...


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