[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/clojure-mode f5b85cac39: Fix clojure-sort-ns with comments
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/clojure-mode f5b85cac39: Fix clojure-sort-ns with comments in the end (#646) |
Date: |
Sat, 24 Jun 2023 16:01:00 -0400 (EDT) |
branch: elpa/clojure-mode
commit f5b85cac392a3a0ea844e7461ca53a8b2d903afb
Author: p4v4n <pavan.mantha99@gmail.com>
Commit: GitHub <noreply@github.com>
Fix clojure-sort-ns with comments in the end (#646)
Closes #645
---
CHANGELOG.md | 1 +
clojure-mode.el | 8 +++++++-
test/clojure-mode-util-test.el | 44 +++++++++++++++++++++++++++++++++++++++++-
3 files changed, 51 insertions(+), 2 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3098888928..1758cb4fb0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,7 @@
### Bugs fixed
+* [#645](https://github.com/clojure-emacs/clojure-mode/issues/645): Fix
infinite loop when sorting a ns with comments in the end.
* [#586](https://github.com/clojure-emacs/clojure-mode/issues/586): Fix
infinite loop when opening file containing `comment` with
`clojure-toplevel-inside-comment-form` set to `t`.
## 5.16.0 (2022-12-14)
diff --git a/clojure-mode.el b/clojure-mode.el
index 320eca1c8a..aac6c8b252 100644
--- a/clojure-mode.el
+++ b/clojure-mode.el
@@ -2030,7 +2030,13 @@ content) are considered part of the preceding sexp."
(save-restriction
(narrow-to-region (point) (save-excursion
(up-list)
- (1- (point))))
+ ;; Ignore any comments in the end before
sorting
+ (backward-char)
+ (forward-sexp -1)
+ (clojure-forward-logical-sexp)
+ (unless (looking-at-p ")")
+ (search-forward-regexp "$"))
+ (point)))
(skip-chars-forward "\r\n[:blank:]")
(sort-subr nil
(lambda () (skip-chars-forward "\r\n[:blank:]"))
diff --git a/test/clojure-mode-util-test.el b/test/clojure-mode-util-test.el
index bf17d02a54..353f0e5ead 100644
--- a/test/clojure-mode-util-test.el
+++ b/test/clojure-mode-util-test.el
@@ -136,7 +136,49 @@
(expect (buffer-string) :to-equal
"(ns my-app.core
(:require [my-app.views [user-page :as user-page]]
- [rum.core :as rum] ;comment\n))")))
+ [rum.core :as rum] ;comment
+))")))
+
+ (it "should sort requires in a basic ns with comments in the end"
+ (with-clojure-buffer "(ns my-app.core
+ (:require [rum.core :as rum] ;comment
+ [my-app.views [user-page :as user-page]]
+ ;;[comment2]
+))"
+ (clojure-sort-ns)
+ (expect (buffer-string) :to-equal
+ "(ns my-app.core
+ (:require [my-app.views [user-page :as user-page]]
+ [rum.core :as rum] ;comment
+
+ ;;[comment2]
+))")))
+ (it "should sort requires in ns with copyright disclamer and comments"
+ (with-clojure-buffer ";; Copyright (c) John Doe. All rights reserved.
+;; The use and distribution terms for this software are covered by the
+;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
+(ns clojure.core
+ (:require
+ ;; The first comment
+ [foo] ;; foo comment
+ ;; Middle comment
+ [bar] ;; bar comment
+ ;; A last comment
+ ))"
+ (clojure-sort-ns)
+ (expect (buffer-string) :to-equal
+ ";; Copyright (c) John Doe. All rights reserved.
+;; The use and distribution terms for this software are covered by the
+;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
+(ns clojure.core
+ (:require
+ ;; Middle comment
+ [bar] ;; bar comment
+ ;; The first comment
+ [foo] ;; foo comment
+
+ ;; A last comment
+ ))")))
(it "should also sort imports in a ns"
(with-clojure-buffer "\n(ns my-app.core
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [nongnu] elpa/clojure-mode f5b85cac39: Fix clojure-sort-ns with comments in the end (#646),
ELPA Syncer <=