Commits

Anonymous committed d5fded3

making it so that code in comments between [ and ] gets indented the way code normally does

  • Participants
  • Parent commits 8ecba19

Comments (0)

Files changed (1)

elisp/contrib/tuareg/tuareg.el

 (defconst tuareg-sig-struct-regexp (tuareg-ro "sig" "struct"))
 (defconst tuareg-top-level-command-regexp
   (concat "#" (tuareg-ro "open" "load" "use")))
+
 (defun tuareg-compute-indent ()
   (save-excursion
     (cond
                  tuareg-comment-end-extra-indent))
           (+ (current-column) tuareg-comment-end-extra-indent)))
        (tuareg-indent-comments
-        (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)
-          ))
+        (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 ((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
+            ;; 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 [
+            (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))))))
        (t (current-column))))
      ((tuareg-in-literal-p)
       (current-column))