start emacs sr-speedbar in buffers mode on loading - emacs

I use sr-speedbar in emacs. On loading, it starts in file mode. I then manually change it to buffers mode. Since I almost always use buffers mode, I would prefer to start it in that. However, I cannot find any way after googling and wondering if someone with Lisp expertise has inputs on how to resolve this

The variable speedbar-initial-expansion-list-name controls the initial view of speedbar. The default value is "files". The other two possibilities are "quick buffers" or "buffers" -- either of the following could be placed in the .emacs file after a (require 'speedbar) statement:
(setq speedbar-initial-expansion-list-name "quick buffers")
or
(setq speedbar-initial-expansion-list-name "buffers")

The sr-speedbar is a package built on speedbar, so you need to consider customizing speedbar itself as well. There is no existing customization option for what you want but you can implement youself by using Hook, in your case, speedbar-mode-hook.
The following should do what you want
(add-hook 'speedbar-mode-hook
(lambda ()
(speedbar-change-initial-expansion-list "quick buffers")))
I copy it from https://stackoverflow.com/a/24291661/2999892 and I've test it by using both speedbar and sr-speedbar.

Related

emacs doremi: to change color-themes

I'm trying to get doremi working in emacs. Specifically, at this stage, to allow me to quickly scroll through a condensed list of color-themes and see each theme as I go through it. For this I would use the 'M-x doremi-color-themes+' command.
What I've done:
Installed color-themes (successfull)
Installed doremi.el, doremi-cmd.el, ring+.el and added
(add-to-list 'loadpath "~/elisp/themes")
(add-to-list 'loadpath "~/elisp/doremi/")
(require 'color-theme)
(color-theme-initialize)
(color-theme-classic)
;; create a list of color themes to scroll through using 'doremi-cmd
(setq my-color-themes (list 'color-theme-classic
'color-theme-retro-green
'color-theme-gray30
'color-theme-subtle-hacker
'color-theme-jonadabian-slate))
(require 'doremi)
(require 'doremi-cmd)
(require 'ring+)
to the .emacs file.
What emacs does:
When I type the comand 'M-x doremi-color-themes+' into the mini-buffer it seems to accept that I've given it a valid command and tells me to use the and arrow keys to move through the list. But when I do that all that happens is the cursor moves up and down in the active window. No changing of color-themes.
Being somewhat new to emacs (and especially customising it) I'm sure I have missed a step or put something in the wrong place. Perhaps there's some sort of (setq 'bla-bla-bla (...)) I need to do?
Sorry for your trouble. Please state your Emacs version (M-x emacs-version), and your version of color-theme.el.
You do not need to require library ring+.el if you use Emacs 23 or later (its code was included in GnuEmacs 23.)
You do not need to use (color-theme-initialize) or (color-theme-classic). The former is done automatically by doremi-color-themes+.
Try starting from emacs -Q (i.e., no init file, ~/.emacs), to be sure there is no interference from stuff in your init file.
Your variable my-color-themes is not referenced anywhere. Instead of defining that variable, just customize user option doremi-color-themes. (Or leave its value nil, which means that all color themes will be cycled through.)
Feel free to contact me by email if you continue to have a problem. Or continue here, if you prefer.
[Just to be sure: you are using color-theme.el, right? There is a lot of confusion out there between Emacs "custom themes" and color themes. Do Re Mi supports both, but they are different critters.]
After a bit for back and forth with #Drew we found a solution to the problem.
It turned out the major problem was that I was using emacs in 'terminal mode' rather than as a GUI application. Bare in mind I'm using a mac.
In the context of Terminal, my arrow keys send escape sequences and so doremi cannot read the event as intended. So it just escapes and applies the message to the active buffer.
There is an answer.
By adding the following lines to my .emacs file (or whatever your init file for emacs is) I was able to redirect doremi to use two other keys. ie. not the up and down arrows.
(setq doremi-down-keys '(?n))
(setq doremi-up-keys '(?p))
Doing this tells doremi to use 'n' as the down key and 'p' as the up key. And all works just fine.
Because I am only new to the world of programming and computing I may often use incorrect terminology. If this is the case please let me know and I will edit accordingly for clarity and consistency.

Does windmove support wrap around navigation in Emacs?

I'm using windmove to switch between windows. Per default, windmove does not wrap around, for example, windmove-up will fail when you are already at the top of the window. However, I want it to wrap around and navigate to the bottom window.
I managed to get it working but the solution is quite a hack (if there is an error just reverse the direction and continue until it fails again):
(define-key my-keys-minor-mode-map (kbd "C-M-k") (lambda () (interactive)
(unless
(ignore-errors (windmove-up))
(while (ignore-errors (windmove-down)) ()))))
Is there a more elegant solution? Does windmove provide a straightforward way to do it?
M-x customize-variable RET windmove-wrap-around RET
Is that it? The variable is basically at the top of windmove.el.
If you don't want to open the source file,
M-x customize-group RET windmove RET
would show you all customizable variables belonging to this mode. Both of them.
For changing windows, you might want to try this package:
switch-window: when invoked, it allows you to select a window from choice (it overlays numeric choices from 1 to the amount of windows over the windows). Choosing a number will switch to the associated window.
This might be even easier to use for navigation of window purposes. As for a direct question of your answer, I would indeed program it in a similar way, though I would also suppose there is a more suitable answer.
Add this to your .emacs file:
(setq windmove-wrap-around t)

Load iMenu at initialization

I'm sorry of r a very basic question. I am trying to load iMenu in GNU Emacs at the initialization. Usually it loads by executing M-x imenu-add-menubar-index. I understand I need to put something into my ~/.emacs file, but everything I tried does not work.
I'm new to GNU Emacs and Lisp, what do I need to put there for the index menu to be generated automatically?
You can have an Imenu "Index" menu bar item available for all buffers that belong to a certain major mode by adding imenu-add-menubar-index to its mode hook. For example,
(add-hook 'c-mode-hook #'imenu-add-menubar-index) ; c
(add-hook 'python-mode-hook #'imenu-add-menubar-index) ; python

Emacs on-the-fly mode changing

When writing shell scripts (which to my knowledge usually don't have .* suffix), I usually do something like the following
1) emacs foo
2) Type in #!/bin/sh
3) Close and reopen emacs so that the shell-script major mode is enabled
Is there any nice way so that I don't have to do step (3)? I could bind M-x shell-script-mode to some key combination, but is there some general way to make emacs re-evaluate the mode using its standard set of rules?
The general way to do it would be M-x normal-mode
Add this to you .emacs:
(add-hook 'after-save-hook
'(lambda ()
(if (not (executable-make-buffer-file-executable-if-script-p))
(normal-mode))))
The first bit executable-make-buffer-file-executable-if-script-p was not part of your question but is also useful: it makes the file executable if it wasn't already (if it looks like a script). If we end up flipping the execut bit, then we also set the mode.

In Emacs, how do I figure out which package is loading tramp?

I have a strange interaction with tramp and cygwin-mount (I think: Emacs: Tab completion of file name appends an extra i:\cygwin). Because of this, I want to disable tramp. I'm unable to find anything in my .emacs which is loading tramp explicitly. I can see "Loading tramp..." when I hit a tab in the find-file minibuffer. I'd like to figure out what package is causing the loading of tramp and disable that. How do I go about doing this? I tried searching for (require 'tramp) but couldn't find anything interesting. The only other option I can think of is to comment out bits of my .emacs one-by-one and see which one works - but this is so brute-force, I'd like a cleverer (and easier) way.
What a great question! If only because I was not aware of the function (eval-after-load file form) which will enable you to write code like the following and put it in your .emacs file:
(eval-after-load "tramp"
'(debug))
Which will, in brute force form, vomit a backtrace in your window and reveal the offending library.
I think you'll find that tramp is turned on by default. If you do:
M-x customize-apropos
Customize (regexp): tramp
('Customize (regexp):' is the prompt from emacs) you'll see two variables listed (at least I do in emacs 23), something like:
If you set tramp-mode to 'off', save for future sessions, and restart emacs tramp should no longer be loaded. I believe you can just turning it off in the current session should allow you to test this, but this doesn't always work with customize variables, although it should do with something like tramp that is part of the standard emacs distribution.
I don't have emacs 22 installed any more, but something similar should work for that too.
I had a similar problem with tramp, when one day I found
"/C:\...\debuglog.txt" on my system.
Because of that file, auto-complete was invoking tramp each time
I entered "/". And tramp was of course giving an error.
auto-complete was calling
(expand-file-name ...)
which, because of the current file-name-handler-alist, was calling tramp.
My solution was:
(delete-if
(lambda (x)
(or (eq (cdr x) 'tramp-completion-file-name-handler)
(eq (cdr x) 'tramp-file-name-handler)))
file-name-handler-alist)
Instrument find-file for debugging and/or instrument your init file for debugging. Then you can step through the loading and see where the tramp stuff is loaded.