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

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

[elpa] externals/drepl b6d3bd9183 05/10: Add setoptions method and getop


From: ELPA Syncer
Subject: [elpa] externals/drepl b6d3bd9183 05/10: Add setoptions method and getoptions notification
Date: Tue, 7 Nov 2023 03:58:04 -0500 (EST)

branch: externals/drepl
commit b6d3bd918380eba7c96ce85168f5b8cf71770224
Author: Augusto Stoffel <arstoffel@gmail.com>
Commit: Augusto Stoffel <arstoffel@gmail.com>

    Add setoptions method and getoptions notification
---
 drepl-ipython.el | 19 ++++++++++++++++---
 drepl-ipython.py | 24 ++++++++++++++++--------
 drepl.el         |  7 +++++++
 3 files changed, 39 insertions(+), 11 deletions(-)

diff --git a/drepl-ipython.el b/drepl-ipython.el
index 02f768e9ef..a825a0827d 100644
--- a/drepl-ipython.el
+++ b/drepl-ipython.el
@@ -36,9 +36,18 @@
   :group 'python
   :link '(url-link "https://github.com/astoff/drepl";))
 
-(defcustom drepl-ipython-buffer-name "*IPython*"
-  "Name of IPython shell buffer."
-  :type 'string)
+(defcustom drepl-ipython-prompts
+  ["In [{}]: " "...: " "\e[31mOut[{}]:\e[0m " "\n" ""]
+  "Prompts of the Python dREPL.
+
+This should be a vector of 5 string: primary prompt, continuation
+prompt, output prefix, input separator, output separator.  The
+substring \"{}\" is replaced by the execution count."
+  :type '(vector (string :tag "Primary prompt")
+                 (string :tag "Continuation prompt")
+                 (string :tag "Output prompt")
+                 (string :tag "Input separator")
+                 (string :tag "Output separator")))
 
 (defvar drepl-ipython--start-file
   (expand-file-name "drepl-ipython.py"
@@ -75,6 +84,10 @@
       (process-send-string buffer (buffer-string))
       (process-send-eof buffer))))
 
+(cl-defmethod drepl--set-options ((repl drepl-ipython) _)
+  (drepl--communicate repl #'ignore 'setoptions
+                      :prompts drepl-ipython-prompts))
+
 (cl-defmethod drepl--restart :around ((repl drepl-ipython) hard)
   (if (and (not hard) (eq (drepl--status repl) 'ready))
       (with-current-buffer (drepl--buffer repl)
diff --git a/drepl-ipython.py b/drepl-ipython.py
index 9450f1e3a8..cb90028db3 100644
--- a/drepl-ipython.py
+++ b/drepl-ipython.py
@@ -105,11 +105,14 @@ class DRepl(InteractiveShell):
     def mainloop(self):
         while self.keep_running:
             try:
-                if self.current_ps1 is not None:
-                    print(self.separate_in, end="")
-                self.current_ps1 = sys.ps1.format(self.execution_count)
-                reply(op="status", status="ready")
-                line = input(self.current_ps1)
+                if self.current_ps1 is None:
+                    reply(op="getoptions")
+                    self.current_ps1, separate_in = "", ""
+                else:
+                    reply(op="status", status="ready")
+                    separate_in = self.separate_in if self.current_ps1 else ""
+                    self.current_ps1 = sys.ps1.format(self.execution_count)
+                line = input(separate_in + self.current_ps1)
                 while line.startswith("\033%"):
                     data = json.loads(line[2:])
                     op = data.pop("op")
@@ -118,14 +121,14 @@ class DRepl(InteractiveShell):
                         print("Invalid op: {}".format(op))
                         continue
                     fun(**data)
-                    if op == "eval":
+                    if op in ("eval", "setoptions"):
                         break  # Allow execution count to increment.
                     reply(op="status", status="ready")
                     line = input()
                 else:
                     print("Invalid input")
             except KeyboardInterrupt as e:
-                print(type(e).__name__)
+                print(e.__class__.__name__)
             except EOFError:
                 reply(op="status", status="busy")
                 if (not self.confirm_exit) or self.ask_yes_no(
@@ -148,7 +151,7 @@ class DRepl(InteractiveShell):
 
     def drepl_checkinput(self, id, code):
         status, indent = self.check_complete(code)
-        prompt = 
sys.ps2.format(self.execution_count).ljust(len(self.current_ps1))
+        prompt = 
sys.ps2.format(self.execution_count).rjust(len(self.current_ps1))
         reply(id=id, status=status, indent=indent, prompt=prompt)
 
     def drepl_describe(self, id, code, offset):
@@ -165,3 +168,8 @@ class DRepl(InteractiveShell):
             )
         except Exception:
             reply(id=id)
+
+    def drepl_setoptions(self, id, prompts=None):
+        if prompts:
+            sys.ps1, sys.ps2, sys.ps3, self.separate_in, self.separate_out = 
prompts
+        reply(id=id)
diff --git a/drepl.el b/drepl.el
index 0da1068d4a..9d7a2b464c 100644
--- a/drepl.el
+++ b/drepl.el
@@ -123,6 +123,9 @@ which determines whether to ask or return nil when in 
doubt."
     ("status" (setf (drepl--status repl)
                     (intern (alist-get 'status data))))
     ("log" (drepl--message "dREPL buffer %s: %s"
+    ("getoptions"
+     (setf (drepl--status repl) 'ready)
+     (drepl--set-options repl data))
                            (buffer-name)
                            (alist-get 'text data)))))
 
@@ -294,6 +297,10 @@ if needed."
   (ignore repl)
   (error "This needs an implementation"))
 
+(cl-defgeneric drepl--set-options (repl data)
+  (ignore repl data)
+  (error "This needs an implementation"))
+
 (cl-defgeneric drepl--restart (repl _hard)
   "Restart the REPL."
   (with-current-buffer (drepl--buffer repl)



reply via email to

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