branch: externals/termint
commit ee09159be7ae24c973310475f538c3f74f12a99c
Author: Milan Glacier <d...@milanglacier.com>
Commit: Milan Glacier <d...@milanglacier.com>

    feat: add new option `:send-delayed-final-ret`.
    
    `:send-delayed-final-ret': Send the final return with a slight delay.
    Some REPLs may not properly recognize when a large chunk of text sent
    with bracketed paste mode has finished being input and needs to be
    evaluated.  Normally, a final return character signals the REPL to
    execute the command, but certain REPLs require a brief delay before
    this final return to properly process the bracketed paste input.  This
    option should generally remain false (the default), with Claude Code
    being a notable exception that requires it to be set to true.
    Contributions are welcome if other REPLs are found to need this option
    enabled.  The default value is nil.
---
 README.md  | 17 +++++++++++------
 termint.el | 34 ++++++++++++++++++++++++++++------
 2 files changed, 39 insertions(+), 12 deletions(-)

diff --git a/README.md b/README.md
index cf2b00ac7d..b7b57b54dc 100644
--- a/README.md
+++ b/README.md
@@ -143,6 +143,12 @@ customization of the REPL's behavior:
   non-empty line of the code chunk as overlay. Alongside the source command 
sent
   to the REPL, providing a useful hint about the actual command being executed.
   the default value is nil.
+- `termint-myrepl-send-delayed-final-ret`: When enabled, send the final return
+  with a slight delay. Some REPLs may not properly recognize when a large chunk
+  of text sent with bracketed paste mode has finished being input and needs to
+  be evaluated. This option should generally remain false (the default), with
+  Claude Code being a notable exception that requires it to be set to true. PRs
+  are welcome if other REPLs are found to need this option enabled.
 
 ## Examples
 
@@ -151,10 +157,9 @@ the derived commands. To address this, we recommend 
configuring `termint` using
 `use-package`, which provides advanced lazy-loading functionality out of the
 box.
 
-We also recommend declare **separate** `use-package` forms for each
-REPL schema.  This structure allows you to activate specific REPL
-commands as long as their corresponding programming language mode
-loads.
+We also recommend declare **separate** `use-package` forms for each REPL 
schema.
+This structure allows you to activate specific REPL commands as long as their
+corresponding programming language mode loads.
 
 In the below example, we created two REPL schemas:
 
@@ -262,8 +267,8 @@ temporary file handling—such as exposure to malicious 
attack—could pose secu
 risks. Thus, while beneficial in certain scenarios, this method requires 
careful
 consideration of its potential drawbacks.
 
-you may consider enabling `:show-source-command-hint` as `t`, which
-provides useful hint about the underlying command being executed.
+you may consider enabling `:show-source-command-hint` as `t`, which provides
+useful hint about the underlying command being executed.
 
 ## Bracketed-Paste Mode
 
diff --git a/termint.el b/termint.el
index 95d68e4bf3..0d31059559 100644
--- a/termint.el
+++ b/termint.el
@@ -181,12 +181,13 @@ without a number is considered as session 0."
      start-pattern
      end-pattern
      bracketed-paste-p
-     str-process-func)
+     str-process-func
+     send-delayed-final-ret)
   "Send STRING to a REPL.
 The target REPL buffer is specified by REPL-NAME and SESSION.
 Additional parameters—START-PATTERN, END-PATTERN, BRACKETED-PASTE-P,
-and STR-PROCESS-FUNC—are variables associated with REPL-NAME,
-initialized during each `termint-define' call."
+STR-PROCESS-FUNC, and SEND-DELAYED-FINAL-RET—are variables associated
+with REPL-NAME, initialized during each `termint-define' call."
   (setq session (termint--get-session-suffix session))
   (let* ((repl-buffer-name
           (if session
@@ -217,7 +218,11 @@ initialized during each `termint-define' call."
                       (and bracketed-paste-p bracketed-paste-end)
                       end-pattern)
             (concat start-pattern string end-pattern))))
-    (funcall send-string repl-buffer-name final-string)))
+    (funcall send-string repl-buffer-name final-string)
+    (when send-delayed-final-ret
+      (run-with-timer 0.3 nil
+                      (lambda ()
+                        (funcall send-string repl-buffer-name "\r"))))))
 
 (defun termint--show-source-command-hint (repl-name session original-content 
source-command)
   "Display the hint of SOURCE-COMMAND.
@@ -414,7 +419,18 @@ variant for greater flexibility and control.
 `:show-source-command-hint' Display the first non-empty line of the
 code chunk as overlay.  Alongside the source command sent to the REPL,
 providing a useful hint about the actual command being executed. the
-default value is nil."
+default value is nil.
+
+`:send-delayed-final-ret' Send the final return with a slight delay.
+Some REPLs may not properly recognize when a large chunk of text sent
+with bracketed paste mode has finished being input and needs to be
+evaluated.  Normally, a final return character signals the REPL to
+execute the command, but certain REPLs require a brief delay before
+this final return to properly process the bracketed paste input.  This
+option should generally remain false (the default), with Claude Code
+being a notable exception that requires it to be set to true.
+Contributions are welcome if other REPLs are found to need this option
+enabled.  The default value is nil."
 
   (let ((start-func-name (intern (concat "termint-" repl-name "-start")))
         (send-region-func-name (intern (concat "termint-" repl-name 
"-send-region")))
@@ -430,6 +446,7 @@ default value is nil."
         (str-process-func (or (plist-get args :str-process-func) ''identity))
         (source-syntax (or (plist-get args :source-syntax) ''identity))
         (show-source-command-hint (plist-get args :show-source-command-hint))
+        (send-delayed-final-ret (plist-get args :send-delayed-final-ret))
         (repl-cmd-name (intern (concat "termint-" repl-name "-cmd")))
         (str-process-func-name (intern (concat "termint-" repl-name 
"-str-process-func")))
         (source-syntax-name (intern (concat "termint-" repl-name 
"-source-syntax")))
@@ -437,6 +454,7 @@ default value is nil."
         (bracketed-paste-p-name (intern (concat "termint-" repl-name 
"-use-bracketed-paste-mode")))
         (start-pattern-name (intern (concat "termint-" repl-name 
"-start-pattern")))
         (end-pattern-name (intern (concat "termint-" repl-name 
"-end-pattern")))
+        (send-delayed-final-ret-name (intern (concat "termint-" repl-name 
"-send-delayed-final-ret")))
         ;; send paragraph and source paragraph
         (send-paragraph-func-name (intern (concat "termint-" repl-name 
"-send-paragraph")))
         (source-paragraph-func-name (intern (concat "termint-" repl-name 
"-source-paragraph")))
@@ -470,6 +488,9 @@ default value is nil."
        (defvar ,end-pattern-name ,end-pattern
          ,(format "The last string to send to the %s REPL after sending the 
text." repl-name))
 
+       (defvar ,send-delayed-final-ret-name ,send-delayed-final-ret
+         ,(format "Whether to send the final return with a slight delay for 
the %s REPL." repl-name))
+
        (defun ,start-func-name (&optional session)
          ,(format
            "Create a %s REPL buffer.
@@ -516,7 +537,8 @@ process with that number."
                                ,start-pattern-name
                                ,end-pattern-name
                                ,bracketed-paste-p-name
-                               ,str-process-func-name))
+                               ,str-process-func-name
+                               ,send-delayed-final-ret-name))
 
        (defun ,send-paragraph-func-name (&optional session)
          ,(format

Reply via email to