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.
Related
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.
Goal: I want to have show-trailing-whitespace enabled for all buffers save a few. Exceptions posing a problem are *Shell Command Output* and its cousin *Async Shell Command*.
I usually have show-trailing-whitespace customized to t. Therefore it is active in all new buffers.
I would also like to have it turned off for certain buffers, foremost amongst them *Shell Command Output*. This poses a problem for me:
The output buffer doesn't use a special mode; it is still in fundamental-mode. There is no fundamental-mode-hook that I could hook this setting into.
There is the after-major-mode-change-hook which is run when the major mode is changed to fundamental-mode, but the buffer starts out in that mode and therefore this hook is not run.
There doesn't seem to be a way to hook into get-buffer-create.
I know I can always advise the function get-buffer-create for this particular example, but I try to avoid that as much as possible.
Any hints?
You might be better off looking at the problem from the other side, and only set the var in those modes where you want to see trailing whitespace.
But I think you have a good point: these shell output buffers should not use fundamental-mode. It's probably time for M-x report-emacs-bug
In accordance with the accepted answer, here's a code snippet that enables trailing whitespaces highlighting for specific modes only:
(setq-default show-trailing-whitespace nil)
(defun namespace/show-trailing-whitespace ()
"Highlight trailing whitespaces in this buffer."
(setq-local show-trailing-whitespace t))
(dolist (hook '(prog-mode-hook text-mode-hook))
(add-hook hook 'namespace/show-trailing-whitespace))
This snippet is essentially taken from Steve Purcell's configuration.
I'm very new to the Emacs text editor and have just started customizing my ~/.emacs file. I'm wondering if it's possible to change an Emacs setting while it's running. For example, if I put the following in my ~/.emacs file:
(show-paren-mode 1)
I can do the same thing when Emacs is running by typing:
M-x then scroll-step then 1.
Why doesn't this work when I want to do something like this:
(setq scroll-step 1)
When I type:
M-x then setq,
all I get is (no match). There must something I'm not understanding here.
There is a few things:
yes, you can change settings at run-time. If you edit your .emacs file, put your cursor after the closing parenthesis in:
(show-paren-mode 1)
And hit ctrl-x ctrl-e and it will evaluate the code.
some things and variables (though very few) require them to run special things after the setting was changed. Generally there aren't too many and most variables you set will take effect immediately after doing the steps in #1.
However, if you edit your settings using M-x customize you'll find that when you make changes there it'll make the settings active immediately, even in those special cases where something special needs to be done after a value change.
M-x allows you to run "interactive" commands. Some elisp functions are supposed to be called directly by the end user, and others are really only meant when writing elisp into a file. And M-x only lets you easily do the ones that have been marked "interactive". Though M-shift-: will let you type an expression and see the results. EG, try M-shift-: followed by (1+ 2) at the prompt.
I want to play and experiment with a number of software tools, each of which will have a command line interface. Some of these tools include hbase, pig, erlang, and prolog. I want to use emacs as a UI to these tools the same way I can run a python shell with M-x run-python or a Lisp interpreter with ielm mode.
Is there a recipe I can follow to wrap one of these command line tools in an emacs mode? I'm looking for something which will display the tool's prompt, let me search through the history with C-c C-n/C-p, submit the current input to the tool's process which I hit Enter, and display the tool's output.
I know many of these tools probably have emacs modes already, I am interested in how to quickly build one if nothing exists.
I recently built an "inferior gosu mode" for the gosu language. It actually turned out to be pretty simple: I just extended comint which is the mode on which both shell and ielm are based. Here is the important bit of the code:
(require 'comint)
(defun inferior-gosu-mode ()
(interactive)
(comint-mode)
(setq comint-prompt-regex inferior-gosu-prompt)
(setq major-mode 'inferior-gosu-mode)
(setq mode-name "Inferior Gosu")
(setq mode-line-process '(":%s"))
(use-local-map 'inferior-gosu-mode-map))
The use-local-map bit is just where you define special key bindings; I have it as just a copy of the comint bindings:
(defvar inferior-gosu-mode-map nil)
(unless inferior-gosu-mode-map
(setq inferior-gosu-mode-map (copy-keymap comint-mode-map)))
After this I had some simple code that defined a command to launch a process that would pop open the *inferior-gosu* buffer if it existed. I also added a bit of code to the normal gosu mode for opening an inferior-gosu shell.
In short: use comint.
Here's a link to the whole code, but there isn't much more to it: https://github.com/TikhonJelvis/Gosu-Mode/blob/master/inferior-gosu-mode.el
Naturally feel free to use that code however you want; you might also want to look at the normal gosu mode to see how you could integrate you erlang and prolog into the languages' respective editing modes.
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.