[slime-cvs] CVS slime/contrib
CVS User nsiivola
nsiivola at common-lisp.net
Fri Dec 30 17:10:13 UTC 2011
Update of /project/slime/cvsroot/slime/contrib
In directory tiger.common-lisp.net:/tmp/cvs-serv19553/contrib
Modified Files:
ChangeLog slime-cl-indent-test.txt slime-cl-indent.el
Log Message:
slime-indentation: better treatment of feature expressions
Particularly interaction with keyword arguments.
--- /project/slime/cvsroot/slime/contrib/ChangeLog 2011/12/24 17:45:24 1.528
+++ /project/slime/cvsroot/slime/contrib/ChangeLog 2011/12/30 17:10:13 1.529
@@ -1,3 +1,22 @@
+2011-12-30 Nikodemus Siivola <nikodemus at random-state.net>
+
+ * slime-cl-indent.el (common-lisp-looking-at-keyword): New function. Looks
+ past #+foo expressions.
+ (common-lisp-backward-keyword-argument): New function. Semi-aware
+ of #+foo expressions.
+ (common-lisp-indent-function-1):
+ 1. Use `common-lisp-indent-parse-state-start'.
+ 2. Move #+/- cleavernes outside the cond: it is always a default, and shouldn't
+ trump other indentation logic. Also make it use the column of the first feature
+ expression, not the last.
+ 3. Make keyword alignment somewhat feature-expression aware.
+ 4. Make heuristics not force remaining forms to be indented at the same line.
+ (common-lisp-indent-test): Leave one leading whitespace on comment lines
+ when messing up indentation.
+
+ * slime-cl-indent-test.txt (tests 77-83): Tests for feature-expression
+ and keyword alignment interaction.
+
2011-12-24 Stas Boukarev <stassats at gmail.com>
* slime-tramp.el (slime-find-filename-translators): Don't signal
--- /project/slime/cvsroot/slime/contrib/slime-cl-indent-test.txt 2011/12/08 13:54:19 1.17
+++ /project/slime/cvsroot/slime/contrib/slime-cl-indent-test.txt 2011/12/30 17:10:13 1.18
@@ -827,3 +827,66 @@
(list foo opt1 opt2
rest)))
...)
+
+;;; Test: 77
+;;
+;; lisp-align-keywords-in-calls: t
+
+(foo *foo*
+ :bar t
+ :quux #+quux t
+ #-quux nil
+ :zot t)
+
+;;; Test: 78
+;;
+;; lisp-align-keywords-in-calls: t
+
+(foo *foo* :fii t
+ :bar t
+ :quux #+quux t
+ #+zot nil
+ :zot t)
+
+;;; Test: 79
+
+(foo #+quux :quux #+quux t
+ #-quux :zoo #-quux t)
+
+;;; Test: 80
+;;
+;; lisp-align-keywords-in-calls: t
+
+(foo *foo* :fii t
+ :bar t
+ #+quux :quux #+quux t
+ :zot t)
+
+;;; Test: 81
+;;
+;; lisp-align-keywords-in-calls: t
+
+(foo *foo* :fii t
+ :bar t
+ #+quux #+quux :quux t
+ :zot t)
+
+;;; Test: 82
+;;
+;; lisp-align-keywords-in-calls: t
+
+(foo *foo* :fii t
+ :bar t
+ #+quux
+ :quux #+quux t
+ :zot t)
+
+;;; Test: 83
+;;
+;; lisp-align-keywords-in-calls: t
+
+(foo *foo* :fii t
+ :bar t
+ #+quux #+quux
+ :quux t
+ :zot t)
--- /project/slime/cvsroot/slime/contrib/slime-cl-indent.el 2011/12/08 13:54:19 1.61
+++ /project/slime/cvsroot/slime/contrib/slime-cl-indent.el 2011/12/30 17:10:13 1.62
@@ -743,6 +743,34 @@
(unless (eql (elt string (- len i 1)) (char-before (- (point) i)))
(return nil)))))
+(defvar common-lisp-feature-expression-regexp "#!?\\(+\\|-\\)")
+
+;;; Semi-feature-expression aware keyword check.
+(defun common-lisp-looking-at-keyword ()
+ (or (looking-at ":")
+ (and (looking-at common-lisp-feature-expression-regexp)
+ (save-excursion
+ (forward-sexp)
+ (skip-chars-forward " \t\n")
+ (common-lisp-looking-at-keyword)))))
+
+;;; Semi-feature-expression aware backwards movement for keyword argument pairs.
+(defun common-lisp-backward-keyword-argument ()
+ (ignore-errors
+ (backward-sexp 2)
+ (when (looking-at common-lisp-feature-expression-regexp)
+ (cond ((ignore-errors
+ (save-excursion
+ (backward-sexp 2)
+ (looking-at common-lisp-feature-expression-regexp)))
+ (common-lisp-backward-keyword-argument))
+ ((ignore-errors
+ (save-excursion
+ (backward-sexp 1)
+ (looking-at ":")))
+ (backward-sexp))))
+ t))
+
(defun common-lisp-indent-function-1 (indent-point state)
;; If we're looking at a splice, move to the first comma.
(when (or (common-lisp-looking-back ",") (common-lisp-looking-back ",@"))
@@ -763,7 +791,7 @@
tentative-calculated
(last-point indent-point)
;; the position of the open-paren of the innermost containing list
- (containing-form-start (elt state 1))
+ (containing-form-start (common-lisp-indent-parse-state-start state))
;; the column of the above
sexp-column)
;; Move to start of innermost containing list
@@ -829,21 +857,32 @@
function)
(setq method '(&lambda &body)))))
+ ;; #+ and #- cleverness.
+ (save-excursion
+ (goto-char indent-point)
+ (backward-sexp)
+ (let ((indent (current-column)))
+ (when (or (looking-at common-lisp-feature-expression-regexp)
+ (ignore-errors
+ (backward-sexp)
+ (when (looking-at common-lisp-feature-expression-regexp)
+ (setq indent (current-column))
+ (let ((line (line-number-at-pos)))
+ (while (ignore-errors
+ (backward-sexp 2)
+ (and
+ (= line (line-number-at-pos))
+ (looking-at common-lisp-feature-expression-regexp)))
+ (setq indent (current-column))))
+ t)))
+ (setq calculated (list indent containing-form-start)))))
+
(cond ((and (or (eq (char-after (1- containing-sexp)) ?\')
(and (not lisp-backquote-indentation)
(eq (char-after (1- containing-sexp)) ?\`)))
(not (eq (char-after (- containing-sexp 2)) ?\#)))
;; No indentation for "'(...)" elements
(setq calculated (1+ sexp-column)))
- ((save-excursion
- (goto-char indent-point)
- (backward-sexp)
- (let ((re "#!?\\(+\\|-\\)"))
- (if (or (looking-at re)
- (ignore-errors
- (backward-sexp)
- (looking-at re)))
- (setq calculated (current-column))))))
((eq (char-after (1- containing-sexp)) ?\#)
;; "#(...)"
(setq calculated (1+ sexp-column)))
@@ -875,10 +914,11 @@
(save-excursion
(goto-char indent-point)
(back-to-indentation)
- (when (looking-at ":")
- (while (ignore-errors (backward-sexp 2) t)
- (when (looking-at ":")
- (setq calculated (current-column)))))))))
+ (when (common-lisp-looking-at-keyword)
+ (while (common-lisp-backward-keyword-argument)
+ (when (common-lisp-looking-at-keyword)
+ (setq calculated (list (current-column)
+ containing-form-start)))))))))
((integerp method)
;; convenient top-level hack.
;; (also compatible with lisp-indent-function)
@@ -926,11 +966,11 @@
(let ((one (current-column)))
(skip-chars-forward " \t")
(if (or (eolp) (looking-at ";"))
- one
+ (list one containing-form-start)
(forward-sexp 2)
(backward-sexp)
(unless (= p (point))
- (current-column)))))))))))
+ (list (current-column) containing-form-start)))))))))))
(defun common-lisp-indent-call-method (function method path state indent-point
@@ -1624,8 +1664,9 @@
(unless (looking-at "^$")
(case (random 2)
(0
- ;; Delete all leading whitespace.
- (while (looking-at " ") (delete-char 1)))
+ ;; Delete all leading whitespace -- except for comment lines.
+ (while (and (looking-at " ") (not (looking-at " ;")))
+ (delete-char 1)))
(1
;; Insert whitespace random.
(let ((n (1+ (random 24))))
@@ -1699,6 +1740,6 @@
;;; (common-lisp-run-indentation-tests t)
;;;
;;; Run specific test:
-;;; (common-lisp-run-indentation-tests 70)
+;;; (common-lisp-run-indentation-tests 77)
;;; cl-indent.el ends here
More information about the slime-cvs
mailing list