[comp.emacs] emacs-lisp-mode indentation

kpc00@JUTS.ccc.amdahl.com (kpc) (09/05/90)

Question about GNU 18.55 emacs-lisp-mode indentation:

If one wants to use this indentation style:

(defun factorial (n)

  "..."

  (cond
    ((zerop n) 1)
    (t (* n (factorial (- n 1))))
  )
)

which puts closing parentheses under their matches and indents by a
fixed amount, in place of emacs-lisp-mode's:

(defun factorial (n)
  
  "..."
  
  (cond
   ((zerop n) 1)
   (t (* n (factorial (- n 1))))
   )
  )

is there a way out there to implement it?
--
Neither representing any company nor, necessarily, myself.

gaynor@sparky.rutgers.edu (Silver) (09/05/90)

kpc00@JUTS.ccc.amdahl.com (kpc) requests support for having close parens line
up under their match.  Personally, I'm not real fond of this style for reasons
better left to comp.lang groups.  But in the spirit of bipartisanship, I offer
the following.  Warning.  This is two-minute code, I spent as much time editing
this message as I did writing and testing the function!

;; Bind me to keys which insert closing parens, like \), \], \}, ...
(defun insert-close-paren-indent-under-match ()
"If on a white line, indent under match.
Self-insert regardless.
Returns nothing."
  (interactive)
  (if (save-excursion (beginning-of-line)
                      (looking-at "^[\ \t]*$"))
    (progn (delete-region (match-beginning 0) (point))
           (insert-char last-input-char 1)
           (let ((start (scan-sexps (point) -1)))
             (save-excursion (beginning-of-line)
                             (indent-to (save-excursion (goto-char start)
                                                        (current-column)))))
           (blink-matching-open))
    (call-interactively 'self-insert-command))))

Regards, [Ag]

carroll@m.cs.uiuc.edu (09/06/90)

/* Written  2:08 am  Sep  5, 1990 by gaynor@sparky.rutgers.edu in m.cs.uiuc.edu:comp.emacs */
/* ---------- "Re: emacs-lisp-mode indentation" ---------- */
kpc00@JUTS.ccc.amdahl.com (kpc) requests support for having close parens line
up under their match.
/* End of text from m.cs.uiuc.edu:comp.emacs */
I have a more complete version that does this, if any one's interested. It's
also included in the epoch distribution, and has code to convert from that form
to "standard" form.