X-Git-Url: https://git.distorted.org.uk/~mdw/profile/blobdiff_plain/5432b9cdaf11453dd6ad5e3dc05f2058230d9e40..c36efcdc0b2d92b02fd7224d4fc53cf5a7cb74e3:/el/dot-emacs.el diff --git a/el/dot-emacs.el b/el/dot-emacs.el index c53beff..fc3c13f 100644 --- a/el/dot-emacs.el +++ b/el/dot-emacs.el @@ -4265,10 +4265,6 @@ that character only to be normal punctuation.") (make-local-variable 'lisp-indent-function) (setq lisp-indent-function 'common-lisp-indent-function)) -(setq-default lisp-simple-loop-indentation 2 - lisp-loop-keyword-indentation 6 - lisp-loop-forms-indentation 6) - (defmacro mdw-advise-hyperspec-lookup (func args) `(defadvice ,func (around mdw-browse-w3m ,args activate compile) (if (fboundp 'w3m) @@ -4308,6 +4304,84 @@ that character only to be normal punctuation.") (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" '(0 mdw-punct-face))))) +;; Special indentation. + +(defvar mdw-lisp-loop-default-indent 2) + +(setq lisp-simple-loop-indentation 0 + lisp-loop-keyword-indentation 0 + lisp-loop-forms-indentation 2 + lisp-lambda-list-keyword-parameter-alignment t) + +(defun mdw-indent-funcall (path state indent-point sexp-column normal-indent) + "Indent `funcall' more usefully. +Essentially, treat `funcall foo' as a function name, and align the arguments +to `foo'." + (and (null (cdr path)) + (save-excursion + (goto-char (cadr state)) + (forward-char 1) + (let ((start-line (line-number-at-pos))) + (and (condition-case nil (progn (forward-sexp 3) t) + (scan-error nil)) + (progn + (forward-sexp -1) + (and (= start-line (line-number-at-pos)) + (current-column)))))))) +(put 'funcall 'common-lisp-indent-function 'mdw-indent-funcall) + +(defadvice common-lisp-loop-part-indentation + (around mdw-fix-loop-indentation (indent-point state) activate compile) + "Improve `loop' indentation. +If the first subform is on the same line as the `loop' keyword, then +align the other subforms beneath it. Otherwise, indent them +`mdw-lisp-loop-default-indent' columns in from the opening parenthesis." + + (let* ((loop-indentation (save-excursion + (goto-char (elt state 1)) + (current-column)))) + + ;; Don't really care about this. + (when (and (eq lisp-indent-backquote-substitution-mode 'corrected)) + (save-excursion + (goto-char (elt state 1)) + (cl-incf loop-indentation + (cond ((eq (char-before) ?,) -1) + ((and (eq (char-before) ?@) + (progn (backward-char) + (eq (char-before) ?,))) + -2) + (t 0))))) + + ;; If the first loop item is on the same line as the `loop' itself then + ;; use that as the baseline. Otherwise advance by the default indent. + (goto-char (cadr state)) + (forward-char 1) + (let ((baseline-indent + (if (= (line-number-at-pos) + (if (condition-case nil (progn (forward-sexp 2) t) + (scan-error nil)) + (progn (forward-sexp -1) (line-number-at-pos)) + -1)) + (current-column) + (+ loop-indentation mdw-lisp-loop-default-indent)))) + + (goto-char indent-point) + (beginning-of-line) + + (setq ad-return-value + (list + (cond ((not (lisp-extended-loop-p (elt state 1))) + (+ baseline-indent lisp-simple-loop-indentation)) + ((looking-at "^\\s-*\\(:?\\sw+\\|;\\)") + (+ baseline-indent lisp-loop-keyword-indentation)) + (t + (+ baseline-indent lisp-loop-forms-indentation))) + + ;; Tell the caller that the next line needs recomputation, even + ;; though it doesn't start a sexp. + loop-indentation))))) + ;; SLIME setup. (defvar mdw-friendly-name "[mdw]"