Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get emacs to indent other things like it indents define?

So Emacs is pretty good at editing Scheme/Racket/Lisp code. One good thing it does is when you type code like:

(define (make-position-table)
  (for/list ([i (in-range 256)])
            `()))

It does a very clever thing and indents the second line to two columns. Now the third line it does what it does with all lisp code and indents that to align all the arguments.

How do I customize Emacs so that it indents the third line as though I was introducing a new body. What I'd like is:

(define (make-position-table)
  (for/list ([i (in-range 256)])
    `()))

I'm guessing this is possible and that I just haven't figured out the arcane Emacs variable to set. Does anyone know how to do this?

like image 376
pknodle Avatar asked Nov 16 '10 23:11

pknodle


People also ask

How do I change emacs indent?

Emacs normally uses both tabs and spaces to indent lines. If you prefer, all indentation can be made from spaces only. To request this, set indent-tabs-mode to nil . This is a per-buffer variable; altering the variable affects only the current buffer, but there is a default value which you can change as well.

How do I indent multiple lines in Emacs?

Select multiply lines, then type C-u 8 C-x Tab , it will indent the region by 8 spaces.

What is the indent command?

The indent command fits as many words (separated by blanks, tabs, or new-lines) on a line as possible. Blank lines break paragraphs. A block comment is a comment that is not to the right of the code, and extends for more than one line.


2 Answers

You can add this to your .emacs file:

(put 'for/list 'scheme-indent-function 1)

See also a hacked version of scheme mode that does many more racket-isms.

like image 85
Eli Barzilay Avatar answered Nov 15 '22 09:11

Eli Barzilay


I believe (put 'for/list 'scheme-indent-function 'defun) should do what you want.

Repeat for other symbols. My .emacs includes

(mapc (lambda (sym) (put sym 'scheme-indent-function 'defun))
      (list 'for 'for/list 'for/and 'for/or
            'match 'case 'syntax-parse 'test-suite 'test-case
            'define-syntax-rule 'match-let 'match-let*))

from the days when I was dabbling in PLT Scheme.

like image 35
Porculus Avatar answered Nov 15 '22 10:11

Porculus