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

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

[nongnu] elpa/inf-clojure c3217c3 200/313: Skip sanitation of comments


From: ELPA Syncer
Subject: [nongnu] elpa/inf-clojure c3217c3 200/313: Skip sanitation of comments
Date: Wed, 11 Aug 2021 10:00:16 -0400 (EDT)

branch: elpa/inf-clojure
commit c3217c3fad1a06b0d40f25b64fffee8f115316d2
Author: Andrea Richiardi <a.richiardi.work@gmail.com>
Commit: Bozhidar Batsov <bozhidar.batsov@gmail.com>

    Skip sanitation of comments
---
 inf-clojure.el            | 30 ++++++++++++++++--------------
 test/inf-clojure-tests.el | 18 +++++++++++++-----
 2 files changed, 29 insertions(+), 19 deletions(-)

diff --git a/inf-clojure.el b/inf-clojure.el
index c44694b..de64f39 100644
--- a/inf-clojure.el
+++ b/inf-clojure.el
@@ -305,27 +305,29 @@ It requires a REPL PROC for inspecting the correct type."
         (setq-local inf-clojure-repl-type repl-type))
     inf-clojure-repl-type))
 
-(defun inf-clojure--single-linify (string)
+(defun inf-clojure--whole-comment-line-p (string)
+  "Return true iff STRING is a whole line semicolon comment."
+  (string-match-p "^\s*;" string))
+
+(defun inf-clojure--make-single-line (string)
   "Convert a multi-line STRING in a single-line STRING.
-It also reduces redundant whitespace for readability."
-  (thread-last string
-    (replace-regexp-in-string "[ \\|\n]+" " ")
-    (replace-regexp-in-string " $" "")))
-
-(defun inf-clojure--trim-newline-right (string)
-  "Trim newlines (only) in STRING."
-  (if (string-match "\n+\\'" string)
-      (replace-match "" t t string)
-    string))
+It also reduces redundant whitespace for readability and removes
+comments."
+  (let* ((lines (seq-filter (lambda (s) (not 
(inf-clojure--whole-comment-line-p s)))
+                            (split-string string "[\r\n]" t))))
+    (mapconcat (lambda (s)
+                 (if (not (string-match-p ";" s))
+                     (replace-regexp-in-string "\s+" " " s)
+                   (concat s "\n")))
+               lines " ")))
 
 (defun inf-clojure--sanitize-command (command)
   "Sanitize COMMAND for sending it to a process.
 An example of things that this function does is to add a final
 newline at the end of the form.  Return an empty string if the
 sanitized command is empty."
-  (let* ((linified (inf-clojure--single-linify command))
-         (sanitized (inf-clojure--trim-newline-right linified)))
-    (if (or (string-blank-p linified) (string-blank-p sanitized))
+  (let ((sanitized (inf-clojure--make-single-line command)))
+    (if (string-blank-p sanitized)
         ""
       (concat sanitized "\n"))))
 
diff --git a/test/inf-clojure-tests.el b/test/inf-clojure-tests.el
index 6147dd3..09b224e 100644
--- a/test/inf-clojure-tests.el
+++ b/test/inf-clojure-tests.el
@@ -111,15 +111,23 @@
          (expect (ict-bounds-string 
(inf-clojure-completion-bounds-of-expr-at-point))
                  :to-equal "deref")))))
 
-(describe "inf-clojure--single-linify"
+(describe "inf-clojure--make-single-line"
   (it "replaces newlines with whitespace"
-      (expect (inf-clojure--single-linify "(do\n(println \"hello world\")\n)") 
:to-equal "(do (println \"hello world\") )"))
+      (expect (inf-clojure--make-single-line "(do\n(println \"hello 
world\")\n)") :to-equal "(do (println \"hello world\") )"))
 
   (it "does not leave whitespace at the end"
-      (expect (inf-clojure--single-linify "(do\n(println \"hello 
world\")\n)\n\n") :to-equal "(do (println \"hello world\") )"))
+      (expect (inf-clojure--make-single-line "(do\n(println \"hello 
world\")\n)\n\n") :to-equal "(do (println \"hello world\") )"))
 
-  (it "returns empty string in case of only newline"
-      (expect (inf-clojure--single-linify "\n\n\n\n") :to-equal "")))
+  (it "returns empty string when the line is only newlines"
+      (expect (inf-clojure--make-single-line "\n\n\n\n") :to-equal ""))
+
+  (it "removes comments when on their own line"
+      (expect (inf-clojure--make-single-line "(do\n(println \"hello world\")\n 
   ;; remove me\n)") :to-equal "(do (println \"hello world\") )"))
+
+  (it "preserves newlines of inline comments"
+      (expect (inf-clojure--make-single-line "(do\n(println \"hello world\") 
;; don't remove this\n)") :to-equal "(do (println \"hello world\") ;; don't 
remove this\n )"))
+
+  )
 
 (describe "inf-clojure--sanitize-command"
   (it "sanitizes the command correctly"



reply via email to

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