geiser-users
[Top][All Lists]
Advanced

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

Re: [PATCH] geiser-repl-autoeval-mode


From: Jose A. Ortega Ruiz
Subject: Re: [PATCH] geiser-repl-autoeval-mode
Date: Mon, 10 Apr 2023 01:59:52 +0100
User-agent: Gnus/5.13 (Gnus v5.13)

Hi Antero,

Thanks for your contribution.  The code looks good.  However, I am not
sure I want to merge it :)  Fact is, this is a feature I, personally,
would recommend against to anyone using Geiser, and that's why I
hesitate.  Its main drawbacks, as I see it, are:

   - Precludes de use of paredit (or similar modes)
   - Interferes with a common mode of working where one writes
     s-expressions, thinks about them, perhaps checks their
     documentation, sends them to evaluate.
   - Everything one does at the REPL is synchronous, no magically
     disappearing prompts when a timeout expires.

On the flip side, the only advantage I can think of is that it saves you
one keystroke.  Paredit alone saves potentially dozens, among other
advantages.  But maybe I am missing some other advantages?

I could say that geiser is an "opinionated" package, but the truth is
just its maintainer is a curmudgeon that would need some convincing to
add this feature, possibly including other users asking for it.  An
alternative would be to create a simple ELPA package for it.

Thoughts?

Cheers,
jao

On Sat, Apr 08 2023, Antero Mejr via wrote:

> Attached is a patch that adds a minor mode for automatically evaluating
> balanced S-expressions in the Geiser REPL, so users don't have to press
> ENTER every time. The mode is disabled by default but can be enabled via
> a variable.
>
> From 66a4e53729baeedcacd02ccc789fa96f1f2a9645 Mon Sep 17 00:00:00 2001
> From: Antero Mejr <antero@mailbox.org>
> Date: Sat, 8 Apr 2023 01:40:46 +0000
> Subject: [PATCH] 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".
> ---
>  elisp/geiser-mode.el |  2 ++
>  elisp/geiser-repl.el | 55 ++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 57 insertions(+)
>
> 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..b760d49 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")
>  
> @@ -782,6 +791,47 @@ If SAVE-HISTORY is non-nil, save CMD in the REPL 
> history."
>    (set-process-sentinel (get-buffer-process (current-buffer))
>                          '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."
> +  :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:
>  
> @@ -931,6 +981,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 +1036,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))

-- 
Fools ignore complexity. Pragmatists suffer it. Some can avoid it.
Geniuses remove it.
  - Alan Perlis, Epigrams on Programming



reply via email to

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