[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"
- [nongnu] elpa/inf-clojure 1a71b5e 163/313: Rephrase process logging description a bit, (continued)
- [nongnu] elpa/inf-clojure 1a71b5e 163/313: Rephrase process logging description a bit, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure ee38fc3 164/313: [Fix #96] Use inf-clojure--send-string instead of comint-proc-query, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure 7493ed8 166/313: Set inf-clojure-*-cmd :risky and :safe properties, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure b048358 173/313: Add expression break chars and prevent completions for numbers (#110), ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure 8c27b06 177/313: Introduce the tools.deps project type, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure 5c8f590 179/313: [Fix #116] Set inf-clojure-buffer REPL type on detect, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure 7b2fcd7 184/313: Revive inf-clojure-apropos, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure 8baa7ad 185/313: Correct inf-clojure-apropos key binding, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure d3c0d4f 187/313: Avoid throwing an error for frequent operations like completion, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure 630471b 194/313: Update CHANGELOG.md, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure c3217c3 200/313: Skip sanitation of comments,
ELPA Syncer <=
- [nongnu] elpa/inf-clojure 9b77479 207/313: Set inf-clojure-tools-deps-cmd to "clojure" (#144), ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure 58150d7 256/313: Improve some wording in the README, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure f63c609 252/313: Fix a typo, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure b5e915c 204/313: Travis test like in cider, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure b88de63 260/313: Tweak a docstring, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure e144b33 276/313: Improve the Makefile commands, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure 917ee77 268/313: Improve the README a bit, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure 91f4121 280/313: Bump the copyright years, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure 8eaf885 275/313: [Fix #152] Sanitize should only remove whitespace at the end of a command, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure ec4a85e 285/313: Bump copyright years, ELPA Syncer, 2021/08/11