Skip to content

Instantly share code, notes, and snippets.

@bowbow99
Created June 11, 2010 17:03
Show Gist options
  • Save bowbow99/434756 to your computer and use it in GitHub Desktop.
Save bowbow99/434756 to your computer and use it in GitHub Desktop.
;;; restart-case の再起動部分を handler-case 風にする calc-lisp-indent
(in-package :editor)
(setf (get 'handler-case 'lisp-indent-handler-macro)
(lambda (sym)
(or (subtypep sym 'condition) (consp sym)))
(get 'restart-case 'lisp-indent-handler-macro)
(lambda (sym) t))
(defun ed::calc-lisp-indent (opoint)
(protect-match-data
(let ((begin-paren (and lisp-indent-close-paren
(looking-at "[ \t]*)"))))
(goto-bol)
(when (and (looking-at "\\s(")
(forward-char -1))
(skip-white-backward)
(forward-char 1))
(or (up-list -1 t)
(return-from calc-lisp-indent 0))
(cond
(begin-paren
(+ (current-column) lisp-paren-imaginary-offset))
((or (looking-at "#")
(and (not (looking-back "#'"))
(looking-back "'")))
(+ (current-column) 1))
(t
(let ((package (or (and (stringp *buffer-package*)
(find-package *buffer-package*))
*package*)))
(when (save-excursion
(when (and (up-list -1 t)
(looking-for "((")
(up-list -1 t))
(forward-char 1)
(multiple-value-bind (symbol found)
(calc-lisp-indent-current-symbol package)
(and found (get symbol 'lisp-indent-flet)))))
(return-from calc-lisp-indent
(+ (current-column) *lisp-body-indention*)))
(let ((column (progn
(forward-char 1)
(current-column))))
(multiple-value-bind (symbol found pkg-marker-p)
(calc-lisp-indent-current-symbol package)
(when pkg-marker-p
(return-from calc-lisp-indent column))
(let ((method (when found
(or (save-excursion
(when (and (up-list -1 t)
(forward-list -1 t) ;(forward-sexp -1 t)
(up-list -1 t)
(forward-char 1))
(multiple-value-bind (symbol-1 found-1)
(calc-lisp-indent-current-symbol package)
(let ((method (when found-1
(get symbol-1 'lisp-indent-handler-macro))))
(when method
(funcall method symbol))))))
(get symbol 'lisp-indent-hook)
(let* ((args (cadr (macro-function symbol)))
(before (when (find &body args)
(subseq args 0 (position &body args)))))
(when before
(while (find (car before) '(&whole &environment))
(setq before (subseq before 2)))
(length before)))))))
(cond ((numberp method)
(let ((count -1))
(while (< (point) opoint)
(skip-white-forward)
(setq count (+ count 1))
(or (forward-sexp 1 t)
(return)))
(+ column -1 (if (< count method)
(* *lisp-body-indent* 2)
*lisp-body-indent*))))
(method
(+ column -1 *lisp-body-indention*))
(t
(skip-chars-forward " \t")
(if (or (eolp) (looking-for ";"))
(if *lisp-indent-offset*
(+ column *lisp-indent-offset*)
column)
(current-column)))))))))))))
@bowbow99
Copy link
Author

  • &body を含まないマクロのインデントがおかしかったのを修正

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment