branch: elpa/inf-clojure commit 8eaf885cb03515c010eff6d9924b641d30b3eb45 Author: Andrea Richiardi <a.richiardi.w...@gmail.com> Commit: Bozhidar Batsov <bozhidar.bat...@gmail.com>
[Fix #152] Sanitize should only remove whitespace at the end of a command --- inf-clojure.el | 14 +------------- test/inf-clojure-tests.el | 23 ++++------------------- 2 files changed, 5 insertions(+), 32 deletions(-) diff --git a/inf-clojure.el b/inf-clojure.el index 62d9402..e63a183 100644 --- a/inf-clojure.el +++ b/inf-clojure.el @@ -375,24 +375,12 @@ Should be a symbol that is a key in `inf-clojure-repl-features'." "Return non-nil 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 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 ((sanitized (inf-clojure--make-single-line command))) + (let ((sanitized (string-trim-right command))) (if (string-blank-p sanitized) "" (concat sanitized "\n")))) diff --git a/test/inf-clojure-tests.el b/test/inf-clojure-tests.el index 7821c06..1dd4d01 100644 --- a/test/inf-clojure-tests.el +++ b/test/inf-clojure-tests.el @@ -111,24 +111,6 @@ (expect (ict-bounds-string (inf-clojure-completion-bounds-of-expr-at-point)) :to-equal "deref"))))) -(describe "inf-clojure--make-single-line" - (it "replaces newlines with whitespace" - (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--make-single-line "(do\n(println \"hello world\")\n)\n\n") :to-equal "(do (println \"hello world\") )")) - - (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" (expect (inf-clojure--sanitize-command "(doc println)") :to-equal "(doc println)\n")) @@ -137,7 +119,10 @@ (expect (inf-clojure--sanitize-command "(doc println)\n\n\n\n") :to-equal "(doc println)\n")) (it "returns empty string when the command is empty" - (expect (inf-clojure--sanitize-command " ") :to-equal ""))) + (expect (inf-clojure--sanitize-command " ") :to-equal "")) + + (it "only removes whitespace at the end of the command - fix 152" + (expect (inf-clojure--sanitize-command "1 5") :to-equal "1 5\n"))) (describe "inf-clojure--update-feature" (it "updates new forms correctly"