Emacs change file extension - mode association

后端 未结 3 1468
难免孤独
难免孤独 2020-12-16 18:32

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-mo         


        
相关标签:
3条回答
  • 2020-12-16 19:04

    Use this.

    ;; octave-mode
    (autoload 'octave-mode "octave-mode" "Loding octave-mode" t)
    (add-to-list 'auto-mode-alist '("\\.m\\'" . octave-mode))
    
    0 讨论(0)
  • 2020-12-16 19:06

    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)

    0 讨论(0)
  • 2020-12-16 19:15

    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)
    
    0 讨论(0)
提交回复
热议问题