Emacs comes with
M-( bound to
M-) runs the command
‘move-past-close-and-reindent’. These commands are very useful in Emacs for writing Lisp. Using them takes some getting used to. The binding of
M-( also appears in other modes, including CcMode.
As an example, consider having to type the definition for the Fibonacci number in Emacs Lisp.
(defun fib (n) (if (< n 2) n (+ (fib (- n 1)) (fib (- n 2)))))
This could be done with the commands
C-j (assuming you are typing the example in an emacs lisp mode buffer, not the scratch buffer where
C-j does something different). see AutoIndentation). (Users of paredit should type
( instead of
M-() They will insert the 81 characters properly indented in just 50 keys (63 finger presses when considering chords).
Here are those keys pretty-printed (see EmacsKeyNotation):
M-( defun SPC fib M-( n M-) M-( if M-( < SPC n SPC 2 M-) n C-j M-( + M-( fib M-( - SPC n SPC 1 M-) M-) M-( fib M-( - SPC n SPC 2 C-M-e
Here they are as a listing (as seen in the
*Edit Macro* buffer of KeyboardMacros):
(global-set-key "\M-'" 'insert-quotations) (global-set-key "\M-\"" 'insert-quotes) (global-set-key (kbd "C-'") 'insert-backquote) (defun insert-quotations (&optional arg) "Enclose following ARG sexps in quotation marks. Leave point after open-paren." (interactive "*P") (insert-pair arg ?\' ?\')) (defun insert-quotes (&optional arg) "Enclose following ARG sexps in quotes. Leave point after open-quote." (interactive "*P") (insert-pair arg ?\" ?\")) (defun insert-backquote (&optional arg) "Enclose following ARG sexps in quotations with backquote. Leave point after open-quotation." (interactive "*P") (insert-pair arg ?\` ?\'))