emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/clojure-mode 76b6df0f39 1/2: [Fix #608] Fix alignment issu


From: ELPA Syncer
Subject: [nongnu] elpa/clojure-mode 76b6df0f39 1/2: [Fix #608] Fix alignment issue involving margin comments.
Date: Tue, 22 Feb 2022 03:58:02 -0500 (EST)

branch: elpa/clojure-mode
commit 76b6df0f398678570cf70bcf809d2c3af2ff7f64
Author: Sam Waggoner <samwagg0583@gmail.com>
Commit: Bozhidar Batsov <bozhidar@batsov.dev>

    [Fix #608] Fix alignment issue involving margin comments.
    
    Alignment wasn't working properly when nested, multi-line sexps were 
followed by margin comments.
---
 CHANGELOG.md                          |  1 +
 clojure-mode.el                       |  6 +++++-
 test/clojure-mode-indentation-test.el | 37 +++++++++++++++++++++++++++++++++++
 3 files changed, 43 insertions(+), 1 deletion(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0a08b4b55c..681623ecd9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -24,6 +24,7 @@
 
 * [#588](https://github.com/clojure-emacs/clojure-mode/pull/588): Fix 
font-lock for character literals.
 * Stop `clojure-sort-ns` from calling `redisplay`.
+* [#608](https://github.com/clojure-emacs/clojure-mode/issues/608) Fix 
alignment issue involving margin comments at the end of nested forms.
 
 ### Changes
 
diff --git a/clojure-mode.el b/clojure-mode.el
index 62b5b36dc7..fd03c37f27 100644
--- a/clojure-mode.el
+++ b/clojure-mode.el
@@ -1252,6 +1252,9 @@ Place point as in `clojure--position-for-alignment'."
 
 (defun clojure--search-whitespace-after-next-sexp (&optional bound _noerror)
   "Move point after all whitespace after the next sexp.
+Additionally, move past a comment if one exists (this is only
+possible when the end of the sexp coincides with the end of a
+line).
 
 Set the match data group 1 to be this region of whitespace and
 return point.
@@ -1260,7 +1263,8 @@ BOUND is bounds the whitespace search."
   (unwind-protect
       (ignore-errors
         (clojure-forward-logical-sexp 1)
-        (search-forward-regexp "\\([,\s\t]*\\)" bound)
+        ;; Move past any whitespace or comment.
+        (search-forward-regexp "\\([,\s\t]*\\)\\(;+.*\\)?" bound)
         (pcase (syntax-after (point))
           ;; End-of-line, try again on next line.
           (`(12) (clojure--search-whitespace-after-next-sexp bound))
diff --git a/test/clojure-mode-indentation-test.el 
b/test/clojure-mode-indentation-test.el
index 9c12b9a909..91a9dcb2b0 100644
--- a/test/clojure-mode-indentation-test.el
+++ b/test/clojure-mode-indentation-test.el
@@ -705,6 +705,43 @@ x
     "#?@(:clj  [2]
     :cljs [2])")
 
+  (when-aligning-it "should handle sexps broken up by line comments"
+    "
+(let [x  1
+      ;; comment
+      xx 1]
+  xx)"
+
+    "
+{:x   1
+ ;; comment
+ :xxx 2}"
+
+    "
+(case x
+  :aa 1
+  ;; comment
+  :a  2)")
+ 
+  (when-aligning-it "should work correctly when margin comments appear after 
nested, multi-line, non-terminal sexps"
+    "
+(let [x  {:a 1
+          :b 2} ; comment
+      xx 3]
+  x)"
+
+    "
+{:aa {:b  1
+      :cc 2} ;; comment
+ :a  1}}"
+
+    "
+(case x
+  :a  (let [a  1
+            aa (+ a 1)]
+       aa); comment
+  :aa 2)")
+
   (it "should handle improperly indented content"
     (let ((content "(let [a-long-name 10\nb 20])")
           (aligned-content "(let [a-long-name 10\n      b           20])"))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]