Emacs change file extension - mode association

风格不统一 提交于 2019-11-27 22:16:33

问题


My Emacs opens .m files in ObjC mode. However I want to open them in Octave mode. I have already added to the .emacs file:

(autoload 'octave-mode "octave-mod" nil t)
(setq auto-mode-alist (cons '("\\.m$" . octave-mode) auto-mode-alist))

What else should I do? I do have Octave mode installed.


回答1:


Fortunately everything is working now and unfortunately I don't remember how I fixed it :) Maybe there was an error in my .emacs earlier. This is the more correct code:

(add-to-list 'auto-mode-alist '("\\.m$" . octave-mode))

Autoloading is unneeded in recent versions; if you do need to enable it, note that "octave-mode" is not a typo.

(autoload 'octave-mode "octave-mod" nil t)



回答2:


Use this.

;; octave-mode
(autoload 'octave-mode "octave-mode" "Loding octave-mode" t)
(add-to-list 'auto-mode-alist '("\\.m\\'" . octave-mode))



回答3:


Just ran into this exact problem. Your statement is correct, but your .emacs file probably isn't loading up correctly. Emacs searches the "HOME" variable to load up preferences, lisp code etc.

To see what your HOME variable is:

Open scratch buffer (this is a "play place" to try things out):

C-x C-b *scratch* <RET>

Evaluate this expression by typing it, then putting the cursor to the right, then hitting C-x C-e

insert (getenv "HOME")

Emacs will display your home path at the bottom (mine defaulted to ...Documents and Settings\UserName) I haven't worked out a good way to change it, but you're supposed to be able to simply add HOME as an environment variable (that didn't work for me).

It's also talked about a bit more over here: http://www.gnu.org/software/emacs/manual/html_node/emacs/Windows-HOME.html

Also remember that the file has to be ".emacs" and not myConfig.emacs or something of the like. Use bash command ren to rename the file (windows explorer won't let you have nameless files)



来源:https://stackoverflow.com/questions/14941995/emacs-change-file-extension-mode-association

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!