diff options
author | Antero Mejr <antero@mailbox.org> | 2023-04-08 01:40:46 +0000 |
---|---|---|
committer | jao <jao@gnu.org> | 2023-04-22 22:25:10 +0100 |
commit | 7e6e05ba7fcbbc9b9ef1ffd54daac0e8b2362e56 (patch) | |
tree | 1a2b5a6d0593043b6bf994bf368911da4d31ea20 /elisp | |
parent | e6976b5f95f4930c20bd4e775d8b94f9dfc0e6f2 (diff) | |
download | geiser-7e6e05ba7fcbbc9b9ef1ffd54daac0e8b2362e56.tar.gz geiser-7e6e05ba7fcbbc9b9ef1ffd54daac0e8b2362e56.tar.bz2 |
Add geiser-repl-autoeval-mode minor mode.
Disabled by default. Adds new custom variables
"geiser-repl-autoeval-mode-delay" and "geiser-repl-autoeval-mode-p".
Diffstat (limited to 'elisp')
-rw-r--r-- | elisp/geiser-mode.el | 2 | ||||
-rw-r--r-- | elisp/geiser-repl.el | 57 |
2 files changed, 59 insertions, 0 deletions
diff --git a/elisp/geiser-mode.el b/elisp/geiser-mode.el index eebb1ef..ad2e419 100644 --- a/elisp/geiser-mode.el +++ b/elisp/geiser-mode.el @@ -328,6 +328,8 @@ With prefix, try to enter the current buffer's module." ("Symbol manual lookup" ("\C-c\C-d\C-i" "\C-c\C-di") geiser-doc-look-up-manual :enable (geiser-doc--manual-available-p)) (mode "Autodoc mode" ("\C-c\C-d\C-a" "\C-c\C-da") geiser-autodoc-mode) + (mode "Autoeval mode" ("\C-c\C-d\C-e" "\C-c\C-de") + geiser-repl-autoeval-mode) -- ("Compile buffer" "\C-c\C-k" geiser-compile-current-buffer) ("Switch to REPL" "\C-c\C-z" geiser-mode-switch-to-repl) diff --git a/elisp/geiser-repl.el b/elisp/geiser-repl.el index 57c4673..18083bc 100644 --- a/elisp/geiser-repl.el +++ b/elisp/geiser-repl.el @@ -29,6 +29,7 @@ (require 'scheme) (require 'font-lock) (require 'project) +(require 'paren) (eval-when-compile (require 'subr-x)) @@ -218,6 +219,14 @@ This variable is a good candidate for .dir-locals.el. See also `geiser-repl-startup-hook'." :type '(repeat string)) +(geiser-custom--defcustom geiser-repl-autoeval-mode-delay 0.125 + "Delay before autoeval is run after an S-expression is balanced, in seconds." + :type 'number) + +(geiser-custom--defcustom geiser-repl-autoeval-mode-p nil + "Whether `geiser-repl-autoeval-mode' gets enabled by default in REPL buffers." + :type 'boolean) + (geiser-custom--defface repl-input 'comint-highlight-input geiser-repl "evaluated input highlighting") @@ -783,6 +792,49 @@ If SAVE-HISTORY is non-nil, save CMD in the REPL history." 'geiser-repl--sentinel)) +;;; geiser-repl-autoeval-mode minor mode: + +(defun geiser-repl--autoeval-paren-function () + (let* ((data (show-paren--default)) + (here (nth 0 data)) + (there (nth 2 data)) + (mismatch (nth 4 data))) + (if (and here + (eq 0 (geiser-repl--nesting-level)) + (not mismatch) + (> here there)) + (geiser-repl--send-input)) + data)) + +(defvar-local geiser-repl-autoeval-mode-string " E" + "Modeline indicator for geiser-repl-autoeval-mode") + +(define-minor-mode geiser-repl-autoeval-mode + "Toggle the Geiser REPL's Autoeval mode. +With no argument, this command toggles the mode. +Non-null prefix argument turns on the mode. +Null prefix argument turns off the mode. + +When Autoeval mode is enabled, balanced S-expressions are automatically +evaluated without having to press ENTER. + +This mode may cause issues with structural editing modes such as paredit." + :init-value nil + :lighter geiser-repl-autoeval-mode-string + :group 'geiser-repl + + (if (boundp 'show-paren-data-function) + (if geiser-repl-autoeval-mode + (progn (show-paren-local-mode 1) + (setq-local show-paren-delay geiser-repl-autoeval-delay) + (setq-local show-paren-data-function + 'geiser-repl--autoeval-paren-function)) + (setq-local show-paren-data-function 'show-paren--default))) + (when (called-interactively-p nil) + (message "Geiser Autoeval %s" + (if geiser-repl-autoeval-mode "enabled" "disabled")))) + + ;;; geiser-repl mode: (defun geiser-repl--bol () @@ -931,6 +983,8 @@ buffer." geiser-repl-interrupt) -- (mode "Autodoc mode" ("\C-c\C-da" "\C-c\C-d\C-a") geiser-autodoc-mode) + (mode "Autoeval mode" ("\C-c\C-de" "\C-c\C-d\C-e") + geiser-repl-autoeval-mode) ("Symbol documentation" ("\C-c\C-dd" "\C-c\C-d\C-d") geiser-doc-symbol-at-point "Documentation for symbol at point" :enable (geiser--symbol-at-point)) @@ -984,6 +1038,9 @@ buffer." #'geiser-repl--wrap-fontify-region-function) (setq-local font-lock-unfontify-region-function #'geiser-repl--wrap-unfontify-region-function) + (setq geiser-autodoc-mode-string "/E") + (when geiser-repl-autoeval-mode-p + (geiser-repl-autoeval-mode 1)) ;; enabling compilation-shell-minor-mode without the annoying highlighter (compilation-setup t)) |