emacs kill multiple buffers by using regex [duplicate] - emacs

This question already has answers here:
Killing buffers whose names start with a particular string
(6 answers)
Closed 5 years ago.
I want to kill all the buffers which start with info, I typed C-x-k info*<*>, it shows "no match".
So I know that I cannot use * to stand for all characters.
What is the correct expression it should be?
Any help would be grateful.
This is my screenshot. Please have a look.
emacs buffer list window

M-x kill-matching-buffers is a standard command for this.
How do I answer y automatically (kill-matching-buffers asks if I should kill a modified buffer)? may also be of interest (although I'm not actually recommending doing that in general).
So I know that I cannot use * to stand for all characters.
.* will match zero or more non-newline characters, but you don't need to use that here, as kill-matching-buffers command does not require a match on the entire name. ^info would match your (stated) requirement.
I encourage you to read C-hig (emacs) Regexps to learn about the syntax of regular expressions in Emacs.

Your buffers have names *info* and *info*<N>, N = 3..16.
C-x k *info TAB TAB shows you all matches for the buffers you want to kill. But C-x k lets you kill only one at a time.
If you use library Icicles then C-x k is a multi-command, which means that it can kill multiple buffers, individually or together. (And Icicles lets you pattern-match using regular expressions. But you don't need that here.)
In this case, you just do C-x k *info TAB C-!, to kill all of the *info buffers.
C-! applies the action to all objects that match your current input pattern.

Related

What is name of temporary buffer in emacs terminology

There are some kind of buffers in Emacs, that are readonly and thay can be closed on q key.
For example, search functionality in projectile (C-c p s g) opens search results buffer which can be closed just pressing q key.
What name of this kind of buffers in Emacs terminology and how to manage them programmatically?
In general, read-only buffers which can be closed with q are likely to have the major mode special-mode, or some derivative thereof.
See C-hig (elisp) Basic Major Modes RET
This kind of buffers in temporary buffer.
You can put your output to temporary buffer using with-output-to-temp-buffer function
A good article about this - Emacs: Capture Shell Command Output in Temporary Buffer
The question is unclear. Temporary buffers do not necessarily bind q to quit or anything similar. Keybindings of temporary buffers are not necessarily similar at all. Look at *Messages* and *scratch*, for example.
There is no single definition of "temporary" buffer in Emacs. That term just means (roughly) any buffer that a user is not likely to save or want to save. In general, any non-file buffer could be thought of as temporary.
Buffers for which q performs some sort of quit operation are not necessarily temporary either, but they often are (not expected to be saved). You can save any buffer using C-x C-w - a *Help* buffer, for instance. And even when q quits the window or buffer in some sense, the exact behavior can be quite different from one buffer to another.
Finally, user settings can affect what things like q (quit) operations do. And they can depend on the particular buffer as well.
In short, the question is not specific enough to draw a helpful answer. But perhaps some of the above can help a general understanding. My suggestion is to pose another, very specific question.

Emacs opens ibuffer or compilation in same window rather than other window

I have been using emacs for many years. The past year or so, there has been an annoying problem, which is that sometimes Ibuffer or the compilation buffer runs in the same window that I am already in. I generally have 2 buffers open, one above the other. I always want Ibuffer to open in the one I am not currently in. But it seems to pick randomly. Is this a bug or feature? Can I stop it? I have searched for an answer several times, but I have not found one. I am running GNU Emacs 24.5.1 in the terminal. Thanks.
The following answer relates to the usage of ibuffer:
The original poster may wish to use the keyboard shortcut bound to the letter o, which is ibuffer-visit-buffer-other-window. The doc-string states that this function is designed to: Visit the buffer on this line in another window. The function ibuffer-visit-buffer-other-window uses pop-to-buffer and switch-to-buffer-other-window, which should avoid a window that is dedicated: http://www.gnu.org/software/emacs/manual/html_node/elisp/Dedicated-Windows.html
The return key is bound to ibuffer-visit-buffer (which uses switch-to-buffer), and the doc-string states that this function is designed to: Visit the buffer on this line. If optional argument SINGLE is non-nil, then also ensure there is only one window. The optional argument can be used interactively by typing C-u RET.

How to format clojure in emacs [duplicate]

I'm new to Clojure and new to Emacs.
Is there an Emacs short-cut to intelligently re-indent the whole file?
if not, is there at least a way to indent selected regions left or right?
I feel like I'm back in the stone age repeatedly pressing the arrows
C-x h selects the entire buffer. C-M-\ reindents the selected region.
Ctrl-x, h (select all) followed by Tab (to indent)
cider-format-buffer command (Since cider 0.9.0)
When you capture data from a sequence like C-u C-c C-e
(cider-eval-last-sexp), the raw data output to your buffer can be
unwieldy to inspect/work with. And the normal code-indenting commands
(mentioned in answers here) don't handle it well.
For handling results from such evaluated expressions, try
cider-format-edn-region.
As a concrete example, have you ever tried reformatting your
~/.lein/profiles.clj? This is pretty hard to do and keep
consistent, until you discover cider-format-edn-region. Take
caution that it will, however, remove any comments.
Use cljfmt for many configurable ways to reformat/reindent. It has an Emacs plugin, but also can be run via lein.

How do I intelligently re-indent Clojure in Emacs?

I'm new to Clojure and new to Emacs.
Is there an Emacs short-cut to intelligently re-indent the whole file?
if not, is there at least a way to indent selected regions left or right?
I feel like I'm back in the stone age repeatedly pressing the arrows
C-x h selects the entire buffer. C-M-\ reindents the selected region.
Ctrl-x, h (select all) followed by Tab (to indent)
cider-format-buffer command (Since cider 0.9.0)
When you capture data from a sequence like C-u C-c C-e
(cider-eval-last-sexp), the raw data output to your buffer can be
unwieldy to inspect/work with. And the normal code-indenting commands
(mentioned in answers here) don't handle it well.
For handling results from such evaluated expressions, try
cider-format-edn-region.
As a concrete example, have you ever tried reformatting your
~/.lein/profiles.clj? This is pretty hard to do and keep
consistent, until you discover cider-format-edn-region. Take
caution that it will, however, remove any comments.
Use cljfmt for many configurable ways to reformat/reindent. It has an Emacs plugin, but also can be run via lein.

Emacs: help me understand file/buffer management

I've been using emacs for all of my text editing needs for the past three years now. When I'm in a single file, working on code or whatnot, I'm fairly efficient. With two files, I can "C-x b RET" between them and I do fine. However, whenever I need to be working on more than two files at a time, I tend to get lost.
Here are some of the problems that I'd like to work on:
I forget what some of my buffers are called, but I don't understand why C-x C-b splits my window into two buffers and exits the mini buffer. Sure I can switch buffers and choose a buffer to visit, but this feels unintuitive, and leaves me with two buffers open.
When I visit a directory rather than a file, I have a convenient list of all of the files and directories. I usually want to do one of two things with this: 1) Open a single file and never see this buffer again OR 2) Open a bunch of files and never see this buffer again. I don't really know how to do this, as moving the point to a file and hitting return doesn't do either of these things.
I know that my buffers aren't like tabs, but I have an inclination to want to scroll through them to find what I want. I don't know of any key-bindings for this, but I'd like it to be M-n / M-p or the like. Then again, this may be a horribly inefficient way to switch buffers.
When I open interactive help of any kind (for example in ESS), I have a habit of switching back to the buffer I was working in and using C-x 1 to get back to a single buffer. When I do this, however, the help buffer hangs around in my buffer list, further confusing me. I know I can switch to that buffer, kill it, switch back, and then go back to a single buffer, but this seems wrong.
The way I've dealt with this so far involves using a tiling window manager and a few emacs windows in different work-spaces, rather than actually learn the best way to manage a number of files in emacs. I don't necessarily want to change emacs to better fit my needs (although I am open to that if it fits in with what I'm about to say), instead, I'd like to grok the thought process behind handling files/buffers the way that emacs does, and how I can be more efficient with it.
Any answer that would help me understand the correct way, or a more efficient way to manage my buffers or files would be greatly appreciated.
Bind C-x C-b to ibuffer. This is a better buffer listing facility with many advanced features, and its default behaviour is to replace the current buffer with the buffer listing, and then bury the listing when you select a buffer (leaving you with the newly-selected buffer in place of the original one).
You can simply use C-x b to enter your selection in the mini-buffer, of course; however the tab-completion (which is needed to make this a viable option, IMO) does open a new window temporarily, at which point I think you might as well familiarise yourself with something with more features.
Use a instead of RET when selecting from dired. This kills the dired buffer instead of leaving it behind. C-h m in any buffer will show you the help for its major mode (followed by help for the minor modes), and you can read about all the available dired key bindings there.
http://www.emacswiki.org/cgi-bin/wiki/TabBarMode ? (edit: I prefer RĂ©mi's answer for this one, but TabBarMode would give you the visual tab element if you were particularly keen on that.)
q is bound to a 'quit' function in a great many major modes. Generally it buries the buffer rather than killing it, but I certainly find that fine.
To elaborate a little on #1, ibuffer has lots of nice features, and M-x customize-group ibuffer RET will give you some idea of how you can customise it to your liking.
Furthermore, you can filter the buffer list by many criteria (again, use C-h m to see its help page), and then generate a 'group' definition from the current filters, and save your custom filters and groups for future usage.
For example:
/ f ^/var/www/ RET: filter buffer list to show only filenames starting with /var/www/.
/ s Web filters RET: name and save active filter set to your init file.
/ g Web development RET: create a named group from the active filters.
/ S My groups RET: name and save group definitions to your init file.
/ r Web filters RET: invoke the "Web filters" filters.
/ R My groups RET: invoke the "My groups" groups.
RET on a group name to collapse or expand it.
C-k and C-y to kill and yank groups, to re-arrange them.
C-h m for more information...
This way you can have a single Emacs instance running, and create filters and groups for different types of task, and easily switch between them.
I think you will really enjoy Ido for dealing with multiple buffers who's names you can't exactly remember. When you type C-x b it shows a list of open buffers in most used order. As you type some of the characters in a buffer name the list is filtered. The characters you type don't have to be at the begging of the name or contiguous. Using C-f, C-b or left/right arrow keys cycles through the buffer choices.
Also see Smex for Ido like functionality for M-x
Closing windows is done with C-x 0. Intentionally splitting the window is done with C-x 2 for horizontal, C-x 3 for vertical. I love this feature, since it allows me to have test and production code visible at the same time. C-x o takes me to the other window.
I use C-x right (or C-x C-right) and C-x left (or C-x C-right) to go to the next and previous buffer. I don't mind anymore off the few buffer that lay around in Emacs but you could use k in the buffer list to kill the buffer you don't use anymore.
You can also try Iswitchb mode which provides auto-completion for buffer names when you switch buffers via C-x b.
To activate:
M-x iswitchb-mode
Or add to your .emacs file:
(iswitchb-mode)
It is similar to Ido mode for buffer switching but a bit more lightweight.
Also, if you want a more customizable listing of your buffers then use M-x bs-show as an alternative to C-x C-b. In that buffer type ? to get a list of actions you can perform.
I think the number one most useful extension for flipping through buffers is Anything. It lets you start typing part of a buffer (or file!) name and it will figure out what you want. I've rebound C-x b to anything-for-buffers. It makes life so much better.
As always, there are many ways to help you with this; it depends a bit on personal preference what works best, here are some links with explanations:
ibuffer; which is an updated buffer menu (C-x C-b)
ido, which let's you have more powerful autocompletion to switch through buffers. It's a kind-of 'better iswitchb'.
These two are enough for me; but you may also be interested in the tabbar-mode, which gives you rudimentary tabs (like firefox has them).