Skip to content

Commit 8eaf885

Browse files
arichiardibbatsov
authored andcommitted
[Fix #152] Sanitize should only remove whitespace at the end of a command
1 parent e291da3 commit 8eaf885

File tree

2 files changed

+5
-32
lines changed

2 files changed

+5
-32
lines changed

inf-clojure.el

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -375,24 +375,12 @@ Should be a symbol that is a key in `inf-clojure-repl-features'."
375375
"Return non-nil iff STRING is a whole line semicolon comment."
376376
(string-match-p "^\s*;" string))
377377

378-
(defun inf-clojure--make-single-line (string)
379-
"Convert a multi-line STRING in a single-line STRING.
380-
It also reduces redundant whitespace for readability and removes
381-
comments."
382-
(let* ((lines (seq-filter (lambda (s) (not (inf-clojure--whole-comment-line-p s)))
383-
(split-string string "[\r\n]" t))))
384-
(mapconcat (lambda (s)
385-
(if (not (string-match-p ";" s))
386-
(replace-regexp-in-string "\s+" " " s)
387-
(concat s "\n")))
388-
lines " ")))
389-
390378
(defun inf-clojure--sanitize-command (command)
391379
"Sanitize COMMAND for sending it to a process.
392380
An example of things that this function does is to add a final
393381
newline at the end of the form. Return an empty string if the
394382
sanitized command is empty."
395-
(let ((sanitized (inf-clojure--make-single-line command)))
383+
(let ((sanitized (string-trim-right command)))
396384
(if (string-blank-p sanitized)
397385
""
398386
(concat sanitized "\n"))))

test/inf-clojure-tests.el

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -111,24 +111,6 @@
111111
(expect (ict-bounds-string (inf-clojure-completion-bounds-of-expr-at-point))
112112
:to-equal "deref")))))
113113

114-
(describe "inf-clojure--make-single-line"
115-
(it "replaces newlines with whitespace"
116-
(expect (inf-clojure--make-single-line "(do\n(println \"hello world\")\n)") :to-equal "(do (println \"hello world\") )"))
117-
118-
(it "does not leave whitespace at the end"
119-
(expect (inf-clojure--make-single-line "(do\n(println \"hello world\")\n)\n\n") :to-equal "(do (println \"hello world\") )"))
120-
121-
(it "returns empty string when the line is only newlines"
122-
(expect (inf-clojure--make-single-line "\n\n\n\n") :to-equal ""))
123-
124-
(it "removes comments when on their own line"
125-
(expect (inf-clojure--make-single-line "(do\n(println \"hello world\")\n ;; remove me\n)") :to-equal "(do (println \"hello world\") )"))
126-
127-
(it "preserves newlines of inline comments"
128-
(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 )"))
129-
130-
)
131-
132114
(describe "inf-clojure--sanitize-command"
133115
(it "sanitizes the command correctly"
134116
(expect (inf-clojure--sanitize-command "(doc println)") :to-equal "(doc println)\n"))
@@ -137,7 +119,10 @@
137119
(expect (inf-clojure--sanitize-command "(doc println)\n\n\n\n") :to-equal "(doc println)\n"))
138120

139121
(it "returns empty string when the command is empty"
140-
(expect (inf-clojure--sanitize-command " ") :to-equal "")))
122+
(expect (inf-clojure--sanitize-command " ") :to-equal ""))
123+
124+
(it "only removes whitespace at the end of the command - fix 152"
125+
(expect (inf-clojure--sanitize-command "1 5") :to-equal "1 5\n")))
141126

142127
(describe "inf-clojure--update-feature"
143128
(it "updates new forms correctly"

0 commit comments

Comments
 (0)