I use file named Makefile.include as a GNU makefile. I am trying to get emacs use the makefile-mode to use for this file. Alt-X makefile-mode works. Is there a way to tell emacs to use this major mode for this file right after opening automatically?
I tried putting
# _*_ mode: makefile; _*_
in the file but that does not appear to have the right effect. Btw I could not find the list of allowed strings one can use after mode:, so I tried BDSmakefile and some other variations as well.
Thanks.
See this question: Setting auto-mode-alist in emacs, and use the pair ("Makefile\\.include\\'" . makefile-mode).
Related
How can I view source code for a builtin Emacs package?
For instance given lisp code (require 'color), I would be interested in which functions are provided by that package. I googled emacs "color.el" and found the source code. But I wonder if this file can be viewed directly from within Emacs itself? By the way, find . -name 'color*' gives
./share/emacs/24.3/lisp/color.el.gz
./share/emacs/24.3/lisp/color.elc
You can get to the source code in a single command with M-x find-library.
You can either open the file directly in Emacs. I think .gz files are by default decompressed. Usually, I pick out one function from the package I'm interested in (e.g. org-mode), look up the documentation for that using C-hf org-mode RET and then click on the file name in the documentation buffer. It will take you the source file.
So ./share/emacs/24.3/lisp/color.el.gz is the gzipped source code, and you can open that in emacs by first doing M-x auto-compression-mode, and then visiting that file.
In vim it's very easy to find a file without knowing which directory the file is in. Doing this ":args **/file.hpp" if the file exists, it will get it open.
Is there any substitution in Emacs to do so? The find-file seems work for wildcards, but it doesn't do the tricky like vim does with **.
M-x find-name-dired looks like what You want (You will be prompted for root directory to start search with and a file mask)
A more blunt but still handy tool: M-x locate
Using OS X? This makes emacs use spotlight instead of the standard locate:
(setq locate-command "mdfind")
A good tip if you use ido-find-file:
From a known root directory, you can use ido-wide-find-file-or-pop-dir, which by default is bound to M-f.
FindFileInProject may also be worth looking at.
In Icicles you can find files by matching not just the relative file name but any parts of the path. You can use substring, regexp, and fuzzy matching. You can AND together multiple search patterns (progressive completion). See multi-command icicle-locate-file. And you can even search against file contents, as well as or instead of file name.
http://www.emacswiki.org/emacs/Icicles_-_File-Name_Input
I like
M-x ifind /some/path/to/start/file.hpp
or just
M-x ifind file.hpp
using the ifind package found here. Note: it does open up a *ifind* buffer which displays the results, which you can either select with the mouse, or navigate using C-x ` (aka M-x next-error).
I have to use windows to write some shell scripts. I decided to use emacs, but I get a weird error when running the script:
/bin/bash^M: bad interpreter: No such file or directory
Correct me if I'm wrong, but that looks like the shebang ends in \r\n instead of just \n. How can I tell emacs to only write \n? I'm in Shell-script major mode. It's quite surprising this isn't fixed by default.
As Jürgen mentioned, you need to use the set-buffer-file-coding-system. You can say
(set-buffer-file-coding-system 'unix)
and stick that into a function inside the find-file-hook so that it will set it for all the buffers you open. Alternatively, you can put it inside the write-file-hook list so that the file-coding-system is set properly before you dump the file to disk.
For a simpler way out, if you're using the GUI version of Emacs, you can click on the 3rd character in the modeline from the left. It's to toggle between eol formats.
Use:
set-buffer-file-coding-system
(should be bound to a key-sequence) before saving the file.
When I do indent-region in cperl-mode
if ($x) { next; }
Emacs reformats it to:
if ($x) {
next;
}
How can I make it stop doing that?
Note: the question originally said that this reformatting happens when yanking. I have yank setup to indent-region as well.
(setq cperl-break-one-line-blocks-when-indent nil)
Assuming you don't want it to autoformat when you type that kind of code either, simply change the bindings of {} to self-insert-command instead of perl-electric-terminator.
I can't find anything in cperl-mode that would do this. Try starting emacs with no customizations:
$ emacs -q
and then turn on cperl-mode in the scratch buffer:
M-x cperl-mode
Paste your text; it should look like the original (i.e. all on one line). Then start customizing cperl-mode:
M-x customize-group<RET>cperl<RET>
setting each variable individually for the current session only, and trying the paste in between each setting. If you suddenly find the behavior you're seeing, you have a starting place to look further (it could be a combination of options).
If you get cperl fully customized and it still doesn't behave "incorrectly" then you need to start looking at what other packages could be causing it. It could take a while....
It doesn't work that way for me, I just tried it with various settings in the Toggle... submenu under the Perl menu. Could there be something other than Cperl mode that's making that happen?
Without sounding like I'm giving a copout answer, why not just do this?
next if $x;
Same code, same effect, and just as readable (to me, at least), but I bet emacs won't try to reformat it.
So, i'm running emacs over a crappy ssh connection and I have it set up to use cscope. I can not use X because of this...hence I'm running emacs inside putty. However, when I search for something with cscope and it opens up the other buffer, I can not
follow the links where cscope tells me which file and line number the item is on. When I go t a line number and hit enter, emacs tells me 'buffer is read-only' (it is trying to actually put in a new line instead of following the link). anyone know how I can follow those links?
I don't know about cscope for sure - but you should be able to find out the appropriate key binding by doing a "Ctrl-h m" in the buffer with all the links. This should open another buffer showing you help/key bindings on all the active modes.
E.g. if you do the same thing in a grep result buffer it indicates the key binding "C-c C-c compile-goto-error" which is used to open file at the grep line number (so it may be the same keys for cscope).
As a workaround, I'm pressing <space> key on the cscope result line. It shows the code in the other frame, although it doesn't position the cursor there.
Changing this line in xcscope.el fixed the problem on my computer.
-(define-key cscope-list-entry-keymap [return] 'cscope-select-entry-other-window)
+(define-key cscope-list-entry-keymap (kbd "RET") 'cscope-select-entry-other-window)
Could you use cscope with Tramp mode? I'm not familiar with cscope, but I've had great results using tramp mode to read/write files remotely over an SSH connection.
I believe GNU find version 4.2 and above supports -L to follow symbolic links. Hence,
find -L . -name *.[ch] > cscope.files
cscope -b -R -q -i cscope.files
might work well
Another workaround. Just type 'o' to select what you want. It means cscope-select-entry-one-window :)