Emacs (lispbox) and autoindent

2006-10-24 13:05:04 PST

Tags: , , ,

For some reason emacs from lispbox doesn't auto indent code by default (and as it turns out, all emcas doesn't auto-indent). Ok. But more confusingly, it isn't trivial to turn it on. It's actually hard to find information even about how to turn it on. It took me a little time with google to finally find what I was looking for some I'll repost it here.

Edit: So this failed to do anything for emcas installed on my home Gentoo box
Edit2: Also it turns out that these instructions break the Lisp Top Level and now I can't evaluate anything in emacs/lispbox so I had to disable it for lispbox too.

This is a bit silly. It should not be this hard to get auto-indent and that finally 'succeeding' it shouldn't hose everything else. Lame.

If anyone knows a sane way to get emcas to auto indent code please leave a comment letting me know how.

To get emacs to auto indent lisp code, add the following to your .emacs file.

.emacs

(defun my-set-newline-and-indent()
    (local-set-key [return] 'newline-and-indent))

(add-hook 'lisp-mode-hook 'my-set-newline-and-indent)
(add-hook 'Lisp-mode-hook 'my-set-newline-and-indent)

For other languages add do similarly like:

(add-hook 'c++-mode-hook 'my-set-newline-and-indent)

That should do it. Except for lispbox because by default it's .bat file tells it not to load config files. So change

%EMACS% --no-init-file --no-site-file --eval=%TO_EVAL

to

%EMACS% --eval=%TO_EVAL

And put your .emacs file wherever the HOME variable is set to.

3 Responses to “Emacs (lispbox) and autoindent”

  1. Doesn’t emacs auto-detect that you’re editing source code, and enable the correct indenting style for that programming language by default? Vim does. :) *smug*

  2. Ha, indeed. But I’m learning emacs so I can use lisp. And it does smart tabbing. When ever you are on a line at hit ‘tab’ it will go to the right spot. So it’s one extra key a line for now, not so bad. But Should be better.

  3. Use C-j (usually bound to “newlline-an-indent”) instead of Return
    (usually bound to “newline”) if you want Emacs to auto-indent. If you
    already are on a blank line, hit “TAB” or just type the line and emacs
    will indent the line when you press C-j or Return to go to the next
    line.

Leave a Reply

Valid XHTML 1.0!
Valid CSS!
Mindstab.net is proudly powered by WordPress
Entries (RSS) and Comments (RSS).
20 queries. 0.432 seconds.