[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/inf-clojure 39e794c 168/313: Protect against empty command
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/inf-clojure 39e794c 168/313: Protect against empty commands |
Date: |
Wed, 11 Aug 2021 10:00:09 -0400 (EDT) |
branch: elpa/inf-clojure
commit 39e794c169c331a43c52b62e546ddd612ef020d7
Author: Andrea Richiardi <a.richiardi.work@gmail.com>
Commit: Bozhidar Batsov <bozhidar.batsov@gmail.com>
Protect against empty commands
Improves the code so that empty strings are not sent to the process
anymore. It
also avoids trimming \t because they are actually used by some REPL.
---
inf-clojure.el | 77 +++++++++++++++++++++++++++++++++++-----------------------
1 file changed, 46 insertions(+), 31 deletions(-)
diff --git a/inf-clojure.el b/inf-clojure.el
index 71791da..f4e2362 100644
--- a/inf-clojure.el
+++ b/inf-clojure.el
@@ -256,15 +256,28 @@ It requires a REPL PROC for inspecting the correct type."
inf-clojure-repl-type))
(defun inf-clojure--single-linify (string)
- "Convert a multi-line STRING in a single-line STRING."
- (replace-regexp-in-string "[[:space:]\\|\n]+" " " string))
+ "Convert a multi-line STRING in a single-line STRING.
+It also reduces/adds redundant whitespace for readability. Note
+that this function will transform the empty string in \" \" (it
+adds an empty space)."
+ (replace-regexp-in-string "[ \\|\n]+" " " string))
+
+(defun inf-clojure--trim-newline-right (string)
+ "Trim newlines (only) in STRING."
+ (if (string-match "\n+\\'" string)
+ (replace-match "" t t string)
+ string))
(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."
- (concat (string-trim-right (inf-clojure--single-linify command))
- "\n"))
+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))
+ ""
+ (concat sanitized "\n"))))
(defun inf-clojure--send-string (proc string)
"A custom `comint-input-sender` / `comint-send-string`.
@@ -275,7 +288,8 @@ always be preferred over `comint-send-string`. It
delegates to
the string for evaluation. Refer to `comint-simple-send` for
customizations."
(inf-clojure--set-repl-type proc)
- (comint-simple-send proc string))
+ (when (> (length string) 0)
+ (comint-simple-send proc string)))
(defcustom inf-clojure-load-form "(clojure.core/load-file \"%s\")"
"Format-string for building a Clojure expression to load a file.
@@ -1041,31 +1055,32 @@ If BEG-REGEXP is nil, the result string will start from
(point)
in the results buffer. If END-REGEXP is nil, the result string
will end at (point-max) in the results buffer. It cuts out the
output from and including the `inf-clojure-prompt`."
- (inf-clojure--log-string command "----CMD->")
- (let ((work-buffer inf-clojure--redirect-buffer-name))
- (save-excursion
- (set-buffer (get-buffer-create work-buffer))
- (erase-buffer)
- (comint-redirect-send-command-to-process
- (inf-clojure--sanitize-command command) work-buffer process nil t)
- ;; Wait for the process to complete
- (set-buffer (process-buffer process))
- (while (and (null comint-redirect-completed)
- (accept-process-output process 1 0 t))
- (sleep-for 0.01))
- ;; Collect the output
- (set-buffer work-buffer)
- (goto-char (point-min))
- (let* ((buffer-string (buffer-substring-no-properties (point-min)
(point-max)))
- (boundaries (inf-clojure--string-boundaries buffer-string
inf-clojure-prompt beg-regexp end-regexp))
- (beg-pos (car boundaries))
- (end-pos (car (cdr boundaries)))
- (prompt-pos (car (cdr (cdr boundaries))))
- (response-string (substring buffer-string beg-pos (min end-pos
prompt-pos))))
- (inf-clojure--log-string buffer-string "<-BUF----")
- (inf-clojure--log-string boundaries "<-BND----")
- (inf-clojure--log-string response-string "<-RES----")
- response-string))))
+ (let ((work-buffer inf-clojure--redirect-buffer-name)
+ (sanitized-command (inf-clojure--sanitize-command command)))
+ (when (not (string-empty-p sanitized-command))
+ (inf-clojure--log-string command "----CMD->")
+ (save-excursion
+ (set-buffer (get-buffer-create work-buffer))
+ (erase-buffer)
+ (comint-redirect-send-command-to-process sanitized-command work-buffer
process nil t)
+ ;; Wait for the process to complete
+ (set-buffer (process-buffer process))
+ (while (and (null comint-redirect-completed)
+ (accept-process-output process 1 0 t))
+ (sleep-for 0.01))
+ ;; Collect the output
+ (set-buffer work-buffer)
+ (goto-char (point-min))
+ (let* ((buffer-string (buffer-substring-no-properties (point-min)
(point-max)))
+ (boundaries (inf-clojure--string-boundaries buffer-string
inf-clojure-prompt beg-regexp end-regexp))
+ (beg-pos (car boundaries))
+ (end-pos (car (cdr boundaries)))
+ (prompt-pos (car (cdr (cdr boundaries))))
+ (response-string (substring buffer-string beg-pos (min end-pos
prompt-pos))))
+ (inf-clojure--log-string buffer-string "<-BUF----")
+ (inf-clojure--log-string boundaries "<-BND----")
+ (inf-clojure--log-string response-string "<-RES----")
+ response-string)))))
(defun inf-clojure--nil-string-match-p (string)
"Return true iff STRING is not nil.
- [nongnu] elpa/inf-clojure 4a87862 161/313: Calculate response boundaries explicitly, (continued)
- [nongnu] elpa/inf-clojure 4a87862 161/313: Calculate response boundaries explicitly, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure 15963ca 162/313: Trim the string before checking nil, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure aaaeef6 167/313: Set string safety for all the form defcustoms, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure 864356a 172/313: [Fix #75] Remove compilation warnings (#109), ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure 5d76920 176/313: Introduce inf-clojure-project-type defcustom, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure f4478ad 183/313: Fix and reword docstring, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure d4010db 190/313: Add @ (deref) and ^ to the expression breaking chars, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure 37b30be 157/313: Bind C-c M-c to inf-clojure-connect, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure 49b8c4b 159/313: Restyle inf-clojure-log-activity output, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure 21d3e97 171/313: Bump the development version to 2.1.0-snapshot, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure 39e794c 168/313: Protect against empty commands,
ELPA Syncer <=
- [nongnu] elpa/inf-clojure ae43e2e 178/313: [Fix #113] Send REPL string always, even if empty, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure c4adc89 181/313: Introduce inf-clojure-completions-fn defcustom, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure 6c719c6 197/313: Avoid leaking buffers from inf-clojure--process-response, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure 5aa9c15 212/313: Add clojure socket REPL command and tweak, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure b87c5fb 215/313: update instructions to setup lumo repl (#147), ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure 16455ab 224/313: Fix typo in inf-clojure--joker-repl-form (#163), ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure 975e580 222/313: Fix CircleCI badge in README, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure 173d0e7 228/313: Bump the development version, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure 80cefbb 244/313: API to update repl-features, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure 3e7ca33 248/313: Add lein and boot to the startup-forms, ELPA Syncer, 2021/08/11