Surprisingly file .bashrc_custom has Fundamental mode even though files .bashrc and .bash_profile in the same directory have (Shell-script[bash]).
How can I configure major mode for .bashrc_custom?
Put this into your Emacs init file:
(add-to-list 'auto-mode-alist '("\\.bashrc_custom\\'" . sh-mode))
Note possibly directory local variables are not questioned here, it's ruled by a list reading strings resp. regular expressions for matching file-names.
Related
There's a huge literature on the topic, but, nevertheless, I cannot get this done.
My ultimate goal is to work with fstar on Microsoft Windows.
C-x C-f resolves ~ as C:/Users/myname which is in line with my HOME environment variable in the Environmental variables Windows section.
(expand-file-name user-emacs-directory), as described here yields, C:/Users/myname/.emacs.d/
In C:/Users/myname/.emacs.d/ I have placed .emacs.el and init.el with the suggested script:
(require 'package) (add-to-list 'package-archives '("melpa" .
"http://melpa.org/packages/") t) (package-initialize)
However M-x returns undefined, no matter if I start Emacs with or without the -q flag (see here). My "Messages" buffer is empty".
A couple of things you could try:
Check the value of the variable user-init-file (use C-h v). That should tell you if Emacs loads the file you want it to load. If you started Emacs with the -q option, the value of this variable should be nil.
The error M-x is undefined can be caused by rebinding the Escape key. (That's because pressing a key while holding down the "Meta" key is equivalent to first pressing Escape and then the key in question.) Is there something in the init file that might cause this to happen?
Try starting Emacs with -Q instead of -q. This makes Emacs skip "site-wide" init files. I can't really think of a reason why your system would have any of those, but it might be worth ruling this out.
You could edit your question and include your entire init file (surround it with ``` on a line by itself), so we could have a look.
In my .emacs, I have the following lines:
(require 'xclip)
(xclip-mode 1)
However, on some computers, I can't have it (e.g. on computer cluster without X11 which xclip requires).
Yet, how can I keep the same .emacs, for instance by using an if statement checking if xclip is in the PATH? I searched for tips online, but coudln't find anything. (Sorry if my question is redundant!)
(when (and (executable-find "xclip")
(require 'xclip nil 'noerror))
(xclip-mode 1))
N.B. Emacs has its own path in exec-path, but it should be initialized to something similar to the PATH env var.
Emacs doesn't recognize the extension .hgrc, so it uses fundamental mode and all the text is black, including comments. Is there a good mode to use for editing .hgrc? And how would I configure emacs to use that mode automatically when I'm editing .hgrc?
Learned so far from answers:
conf-mode is the mode I want, and there are various ways to configure emacs to use it for editing .hgrc.
I added
(add-to-list 'auto-mode-alist '("/\\.[^/]*rc" . conf-mode) t)
to my .emacs.el, so
my emacs opens all RC files (including .hgrc) in Conf[Unix] mode.
The reason for the 3rd argument to add-to-list is that the default mode for run control files is conf-mode unless a prior setting overrides it.
Visit .hgrc, switch to Conf Mode with M-x conf-mode, and then type M-x add-file-local-variable-prop-line RET mode RET conf-mode.
This adds a special comment at the beginning of your .hgrc, which tells Emacs to use conf-mode for this file:
# -*- mode: conf; -*-
[extensions]
hgext.color =
# …
I encountered strange behaviour of expand-file-name function on windows during installation of last cedet using el-get. The issue is related to generation of autoloads.
The autoload.el on last emacs 24.1.50 contains the following function:
(defun autoload-generated-file ()
(expand-file-name generated-autoload-file
;; File-local settings of generated-autoload-file should
;; be interpreted relative to the file's location,
;; of course.
(if (not (local-variable-p 'generated-autoload-file))
(expand-file-name "lisp" source-directory))))
In my case generated-autoload-file is:
"/home/ngulyamov/.emacs.d/el-get/cedet/lisp/cedet/srecode/loaddefs.el"
as I have $HOME$ environment variable pointed to C:/home/ngulyamov. In this case above function returns:
"d:/home/ngulyamov/.emacs.d/el-get/cedet/lisp/cedet/srecode/loaddefs.el"
due to source-directory contains:
"d:/devel/emacs/emacs-bzr/trunk_jenkins/".
As you can see it changes drive letter from C: to D:.
At the same time on emacs 23.3 this function returns semi-correct value as source-directory contains value:
"c:/Users/Sean/Downloads/emacs-23.3/".
According to expand-file-name function description:
(expand-file-name NAME &optional DEFAULT-DIRECTORY)
Convert filename NAME to absolute, and canonicalize it.
Second arg DEFAULT-DIRECTORY is directory to start with if NAME is relative
(does not start with slash or tilde); if DEFAULT-DIRECTORY is nil or missing,
the current buffer's value of `default-directory' is used.
The paths on Windows never start from slash or tilde.
Now my questions:
1. Does expand-file-name function behaviour correct on Windows?
2. Why source-directory contains value of developers paths?
Could we consider expand-file-name as buggy on windows? Or it is just wrongly used in autoload.el?
Thank you in advance.
Finally I figured out the reason. The issue is coming from Makefile of cedet which uses $(abspath) functionality of make 3.8. The cygwin version of make in this case returns UNIX way of path, i.e. /home/ngulyamov/... which then replaces by source-directory root in autoload by d:/home/ngulyamov/.... The GnuWin32 version of make works correctly but by strange reason I have the following issue:
C:\home\ngulyamov\.emacs.d\el-get\cedet>\gnuwin32\bin\make all
Removing loaddefs.el files from subprojects.
Generating autoloads.
make[1]: Entering directory `C:/home/ngulyamov/.emacs.d/el-get/cedet/lisp/cedet'
> autoloads
Wrote C:/home/ngulyamov/.emacs.d/el-get/cedet/lisp/cedet/loaddefs.el
Loading vc-bzr...
Generating autoloads for C:/home/ngulyamov/.emacs.d/el-get/cedet/lisp/cedet/cedet-android.el...
Memory exhausted--use C-x s then exit and restart Emacs
make[1]: *** [autoloads] Error 127
So dirty fix is specifying source-directory in autoload.el itself like:
(setq-default source-directory "C:/home/ngulyamov/.emacs.d/")
Anyway, why source-directory is pointing to developer's computer path is remaining open.
So (let us not concern ourselves with why) I have a .emacs file which is called dotemacs, and a .bashrc file which is called dotbashrc.
When I load up dotemacs, I get no syntax highlighing (amongst other things). If I do M-x lisp-mode then all is well.
Without changing the name of the file, how do I get emacs to recognise automatically that dotemacs is a lisp file and go into lisp-mode? Similarly for bash scripts, and indeed any other type of file with the wrong (or no) extension.
You can put this at the top of the dotemacs file:
; -*- mode: lisp -*-
causing it to start elisp-mode when you load the file.
For shell scripts, putting a #!/bin/bash (for whichever shell you are using) is enough to turn on the correct mode. Or otherwise put this at the top of the file:
# -*- mode: sh -*-
I like the answer above, but here is another way you could do it :)
Add the following line to your .emacs
(add-to-list 'auto-mode-alist '(".emacs" . lisp-mode))