Emacs sr-speedbar - emacs

I am currently trying to learn Emacs more in depth so that I can do more with my Emacs than just simple editing stuff...
I am making good progress and at the moment I am trying to configure the 'sr-speedbar' module to my liking, but some details I can't figure out myself:
Say that I've 2 open buffer windows A and B plus the speedbar window. If I open a file by pressing Enter in the speedbar window, then the new file always get opened in the same buffer window B (which I opened last). Can I somehow specify that the new content should be opened in buffer window A?
Currently the speedbar window refreshes itself automatically to the new location whenever I open a new file using 'C-x C-f'. This is actually pretty useful, but sometimes I don't want this when I am quickly trying things out in a tmp file. And the refresh also "destroys" my "tree-view" of the speedbar, where I expanded the directory contents rather than opening them directly. The question is, how can I suppress this "refreshing behaviour"? Can I somehow disable the automatic mode and trigger it manually if I need it?
And do you guys have more useful tips regarding speedbar navigation? How does a Emacs guru use speedbar or are there better alternatives?
Thx in advance for your help!

You can turn off the auto-refresh in your init file like this -
(require 'sr-speedbar)
(setq sr-speedbar-auto-refresh nil)
and/or turn it on and off later with the function sr-speedbar-refresh-toggle.
The defaults it (and speedbar) comes with are a bit odd though - it also doesn't show files that it doesn't recognize, uses images for buttons, and is set on the right side - so you can set these if you'd like -
(setq speedbar-show-unknown-files t) ; show all files
(setq speedbar-use-images nil) ; use text for buttons
(setq sr-speedbar-right-side nil) ; put on left side
I do use sr-speedbar for projects that have enough of a directory structure - otherwise I use the usual switch-to-buffer (C-x b), ibuffer (C-x C-b), and dired (C-x d), and another function that switches to the previous buffer. Also bound to single keys because they get used so much.
But... I'm still learning Emacs - I haven't tried helm, projectile, or project-explorer yet - they look interesting also.

Related

How can I more easily switch between buffers in Emacs?

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.

Emacs C-x C-c overriding save-buffers-kill-terminal if within last open frame

I have setup emacs -daemon to run on login to Gnome and associated emacsclient with .cpp and .py files that I work with in Eclipse in order that emacs is used as my default editor for these files when selected within Eclipse. This way I can get a good work flow combining the editing capabilities of emacs and the project/build management and debugging facilities of Eclipse.
Anyhoo... I want to prevent C-x C-c from closing the Emacs frame I am currently editing in if it is the only Emacs frame remaining visible at any given moment.
Is there a way of querying the daemon Emacs process in order to find out how many frames are open and override the default C-x C-c behaviour to do nothing (if only 1 frame remaining) thereby ensuring there is always at least one visible frame open at all times?
Some elisp that implements this behaviour and that can be added to my .emacs would be great.
Bonus Points :¬)
I have aliases that map vi, emacs etc... to "emacsclient -c", so I get emacs frames coming and going all the time in general. A further enhancement would be for Eclipse to send files that I want to edit directly to a specific frame e.g. the 1st frame opened with emacsclient -c.
Make emacs immortal (what ever the way you've started it) :
(defadvice kill-emacs (around emacs-immortal) nil)
(ad-activate 'kill-emacs)
Use ad-deactivate to deactivate this trick.
Within emacs-clients, save-buffers-kill-terminal only calls server-save-buffers-kill-terminal, so you might want to install an advice onto that to not affect non-client frames. The frame-list function cal be used to introspect the currently existing frames. It apparently always includes one entry for the daemon process itself, and then one for each open frame.
(defadvice server-save-buffers-kill-terminal (around dont-kill-last-client-frame activate)
(when (< 2 (length (frame-list)))
ad-do-it))

Restore Emacs Session/Desktop

I've been searching for how to restore an emacs session, with no luck. I'm looking to restore all previously open buffers, some of which might contain erc, shells, directory listings, files, etc.
Every time I open emacs, I spend a considerable amount of time arranging my buffers; splitting them into rows and columns, opening a shell, arranging irc channels. It takes a while to get onto work.
I've tried adding the following to my init.el
(desktop-save-mode 1)
And then using M-x desktop-save. This only seems to restore files that are open, not shells or anything else running within buffers.
I've also checked the following questions:
Session management in emacs using Desktop library
Emacs session / projects / window management
Emacs: reopen buffers from last session on startup?
And read through:
DeskTop and EmacsSession at emacsWiki.org
Here's a screenshot example of my emacs session.
A simple answer would be to just focus on real work :P
I'd suggest a simple solution - create a function that sets up your preferred layout. For example I like to have some IRC channels in the second half of my screen in separate windows, so that I may have a look at them from time to time, while coding for instance in another window. So I've written some simple code to take care of the window splitting and arrange my buffers as I wish:
;; show some buffers
(defun show-some-buffers (buffer-list)
(split-window-horizontally)
(other-window 1)
(dolist (buffer buffer-list)
(split-window-vertically)
(switch-to-buffer (get-buffer buffer))
(other-window 1))
;; at the end we have one extra window we need to delete
(delete-window)
(balance-windows))
;; show some erc buffers
(defun show-erc-buffers ()
(interactive)
(show-some-buffers '("#emacs" "#clojure")))
The code is fairly simple and features no error checking, but it will give you a hint about what I mean.
You might want to consider using registers as well to store some window configurations.
As you've found, desktop.el and session.el are a good start, but they don't restore the window layouts.
However, using revive.el you can save/restore arbitrary window configurations, which are remembered between restarts.
Also check out these hints relating to window layouts, which cover winner-mode and the trick of saving window configurations into registers.
In addition to #Bozhidar's excellent answer on automating your window layout (which I do myself), you may also want to look into using GNU Screen which can be used to retain an arbitrary set of processes across log ins. There's a pretty good tutorial here, and since you'll be using emacs you'll also want to give this a read.

How to remove directory window and add a cscope window in Emacs ECB?

Yesterday I installed ECB on my Emacs, and I find method window and history window quite useful. But directory tree window and source window less useful, if I can hide them I will save more space for method window and history.
Another problem is that I use cscope to search through the project for definitions and callers, the result of cscope is shown by splitting the main window into two. I'd like to know is it possible to make cscope result window fixed in ECB window, just like method window and history window?
Many thanks.
===============
Thanks to sanityinc and ecb documents, finally I create a layout with cscope fixed in it. I'll post code here in case it will help others.
(require 'ecb)
(ecb-layout-define "my-cscope-layout" left nil
(ecb-set-methods-buffer)
(ecb-split-ver 0.5 t)
(other-window 1)
(ecb-set-history-buffer)
(ecb-split-ver 0.25 t)
(other-window 1)
(ecb-set-cscope-buffer))
(defecb-window-dedicator ecb-set-cscope-buffer " *ECB cscope-buf*"
(switch-to-buffer "*cscope*"))
(setq ecb-layout-name "my-cscope-layout")
;; Disable buckets so that history buffer can display more entries
(setq ecb-history-make-buckets 'never)
There are a bunch of layout presets, listed here, one of which might work for you. Also, you can create a custom layout following the directions here, which can even be done interactively using the ecb-create-new-layout command.
The latter page also describes how to add a new fixed window, of the type you want for cscope.

Pin Emacs buffers to windows (for cscope)

For my day job, I live in Emacs. Utterly. I also have become pretty dependent on CScope to help me find things in the code.
Normally, I have 2 windows in a split (C-x 3):
alt text http://bitthicket.com/files/emacs-2split.JPG
And I use the right window for code buffers and the left window for the CScope search buffer. When you do a CScope search and select a result, it automatically updates the right-side window to show the buffer referred to by the result. This is all well and good, except that it causes me to lose my place in some other buffer that I was studying. Sometimes this is no biggie, because [C-s u] gets me back to where I was.
What would be better, though, is to have 3 split windows like this ([C-x 2] in the left window):
alt text http://bitthicket.com/files/emacs-3split.jpg
And have the bottom left window contain the CScope search buffer, and the top left window be the only buffer that CScope ever updates. That way, I can see my CScope searches and navigate around the code without losing the buffer I'm focused on.
Anyone know how I can do that?
Put this in your .emacs file:
;; Toggle window dedication
(defun toggle-window-dedicated ()
"Toggle whether the current active window is dedicated or not"
(interactive)
(message
(if (let (window (get-buffer-window (current-buffer)))
(set-window-dedicated-p window
(not (window-dedicated-p window))))
"Window '%s' is dedicated"
"Window '%s' is normal")
(current-buffer)))
Then bind it to some key - I use the Pause key:
(global-set-key [pause] 'toggle-window-dedicated)
And then use it to "dedicate" the window you want locked. then cscope can only open files from its result window in some OTHER window. Works a charm. I specifically use it for exactly this purpose - keeping one source file always on screen, while using cscope in a second buffer/window, and looking at cscope results in a third.
Well, I decided to not be a reputation-whore and find the answer myself. I looked in cscope.el as shown on the Emacs wiki, as well as the xcscope.el that comes with the cscope RPM package on RHEL.
Neither appear to give a way to do what I'm wanting. The way is probably to edit the ELisp by adding a package variable like *browse-buffer* or something and just initialize that variable if not already initialized the first time the user does [C-c C-s g] or whatever, and always have the resulting code shown in *browse-buffer*. Then the user can put the *browse-buffer* wherever he wants it.