branch: elpa/inf-clojure commit a36d2a0473a211078af995ef9ea28f00fe1e6b32 Author: Andrea Richiardi <a.richiardi.w...@gmail.com> Commit: Bozhidar Batsov <bozhidar.bat...@gmail.com>
Remove unwanted ansi chars from the REPL output The change deletes some arbitrary characters that the Lumo REPL emits. --- inf-clojure.el | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/inf-clojure.el b/inf-clojure.el index 7415765..51a4f0b 100644 --- a/inf-clojure.el +++ b/inf-clojure.el @@ -332,6 +332,7 @@ to continue it." (setq comint-input-filter #'inf-clojure-input-filter) (setq-local comint-prompt-read-only inf-clojure-prompt-read-only) (add-hook 'comint-preoutput-filter-functions #'inf-clojure-preoutput-filter nil t) + (add-hook 'comint-output-filter-functions 'inf-clojure--ansi-filter) (add-hook 'completion-at-point-functions #'inf-clojure-completion-at-point nil t) (ansi-color-for-comint-mode-on)) @@ -356,6 +357,19 @@ to continue it." "Remove subprompts from STRING." (replace-regexp-in-string inf-clojure-subprompt "" string)) +(defconst inf-clojure--ansi-clear-line "\\[1G\\|\\[0J\\|\\[13G" + "Ansi codes sent by the lumo repl that we need to clear." ) + +(defun inf-clojure--ansi-filter (string) + "Filter unwanted ansi character from STRING." + (save-excursion + ;; go to start of first line just inserted + (comint-goto-process-mark) + (goto-char (max (point-min) (- (point) (string-width string)))) + (forward-line 0) + (while (re-search-forward inf-clojure--ansi-clear-line nil t) + (replace-match "")))) + (defun inf-clojure-preoutput-filter (str) "Preprocess the output STR from interactive commands." (cond