[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)
- [elpa] branch externals/drepl created (now aeba86f820), ELPA Syncer, 2023/11/07
- [elpa] externals/drepl 5650fef65d 08/10: Buffer association logic, ELPA Syncer, 2023/11/07
- [elpa] externals/drepl eaced7db3b 01/10: Initial commit, ELPA Syncer, 2023/11/07
- [elpa] externals/drepl 936bbe1c27 03/10: Add OSC to comint-output-filter-functions, ELPA Syncer, 2023/11/07
- [elpa] externals/drepl f0e87367b3 02/10: Make prompt faces inherit from default, ELPA Syncer, 2023/11/07
- [elpa] externals/drepl b30295f6f9 04/10: Use defclass instead of defstruct, ELPA Syncer, 2023/11/07
- [elpa] externals/drepl b6d3bd9183 05/10: Add setoptions method and getoptions notification,
ELPA Syncer <=
- [elpa] externals/drepl b79b71d39b 06/10: Refactoring and documentation, ELPA Syncer, 2023/11/07
- [elpa] externals/drepl 8f96ca981a 07/10: Add commands to evaluate a region and a buffer, ELPA Syncer, 2023/11/07
- [elpa] externals/drepl 61d907e463 09/10: Use Eldoc to display documentation, ELPA Syncer, 2023/11/07
- [elpa] externals/drepl aeba86f820 10/10: Add readme and commentary, ELPA Syncer, 2023/11/07