Skip to content

Commit 812d202

Browse files
committed
Fix REPL prompt corruption
For some reason, `pop-to-buffer` with Emacs 25.1 after `make-comint` results in corrupted prompt with strange ANSI control sequence. For example, when feeding `class Foo {}` and enter key, the input is echoed with the following character sequence ~~~ class Foo {}^[[1G^[[2m 1> ^[[22m^[[18G ~~~ which would be interpreted by a terminal like this ~~~ 1> Foo {} ~~~ This is not desirable. FYI, each sequence means as follows: |sequence |meaning | |---------|-----------------| |`^[[1G` |Goto 1st column | |`^[[2m` |Use faint color | |`^[[22m` |Use normal color | |`^[[18G` |Goto 18th column | Curiously, while invoking `swift` command from `shell` mode works fine, it will be corrupted with the following steps: 1. Start `shell` mode. 2. Type `M-x`. 3. Cancel the minibuffer with `C-g`. 4. Invoke `swift` command from the shell. I could not find the cause nor why this workaround works.
1 parent 58f31cc commit 812d202

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

swift-mode-repl.el

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,20 @@ Runs the hook `swift-repl-mode-hook' \(after the `comint-mode-hook' is run).
6161
(list (if current-prefix-arg
6262
(read-string "Run swift REPL: " swift-mode:repl-executable)
6363
swift-mode:repl-executable)))
64-
(unless (comint-check-proc (concat "*" cmd "*"))
65-
(save-excursion
66-
(let ((cmdlist (split-string cmd)))
67-
(set-buffer
68-
(apply 'make-comint cmd (car cmdlist) nil (cdr cmdlist)))
69-
(swift-repl-mode))))
70-
(setq-local swift-mode:repl-executable cmd)
71-
(setq-local swift-mode:repl-buffer (concat "*" cmd "*"))
72-
(setq-default swift-mode:repl-buffer swift-mode:repl-buffer)
73-
(unless dont-switch
74-
(pop-to-buffer swift-mode:repl-buffer)))
64+
(let ((original-buffer (current-buffer))
65+
(buffer (get-buffer-create (concat "*" cmd "*"))))
66+
(unless dont-switch
67+
(pop-to-buffer buffer))
68+
(unless (comint-check-proc (concat "*" cmd "*"))
69+
(save-excursion
70+
(let ((cmdlist (split-string cmd)))
71+
(apply 'make-comint-in-buffer
72+
cmd buffer (car cmdlist) nil (cdr cmdlist))
73+
(swift-repl-mode))))
74+
(with-current-buffer original-buffer
75+
(setq-local swift-mode:repl-executable cmd)
76+
(setq-local swift-mode:repl-buffer (concat "*" cmd "*"))
77+
(setq-default swift-mode:repl-buffer swift-mode:repl-buffer))))
7578

7679
;;;###autoload
7780
(defalias 'run-swift 'swift-mode:run-repl)

0 commit comments

Comments
 (0)