1

I'm trying to install lua-mode into emacs for windows but nothing seems to be working. I've set my HOME environment variable. I've added init.el and lua-mode.el to the HOME\.emacs.d directory. Then I've added the following code to init.el:

(autoload 'lua-mode "lua-mode" "Lua editing mode." t)
(add-to-list 'auto-mode-alist '("\\.lua$" . lua-mode))
(add-to-list 'interpreter-mode-alist '("lua" . lua-mode))

(add-hook 'lua-mode-hook 'turn-on-font-lock)

Nothing is working when I start up emacs and load a .lua file. The major mode is always set to fundamental and there are no other options to change to. What can I do to get this working?

Graham
  • 5,488
  • 13
  • 57
  • 92

3 Answers3

2

maybe you need something like (require 'lua-mode) or something like that? Also make sure that the lua-mode file is in a directory in your load-path variable. Something like this before anything else:

(add-to-list 'load-path "/home/dervin/.emacs.d/site-lisp/")

or wherever, and then the require-

Dervin Thunk
  • 19,515
  • 28
  • 127
  • 217
  • Its almost like emacs isn't even seeing my `init.el` file. Even though I've set HOME and all that. I tried adding that line of code to it pointing to the right folder but it didn't work. I don't know what to do now. – Graham Apr 09 '11 at 18:42
  • 1
    is this Windows? If so, fire up Emacs, write `M-x pwd` (this will give you the home directory), save your init.el there (or better yet, your .emacs). Another thing you can do: fire up Emacs, load init.el (`C-x C-f`) and then write `M-x eval-buffer` and see what happens. A third thing you can do is start emacs from console and pass the `-u=` (or `--user=`) and see what happens. – Dervin Thunk Apr 09 '11 at 20:04
2

The lines look OK. This can depend on a number of things:

  • The init.el file is not loaded at startup. In face, this is a non-standard name when it comes to Emacs. Emacs tries to load the files ~/.emacs, ~/emacs.el, and ~/.emacs.d/init.el in order, and will load the first one found. To verify that you file has loaded, you could add (message "Loading my init.el") inside it and check the *Messages* buffer.
  • The directory where you stored the file lua-mode.el is not in the load path. In fact, the ~/.emacs.d directory is not part of the standard load path.
Lindydancer
  • 25,428
  • 4
  • 49
  • 68
  • It's not true that `init.el` is a non-standard name. Using a `.emacs.d` directory containing an `init.el` is the modern way to keep all of emacs' config files in one directory. – sanityinc Apr 11 '11 at 12:26
  • Oh, I didn't know that. I updated the answer accordingly. Thanks! – Lindydancer Apr 11 '11 at 13:48
  • Following this scheme, you can check your entire emacs config into a VC system, like this: http://github.com/purcell/emacs.d/ – sanityinc Apr 11 '11 at 16:20
2

It's possible that your init.el is never read, because you also have a .emacs file (or .emacs.el) in your $HOME directory. You can choose between those three alternatives for Emacs' init file, but only one of them will be read. Traditionally, that's .emacs but some operating systems have problems with that filename syntax.

Also, make sure that you placed init.el in your actual home directory, not a directory called "HOME" or something.

See here for further details on Emacs init files and here for more info on home directories.


If you're not keen on using the init.el variant, here are instruction that should make lua-mode work for you using .emacs:

  1. Start a new Emacs
  2. Type C-x C-f ~/.emacs <ENTER> (C-x means press CTRL, hold it, press x, release - same for C-f)
  3. Insert the following lines:

    (add-to-list 'load-path "/path/to/lua-mode-dir")
    
    (autoload 'lua-mode "lua-mode" "Lua editing mode." t)
    (add-to-list 'auto-mode-alist '("\\.lua$" . lua-mode))
    (add-to-list 'interpreter-mode-alist '("lua" . lua-mode))
    
    (add-hook 'lua-mode-hook 'turn-on-font-lock)
    
  4. Type C-x C-s to save the buffer to file

  5. Type C-x C-c to close Emacs

Note that in step 3 you have to adjust "/path/to/lua-mode-dir" with the actual path to the directory where you saved the file lua-mode.el on your hard disk.

Thomas
  • 17,016
  • 4
  • 46
  • 70
  • @cschol: It's only one piece in the mosaic. If the missing load-path was the cause of this, the OP would have gotten an error message when opening a .lua file. But since he didn't get an error, it seems that the init.el is never actually loaded. – Thomas Apr 11 '11 at 14:57