[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/drepl 37dc526d1b 4/5: Add drepl--define macro
From: |
ELPA Syncer |
Subject: |
[elpa] externals/drepl 37dc526d1b 4/5: Add drepl--define macro |
Date: |
Sun, 12 Nov 2023 12:57:57 -0500 (EST) |
branch: externals/drepl
commit 37dc526d1b895f0dc7f473d92562848cffcc19ce
Author: Augusto Stoffel <arstoffel@gmail.com>
Commit: Augusto Stoffel <arstoffel@gmail.com>
Add drepl--define macro
---
drepl-ipython.el | 13 ++-----------
drepl-lua.el | 13 ++-----------
drepl.el | 39 +++++++++++++++++++++++++++++++++++----
3 files changed, 39 insertions(+), 26 deletions(-)
diff --git a/drepl-ipython.el b/drepl-ipython.el
index bf7cc5c3e5..2b9971f3d2 100644
--- a/drepl-ipython.el
+++ b/drepl-ipython.el
@@ -58,17 +58,8 @@ substring \"{}\" is replaced by the execution count."
default-directory))
"File name of the startup script.")
-(cl-defstruct (drepl-ipython
- (:include drepl-base)
- (:copier nil)
- (:conc-name drepl-ipython--)))
-(put 'drepl-ipython 'drepl--buffer-name "IPython")
-
-;;;###autoload
-(defun drepl-run-ipython ()
- "Start the IPython interpreter."
- (interactive)
- (drepl--run 'drepl-ipython t))
+;;;###autoload (autoload 'drepl-ipython "drepl-ipython" nil t)
+(drepl--define drepl-ipython :display-name "IPython")
(cl-defmethod drepl--command ((_ drepl-ipython))
`(,python-interpreter "-c"
diff --git a/drepl-lua.el b/drepl-lua.el
index 2f6b383747..0b01d1b268 100644
--- a/drepl-lua.el
+++ b/drepl-lua.el
@@ -45,17 +45,8 @@
default-directory))
"File name of the startup script.")
-(cl-defstruct (drepl-lua
- (:include drepl-base)
- (:copier nil)
- (:conc-name drepl-lua--)))
-(put 'drepl-lua 'drepl--buffer-name "Lua")
-
-;;;###autoload
-(defun drepl-run-lua ()
- "Start the Lua interpreter."
- (interactive)
- (drepl--run 'drepl-lua t))
+;;;###autoload (autoload 'drepl-lua "drepl-lua" nil t)
+(drepl--define drepl-lua :display-name "Lua")
(cl-defmethod drepl--command ((_ drepl-lua))
`(,drepl-lua-program "-v" "-e" "loadfile()():main()"))
diff --git a/drepl.el b/drepl.el
index fb66620732..9bdc13a11c 100644
--- a/drepl.el
+++ b/drepl.el
@@ -91,8 +91,39 @@ List of requests pending to be sent."))
"The underlying process of dREPL object REPL."
(get-buffer-process (drepl--buffer repl)))
+(cl-defmacro drepl--define (name &key display-name docstring extra-slots)
+ "Define a REPL type.
+NAME is a symbol to name the struct type identifying the REPL as
+well as the interactive command to launch it.
+
+DISPLAY-NAME is a string used to generate the default buffer name
+of REPL instances, among other things.
+
+DOCSTRING is the docstring of the command NAME.
+
+EXTRA-SLOTS is a list of slots passed to `cl-defstruct' in
+addition to those of `drepl-base'."
+ (let* ((display-name (or display-name (symbol-name name)))
+ (conc-name (intern (format "%s--" name))))
+ `(progn
+ (defun ,name ()
+ ,(or docstring
+ (format "Start the %s interpreter." display-name))
+ (interactive)
+ (drepl--run ',name t))
+ (cl-defstruct (,name
+ (:include drepl-base)
+ (:copier nil)
+ (:constructor nil)
+ (:constructor ,(intern (format "%screate" conc-name)))
+ (:conc-name ,conc-name))
+ ,(format "Structure keeping the state of a %s REPL." display-name)
+ ,@extra-slots)
+ (put ',name 'drepl--display-name ,display-name))))
+
(defun drepl--log-message-1 (&rest args)
- "Helper function for `drepl--log-message'."
+ "Helper function for `drepl--log-message'.
+ARGS is the entire argument list of `drepl--log-message'."
(with-current-buffer (get-buffer-create drepl--log-buffer)
(goto-char (point-max))
(when-let ((w (get-buffer-window)))
@@ -451,7 +482,7 @@ project; otherwise fall back to `default-directory'."
(format "%s/*%s*"
(file-name-nondirectory
(directory-file-name directory))
- (or (get type 'drepl--buffer-name) type)))
+ (or (get type 'drepl--display-name) type)))
(defun drepl--get-buffer-create (type may-prompt)
"Get or create a dREPL buffer of the given TYPE.
@@ -513,7 +544,7 @@ it, if necessary."
(unless (comint-check-proc buffer)
(cl-letf* (((default-value 'process-environment) process-environment)
((default-value 'exec-path) exec-path)
- (constructor (intern (format "make-%s" type)))
+ (constructor (intern (format "%s--create" type)))
(repl (funcall constructor :buffer buffer))
(command (drepl--command repl)))
(with-current-buffer buffer
@@ -548,5 +579,5 @@ it, if necessary."
(provide 'drepl)
-; LocalWords: dREPL
+; LocalWords: dREPL drepl
;;; drepl.el ends here