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

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

[elpa] externals/drepl e7ea08d656 2/5: Add drepl--adapt-comint-to-mode


From: ELPA Syncer
Subject: [elpa] externals/drepl e7ea08d656 2/5: Add drepl--adapt-comint-to-mode
Date: Sun, 12 Nov 2023 12:57:57 -0500 (EST)

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

    Add drepl--adapt-comint-to-mode
---
 drepl-ipython.el |  4 ++--
 drepl-lua.el     |  3 +--
 drepl.el         | 26 +++++++++++++++++++++++++-
 3 files changed, 28 insertions(+), 5 deletions(-)

diff --git a/drepl-ipython.el b/drepl-ipython.el
index 4ec2f9e997..b40e92801d 100644
--- a/drepl-ipython.el
+++ b/drepl-ipython.el
@@ -28,7 +28,7 @@
 
 (require 'comint-mime)
 (require 'drepl)
-(require 'python)
+(require 'python)                       ;For `python-interpreter' only
 
 ;;; Customization options
 
@@ -73,7 +73,7 @@ substring \"{}\" is replaced by the execution count."
 
 (cl-defmethod drepl--init ((_ drepl-ipython))
   (drepl-mode)
-  (setq-local comint-indirect-setup-function #'python-mode)
+  (drepl--adapt-comint-to-mode ".py")
   (push '("5151" . comint-mime-osc-handler) ansi-osc-handlers)
   (let ((buffer (current-buffer)))
     (with-temp-buffer
diff --git a/drepl-lua.el b/drepl-lua.el
index 4511d47365..4236b544af 100644
--- a/drepl-lua.el
+++ b/drepl-lua.el
@@ -27,7 +27,6 @@
 
 ;;; Customization options
 (require 'drepl)
-(require 'lua-mode)
 
 (defgroup drepl-lua nil
   "Lua shell implemented via dREPL."
@@ -60,7 +59,7 @@
 
 (cl-defmethod drepl--init ((_ drepl-lua))
   (drepl-mode)
-  (setq-local comint-indirect-setup-function #'lua-mode)
+  (drepl--adapt-comint-to-mode ".lua")
   (let ((buffer (current-buffer)))
     (with-temp-buffer
       (insert-file-contents drepl-lua--start-file)
diff --git a/drepl.el b/drepl.el
index 5261dbcc55..cc6cb0bc07 100644
--- a/drepl.el
+++ b/drepl.el
@@ -37,7 +37,9 @@
 (require 'cl-lib)
 (require 'comint)
 (require 'project)
-(eval-when-compile (require 'subr-x))
+(eval-when-compile
+  (require 'derived)
+  (require 'subr-x))
 
 ;;; Variables and customization options
 
@@ -470,6 +472,28 @@ This method is called when the REPL sends a `getoptions'
 notification.  The REPL is in `ready' state when this happens.
 The notification message is passed as DATA.")
 
+(defun drepl--adapt-comint-to-mode (mode)
+  "Set up editing in a Comint buffer to resemble major MODE.
+
+Specifically:
+- Set `comint-indirect-setup-function' to MODE.
+- Set syntax table to MODE-syntax-table.
+
+MODE can be a major mode symbol or a string to look up an
+appropriate mode using `auto-mode-alist'."
+  (when (stringp mode)
+    (setq mode (cdr (assoc mode auto-mode-alist #'string-match-p))))
+  (when (functionp mode)
+    (setq mode (alist-get mode major-mode-remap-alist mode))
+    (when (autoloadp (symbol-function mode))
+      (autoload-do-load (symbol-function mode) mode))
+    (setq-local comint-indirect-setup-function mode)
+    (when-let ((syntbl-sym (derived-mode-syntax-table-name mode))
+               (syntbl-val (when (boundp syntbl-sym)
+                             (symbol-value syntbl-sym))))
+      (when (syntax-table-p syntbl-val)
+        (set-syntax-table syntbl-val)))))
+
 (defun drepl--run (class may-prompt)
   "Pop to a REPL of the given CLASS or start a new one.
 



reply via email to

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