From 0820db25833232b7126e8ab8935598a103415c58 Mon Sep 17 00:00:00 2001 From: abicky Date: Tue, 18 Sep 2018 01:23:22 +0900 Subject: [PATCH] Delete prompts inserted on set_window_size This PR resolves https://github.com/abicky/nodejs-repl.el/issues/15. --- nodejs-repl.el | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/nodejs-repl.el b/nodejs-repl.el index 48875d2..d0e57e9 100644 --- a/nodejs-repl.el +++ b/nodejs-repl.el @@ -146,7 +146,7 @@ See also `comint-process-echoes'" (defvar nodejs-repl-cache-completions ()) (defvar nodejs-repl-get-completions-for-require-p nil) -(defvar nodejs-repl-completion-at-point-called-p nil) +(defvar nodejs-repl-prompt-deletion-required-p nil) ;;;-------------------------- ;;; Private functions @@ -269,6 +269,9 @@ when receive the output string" (setq nodejs-repl-cache-token "") (setq nodejs-repl-cache-completions ())) +(defun nodejs-repl--set-prompt-deletion-required-p () + (setq nodejs-repl-prompt-deletion-required-p t)) + (defun nodejs-repl--remove-duplicated-prompt (string) ;; `.load` command of Node.js repl outputs a duplicated prompt (let ((beg (or comint-last-output-start @@ -279,10 +282,10 @@ when receive the output string" (when (re-search-forward (concat nodejs-repl-prompt nodejs-repl-prompt) end t) (replace-match nodejs-repl-prompt))))) -(defun nodejs-repl--remove-unexpected-prompts (string) - ;; Unexpected prompts are inserted if `completion-auto-help' is t - (when nodejs-repl-completion-at-point-called-p - (setq nodejs-repl-completion-at-point-called-p nil) +(defun nodejs-repl--delete-prompt (string) + ;; A prompt will be inserted if window--adjust-process-windows is called + (when nodejs-repl-prompt-deletion-required-p + (setq nodejs-repl-prompt-deletion-required-p nil) (let ((beg (or comint-last-output-start (point-min-marker))) (end (process-mark (get-buffer-process (current-buffer))))) @@ -480,13 +483,15 @@ otherwise spawn one." "Major mode for Node.js REPL" :syntax-table nodejs-repl-mode-syntax-table (set (make-local-variable 'font-lock-defaults) '(nil nil t)) - (add-hook 'comint-output-filter-functions 'nodejs-repl--remove-unexpected-prompts nil t) + (add-hook 'comint-output-filter-functions 'nodejs-repl--delete-prompt nil t) (add-hook 'comint-output-filter-functions 'nodejs-repl--remove-duplicated-prompt nil t) (add-hook 'comint-output-filter-functions 'nodejs-repl--filter-escape-sequnces nil t) (add-hook 'comint-output-filter-functions 'nodejs-repl--clear-cache nil t) (setq comint-input-ignoredups nodejs-repl-input-ignoredups) (setq comint-process-echoes nodejs-repl-process-echoes) (add-hook 'completion-at-point-functions 'nodejs-repl--completion-at-point-function nil t) + (make-local-variable 'window-configuration-change-hook) + (add-hook 'window-configuration-change-hook 'nodejs-repl--set-prompt-deletion-required-p) (ansi-color-for-comint-mode-on)) ;;;###autoload