Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions nodejs-repl.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)))))
Expand Down Expand Up @@ -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
Expand Down