[slime-cvs] CVS slime/contrib

CVS User nsiivola nsiivola at common-lisp.net
Mon Oct 31 09:45:45 UTC 2011


Update of /project/slime/cvsroot/slime/contrib
In directory tiger.common-lisp.net:/tmp/cvs-serv11550/contrib

Modified Files:
	ChangeLog slime-cl-indent-test.txt slime-cl-indent.el 
Log Message:
slime-indent: improve indentation of comments in LOOPs


--- /project/slime/cvsroot/slime/contrib/ChangeLog	2011/10/31 09:44:59	1.501
+++ /project/slime/cvsroot/slime/contrib/ChangeLog	2011/10/31 09:45:45	1.502
@@ -1,5 +1,21 @@
 2011-10-31  Nikodemus Siivola  <nikodemus at random-state.net>
 
+	Improve indentation of comments inside LOOP.
+
+	* slime-cl-indent-test.txt: New tests 54-63.
+
+	* slime-cl-indent.el (common-lisp-loop-type): Deal with comments
+	at the start of the loop, add simple/split type.
+
+	* slime-cl-indent.el (lisp-indent-loop): Use
+	common-lisp-loop-part-indentation for simple loops regardless of
+	the value of lisp-loop-indent-subclauses.
+
+	* slime-cl-indent.el (common-lisp-loop-part-indentation): Handle the
+	new simple/split type, improve comment indentation logic.
+
+2011-10-31  Nikodemus Siivola  <nikodemus at random-state.net>
+
 	* slime-cl-indent.el (style "sbcl"): Indentation for !DEF-TYPE-TRANSLATOR.
 
 2011-10-29  Nikodemus Siivola  <nikodemus at random-state.net>
--- /project/slime/cvsroot/slime/contrib/slime-cl-indent-test.txt	2011/10/29 11:15:15	1.11
+++ /project/slime/cvsroot/slime/contrib/slime-cl-indent-test.txt	2011/10/31 09:45:45	1.12
@@ -580,3 +580,90 @@
               &allow-other-keys)
   (list opt1 opt2
         rest))
+
+;;; Test: 54
+;;
+
+(loop (foo)
+      ;; comment
+      (bar)
+      (quux))
+
+;;; Test: 55
+;;
+
+(loop ;; comment
+      (foo)
+      (bar))
+
+;;; Test: 56
+;;
+
+(loop
+  (foo)
+  ;; comment
+  (bar))
+
+
+;;; Test: 57
+;;
+
+(loop
+  ;; comment
+  (foo)
+  (bar))
+
+;;; Test: 58
+;;
+;; lisp-loop-indent-subclauses: t
+
+(loop ;; comment at toplevel of the loop
+      with foo = t
+      do (foo foo)
+         (foo))
+
+;;; Test: 59
+;;
+;; lisp-loop-indent-subclauses: nil
+
+(loop ;; comment at toplevel of the loop
+      with foo = t
+      do (foo foo)
+         (foo))
+
+;;; Test: 60
+;;
+;; lisp-loop-indent-subclauses: t
+
+(loop
+  ;; comment at toplevel of the loop
+  with foo = t
+  do (foo foo))
+
+;;; Test: 61
+;;
+;; lisp-loop-indent-subclauses: nil
+
+(loop
+  ;; comment at toplevel of the loop
+  with foo = t
+  do (foo foo)
+     (foo))
+
+;;; Test: 62
+;;
+;; lisp-loop-indent-subclauses: t
+
+(loop with foo = t
+      do (foo foo)
+         ;; comment inside clause
+         (bar))
+
+;;; Test: 63
+;;
+;; lisp-loop-indent-subclauses: nil
+
+(loop with foo = t
+      do (foo foo)
+         ;; comment inside clause
+         (bar))
--- /project/slime/cvsroot/slime/contrib/slime-cl-indent.el	2011/10/31 09:44:59	1.51
+++ /project/slime/cvsroot/slime/contrib/slime-cl-indent.el	2011/10/31 09:45:45	1.52
@@ -578,39 +578,54 @@
 
 (defun common-lisp-loop-type (loop-start)
   "Returns the type of the loop form at LOOP-START.
-Possible types are SIMPLE, EXTENDED, and EXTENDED/SPLIT.
-EXTENDED/SPLIT refers to extended loops whose body does
-not start on the same line as the opening parenthesis of
-the loop."
-  (condition-case ()
-      (save-excursion
-        (goto-char loop-start)
-        (let ((line (line-number-at-pos)))
-          (forward-char 1)
-          (forward-sexp 2)
-          (backward-sexp 1)
-          (if (looking-at "\\sw")
-              (if (= line (line-number-at-pos))
-                  'extended
-                'extended/split)
-            'simple)))
-    (error 'simple)))
+Possible types are SIMPLE, SIMPLE/SPLIT, EXTENDED, and EXTENDED/SPLIT. */SPLIT
+refers to extended loops whose body does not start on the same line as the
+opening parenthesis of the loop."
+  (let (comment-split)
+    (condition-case ()
+        (save-excursion
+          (goto-char loop-start)
+          (let ((line (line-number-at-pos))
+                (maybe-split t))
+            (forward-char 1)
+            (forward-sexp 1)
+            (save-excursion
+              (when (looking-at "\\s-*\\\n*;")
+                (search-forward ";")
+                (backward-char 1)
+                (if (= line (line-number-at-pos))
+                    (setq maybe-split nil)
+                  (setq comment-split t))))
+            (forward-sexp 1)
+            (backward-sexp 1)
+            (if (looking-at "\\sw")
+                (if (or (not maybe-split) (= line (line-number-at-pos)))
+                    'extended
+                  'extended/split)
+              (if (or (not maybe-split) (= line (line-number-at-pos)))
+                  'simple
+                'simple/split))))
+      (error
+       (if comment-split
+           'simple/split
+         'simple)))))
 
-(defun common-lisp-loop-part-indentation (indent-point state)
+(defun common-lisp-loop-part-indentation (indent-point state type)
   "Compute the indentation of loop form constituents."
   (let* ((loop-start (elt state 1))
-         (type (common-lisp-loop-type loop-start))
          (loop-indentation (save-excursion
                              (goto-char loop-start)
-                             (if (eq 'extended/split type)
+                             (if (eq type 'extended/split)
                                  (- (current-column) 4)
                                (current-column))))
          (indent nil)
-         (re "\\(:?\\sw+\\|;\\|)\\|\n\\)"))
+         (re "\\(:?\\sw+\\|)\\|\n\\)"))
     (goto-char indent-point)
     (back-to-indentation)
-    (cond ((eq 'simple type)
+    (cond ((eq type 'simple/split)
            (+ loop-indentation lisp-simple-loop-indentation))
+          ((eq type 'simple)
+           (+ loop-indentation 6))
           ;; We are already in a body, with forms in it.
           ((and (not (looking-at re))
                 (save-excursion
@@ -621,8 +636,8 @@
                              (looking-at common-lisp-indent-body-introducing-loop-macro-keyword))
                     t)))
            (list indent loop-start))
-          ;; Keyword-style
-          ((or lisp-loop-indent-forms-like-keywords (looking-at re))
+          ;; Keyword-style or comment outside body
+          ((or lisp-loop-indent-forms-like-keywords (looking-at re) (looking-at ";"))
            (list (+ loop-indentation 6) loop-start))
           ;; Form-style
           (t
@@ -1213,13 +1228,15 @@
        (error (+ sexp-column lisp-body-indent)))))
 
 (defun lisp-indent-loop (path state indent-point sexp-column normal-indent)
-  (cond ((not (null (cdr path)))
-         normal-indent)
-        (lisp-loop-indent-subclauses
-         (list (common-lisp-indent-loop-macro-1 state indent-point)
-               (common-lisp-indent-parse-state-start state)))
-        (t
-         (common-lisp-loop-part-indentation indent-point state))))
+  (if (cdr path)
+      normal-indent
+    (let* ((loop-start (elt state 1))
+           (type (common-lisp-loop-type loop-start)))
+      (cond ((and lisp-loop-indent-subclauses (member type '(extended extended/split)))
+             (list (common-lisp-indent-loop-macro-1 state indent-point)
+                   (common-lisp-indent-parse-state-start state)))
+            (t
+             (common-lisp-loop-part-indentation indent-point state type))))))
 
 ;;;; LOOP indentation, the complex version -- handles subclause indentation
 





More information about the slime-cvs mailing list