emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/swift-mode 812d202 341/496: Fix REPL prompt corruption


From: ELPA Syncer
Subject: [nongnu] elpa/swift-mode 812d202 341/496: Fix REPL prompt corruption
Date: Sun, 29 Aug 2021 11:34:03 -0400 (EDT)

branch: elpa/swift-mode
commit 812d202bdf41dbc0f0e145610ee1c103071918bc
Author: taku0 <mxxouy6x3m_github@tatapa.org>
Commit: taku0 <mxxouy6x3m_github@tatapa.org>

    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.
---
 swift-mode-repl.el | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/swift-mode-repl.el b/swift-mode-repl.el
index 3fc26e4..0493639 100644
--- a/swift-mode-repl.el
+++ b/swift-mode-repl.el
@@ -61,17 +61,20 @@ Runs the hook `swift-repl-mode-hook' \(after the 
`comint-mode-hook' is run).
    (list (if current-prefix-arg
              (read-string "Run swift REPL: " swift-mode:repl-executable)
            swift-mode:repl-executable)))
-  (unless (comint-check-proc (concat "*" cmd "*"))
-    (save-excursion
-      (let ((cmdlist (split-string cmd)))
-        (set-buffer
-         (apply 'make-comint cmd (car cmdlist) nil (cdr cmdlist)))
-        (swift-repl-mode))))
-  (setq-local swift-mode:repl-executable cmd)
-  (setq-local swift-mode:repl-buffer (concat "*" cmd "*"))
-  (setq-default swift-mode:repl-buffer swift-mode:repl-buffer)
-  (unless dont-switch
-    (pop-to-buffer swift-mode:repl-buffer)))
+  (let ((original-buffer (current-buffer))
+        (buffer (get-buffer-create (concat "*" cmd "*"))))
+    (unless dont-switch
+      (pop-to-buffer buffer))
+    (unless (comint-check-proc (concat "*" cmd "*"))
+      (save-excursion
+        (let ((cmdlist (split-string cmd)))
+          (apply 'make-comint-in-buffer
+                 cmd buffer (car cmdlist) nil (cdr cmdlist))
+          (swift-repl-mode))))
+    (with-current-buffer original-buffer
+      (setq-local swift-mode:repl-executable cmd)
+      (setq-local swift-mode:repl-buffer (concat "*" cmd "*"))
+      (setq-default swift-mode:repl-buffer swift-mode:repl-buffer))))
 
 ;;;###autoload
 (defalias 'run-swift 'swift-mode:run-repl)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]