How can I get information about what mode a certain buffer is in in emacs. For example when I'm in buffer x how can i find ut if it is actually view-mode or whatever else it might be. The reason I want this is so that I can customize evil mode to only the buffers where I want it using:
(add-to-list 'evil-insert-state-modes 'view-mode)
The problem is that I don't know what the names are of the actual different modes I want to add to this list.
Hit M-: and type major-mode. You'll see the name of the major mode of the current buffer in the echo area.
Related
With C-x C-b the buffer list is displayed. First in it's natural order with most recently used buffers on top, and buried buffers at the bottom.
There, I can now sort the Buffer by name, size, mode and file. But once I click on such an option I cannot go back to the original ordering.
Also killing the buffer and recreating it does not change that order. (Using 25.2)
So how can I get that ordering back without restarting emacs?
There is another mode that's nowadays built-in to Emacs that can be used to display the buffer list: ibuffer-mode.
If you are not using it already, you can experiment with M-x ibuffer and find out its capabilities with C-h m. Note that in particular, it can sort the buffer list in various ways, one of which is by recency with s v, which is what the OP asked for; but note also that it has many other ways to sort that make it very flexible.
Once you are convinced that that's the way to go, you can redefine the C-x C-b keybinding in your init file with:
(global-set-key (kbd "C-x C-b") 'ibuffer)
I did that a long time ago and have never looked back. IMO, it should be the default: that may come to pass, but AFAIK that is still not the case.
Sorting order goes away as expected when I kill buffer named *Buffer List* and reopen using C-x C-b (Using emacs 27.1 & 28.1). From the EmacsWiki
Once sorted, there is no nice way to restore the default MRU sort. You
have to ‘kill-buffer’ the buffer menu buffer, and then re-open it.
(Sorting sets the variable ‘tabulated-list-sort-key’ in
tabulated-list.el. Its default is ‘nil’. No way to restore the nil
value is provided.)
May be worth adding a custom function which can disable the sort without closing the buffer.
(defun disable-buffer-sort()
(interactive)
(save-excursion
(set-buffer (get-buffer "*Buffer List*"))
(setq tabulated-list-sort-key 'nil)
(revert-buffer)
))
(disable-buffer-sort)
As #NickD mentioned in other answer ibuffer-mode is also a good alternative with more features.
evil-mode has evil-emacs-state-modes var, which defines modes to open in emacs mode.
I have magit-diff-mode listed in that var (in fact, it is a default).
Running magit-diff opens correctly in emacs mode.
However, if I a run magit-status (opens in emacs mode), place the point on Head (first line in the buffer) and hit Ret, magit-visit-thing is called and and the commit info is shown in a new buffer. This buffer is in magit-diff-mode, however, evil-mode is active for this buffer.
How do I prevent this behaviour?
As we figured out in the comments - the buffer opens in magit-revision-mode, not in magit-diff-mode.
To find out the major mode of the buffer, describe variable major-mode - C-h v major-mode <RET>.
For you information, when you do describe-mode instead (C-h m) what you see as mode name is the string that appears in the status line. It may be difficult to guess from it what the actual mode name is - like Magit Rev is actually a string for magit-revision-mode - no way of knowing unless you look in magit-diff.el:
define-derived-mode magit-revision-mode magit-diff-mode "Magit Rev"
I have a window whose mode line at the bottom says "(Text Spc Fill)", probably as a default for *.txt filenames. "Spc" seems to be a minor mode which attempts to preserve English text by, for example, collapsing two spaces to one after a word is removed. However, I don't want that in this buffer.
So, how can I turn off this minor mode?
I don't know the actual name of the mode. I tried M-x spc-mode and M-x space-mode, and I looked through a few help pages.
More generally, is there an easy way to get the list of modes which are active in the current buffer? Or to find out about a mode given its mode-line abbreviation? (These can be unpredictable; for example, M-x visual-line-mode corresponds to (WordWrap).)
This is Aquamacs, Emacs version 23.3.50.1.
To answer your second question, the command describe-mode (C-hm) will list
your major mode, along with
some documentation (usually including keybindings), and
all of the minor modes that are active
You might be surprised how many minor modes are active in a typical setup. Not all active modes have an "indicator."
in your .emacs file add the line
(remove-hook 'text-mode-hook 'turn-on-auto-fill)
Source
I've recently started using emacs and I'm enjoying using it for the most part. The only thing I'm not enjoying, is switching between buffers. I often have a few buffers open and I've grown tired of using C-x b and C-x C-b, are there any packages that make switching between buffers easier? I've looked into emacs wiki on switching buffers and I'd appreciate insight/feedback on what are are using/enjoying. Thanks.
UPDATE: iswitchb-mode is obsolete in Emacs >= 24.4, replaced by ido.
All of the features of iswitchdb are now provided by ido. Ross provided a link to the documentation in his answer. You can activate with the following in your .emacs (or use the customization interface as Ross suggests):
(require 'ido)
(ido-mode 'buffers) ;; only use this line to turn off ido for file names!
(setq ido-ignore-buffers '("^ " "*Completions*" "*Shell Command Output*"
"*Messages*" "Async Shell Command"))
By default, ido provides completions for buffer names and file names. If you only want to replace the features of iswitchb, the second line turns off this feature for file names. ido will ignore any buffers that match the regexps listed in ido-ignore-buffers.
The behaviour described below for iswitchb-mode applies equally to ido for switching buffers.
iswitchb-mode (Emacs < 24.4)
iswitchb-mode replaces the default C-x b behaviour with a very intuitive buffer-switching-with-completion system. There are more sophisticated options, but I've never needed more than this.
After you hit C-x b, you are presented with a list of all buffers. Start typing the name of the buffer you want (or part of its name), and the list is narrowed until only one buffer matches. You don't need to complete the name, though, as soon as the buffer you want is highlighted hitting enter will move you to it. You can also use C-s and C-r to move through the list in order.
You can turn it on by default with this in your .emacs:
(iswitchb-mode 1)
You can also tell it to ignore certain buffers that you never (or very rarely) need to switch to:
(setq iswitchb-buffer-ignore '("^ " "*Completions*" "*Shell Command Output*"
"*Messages*" "Async Shell Command"))
You can use C-x <right> (next-buffer) and C-x <left> (previous-buffer) to cycle around in the buffer ring. You could bind S-<right> and S-<left> to these functions. (S is the "super-key" or windows-key). This way you can save some keystrokes.
Moreover, note that C-x b has a default entry, i.e. it displays a standard value (most of the time this is the previously viewed buffer), so that you don't always need to enter the buffer name explicitly.
Another nice trick is to open separate windows using C-x 2 and C-x 3. This displays several buffers simultaneously. Then you can bind C-<tab> to other-window and get something similar to tabbed browsing.
M-x customize-group ido then set Ido Mode to Turn on both buffer and file and set Ido Everywhere to on. Then click the Save for future sessions button at the top and enjoy ido magic for both files and buffers. Read the docs to get a sense of how to use ido.
Also, take a look at smex.
ido-mode provides an efficient way to switch buffers.
ibuffer is best for managing all opened buffers.
anything is good for selecting an interested thing from different
sources. (for eg: a single key can be used to switch to another
buffer or to open recently closed file or to open a file residing
in the same directory or ... anything you want ... )
If you've looked at the Emacs Wiki, you probably have all this information already, but here are a few other relevant Q&As:
Emacs: help me understand file/buffer management
Buffer switching in Emacs
How to invoke the buffer list in Emacs
My toolkit consists of ibuffer, windmove+framemove, winner-mode, and a custom binding to make C-xleft/right and C-cleft/right less of a hassle to use.
I have mapped the "§"-key to 'buffer-list and I find it to be very efficient.
I've started using anything for a couple of days and I'm really liking it: http://www.emacswiki.org/emacs/Anything .
Emacs-fu has an good intro to anything: http://emacs-fu.blogspot.com/2011/09/finding-just-about-anything.html
My favourite function for this is helm-mini which is part of helm.
As other helm functions, it allows incremental narrowing of the selection. It also searches your recently visited buffers, which is a really nice way to re-open a buffer. Helm can be a little surprising at first and as a new Emacs user, I found it visually overwhelming and I preferred ido or ibuffer which have been suggested in other replies. But now I absolutely love it and use it all the time for countless things.
Something that I realized by accident and that can be useful:
mouse-buffer-menu is by default bound to <C-mouse-1> (Control key + mouse left click) and opens a popup with a list of the current buffers.
In Emacs (23 on Mac Leopard), I've discovered how to highlight the current line with hl-line-mode, but when using it globally in all buffers, it highlights the current line in all buffers in all frames.
I'd like to be able to highlight the current line (or at least have a different face for it) in only the currently active buffer. I'm sure this must be possible to some degree as the cursor changes dependent on whether the buffer is the current one or not.
Thanks
Singletoned
Looking at the documentation for hl-line-mode, it appears that you might have the variable hl-line-sticky-flag turned on. Try
C-h v hl-line-sticky-flag
to see if it's non-nil, and if so, then add
(setq hl-line-sticky-flag nil)
to your .emacs.