Commits

Peter Szilagyi committed 35ae091

Tuareg indentation: Added {[ ]} and {v v} support to tuareg-compute-indent.

  • Participants
  • Parent commits c2fb94b

Comments (0)

Files changed (1)

File elisp/contrib/tuareg/tuareg.el

                  tuareg-comment-end-extra-indent))
           (+ (current-column) tuareg-comment-end-extra-indent)))
        (tuareg-indent-comments
-        (let* ((comment-begin (save-excursion (tuareg-beginning-of-literal-or-comment-fast)))
-               (code-in-comment-begin (save-excursion (re-search-backward "^[ \t]*\\[+[ \t]*$" comment-begin t)))
-               (code-in-comment-end   (save-excursion (re-search-backward "^[ \t]*\\]+[ \t]*$" code-in-comment-begin t))))
-          (if (not (and code-in-comment-begin (not code-in-comment-end))) ; not in code?
+        (let* ((comment-begin (save-excursion
+                                (tuareg-beginning-of-literal-or-comment-fast)))
+               block-column
+               block-verbatim-p
+               block-end-regexp
+               (block-begin
+                (save-excursion
+                  ;; The delimiter doesn't necessarily have to be on a
+                  ;; line by itself, but it does need to end the line.
+                  (when (re-search-backward "[^{]\\({[[v]\\|\\[\\)[ \t]*$"
+                                            comment-begin
+                                            t)
+                    (forward-char)
+                    (setq block-column (+ (current-column) 2))
+                    (setq block-verbatim-p (looking-at "{v"))
+                    (setq block-end-regexp (cond ((looking-at "{\\[") "^[ \t]*\\]}[^}]")
+                                                 (block-verbatim-p "^[ \t]*v}[^}]")
+                                                 (t "^[ \t]*\\][^}]")))
+                    (forward-line)
+                    (point))))
+               (block-end (when block-end-regexp
+                            (save-excursion
+                              ;; If you're pointing at the delimiter,
+                              ;; you're really outside the block.
+                              (forward-line)
+                              (re-search-backward block-end-regexp block-begin t)))))
+          (if (not (and block-begin (not block-end))) ; not in block?
               (let ((star (and (tuareg-leading-star-p)
                                (looking-at "\\*"))))
                 (tuareg-beginning-of-literal-or-comment-fast)
                 (if star (re-search-forward "(") (re-search-forward "(\\*+[ \t]*"))
-                (current-column)
-                )
-            ;; CR cfalls: Small bug: the first statement will be
+                (current-column))
+            ;; XCR cfalls: Small bug: the first statement will be
             ;; indented too much unless you start the code region with
             ;; ;; because it sees the [ as starting a list.  Also
             ;; should support {[ in addition to just [
+            ;;
+            ;; pszilagyi: I fixed the first with more narrowing
+            ;; (inside the delimiters) and distinguishing the the
+            ;; first line.  Fixed the second, and added {v
             (save-restriction ; add code-based indentation using narrow-to-region
-              (progn
-                (narrow-to-region code-in-comment-begin (save-excursion (progn (forward-line) (point))))
-                (tuareg-compute-indent))))))
+              (narrow-to-region block-begin (save-excursion (forward-line)
+                                                            (point)))
+              ;; CR pszilagyi: An initial blank line in the block will
+              ;; effectively reset the indentation column to zero.
+              (cond (block-verbatim-p (current-column))
+                    ((= (line-number-at-pos) 1) block-column)
+                    (t (tuareg-compute-indent)))))))
        (t (current-column))))
      ((tuareg-in-literal-p)
       (current-column))