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

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

[nongnu] elpa/sly a0cb300: Close #360: make REPL prompt customizable


From: ELPA Syncer
Subject: [nongnu] elpa/sly a0cb300: Close #360: make REPL prompt customizable
Date: Thu, 4 Feb 2021 11:57:08 -0500 (EST)

branch: elpa/sly
commit a0cb30051434be91f8c1889643a77bf218f8b0f5
Author: Pierre Neidhardt <mail@ambrevar.xyz>
Commit: João Távora <joaotavora@gmail.com>

    Close #360: make REPL prompt customizable
    
    Co-authored-by: João Távora <joaotavora@gmail.com>
    
    * contrib/sly-mrepl.el (sly-mrepl-prompt-formatter): New defcustom.
    (sly-mrepl-default-prompt): New function.
    (sly-mrepl--insert-prompt): Call sly-mrepl-prompt-formatter.
    (channel-method :prompt): Delegate to
    sly-mrepl--insert-prompt.
    
    * contrib/slynk-mrepl.lisp (prompt-arguments): Add "next" entry level.
    
    * doc/sly.texi (Defcustom variables): Document REPL customization
    variables.
---
 contrib/sly-mrepl.el     | 64 ++++++++++++++++++++++++++++++++++++------------
 contrib/slynk-mrepl.lisp |  2 ++
 doc/sly.texi             | 35 ++++++++++++++++++++++++++
 3 files changed, 86 insertions(+), 15 deletions(-)

diff --git a/contrib/sly-mrepl.el b/contrib/sly-mrepl.el
index 90c1397..74af7d8 100644
--- a/contrib/sly-mrepl.el
+++ b/contrib/sly-mrepl.el
@@ -237,11 +237,9 @@ for output printed to the REPL (not for evaluation 
results)")
            (setq sly-mrepl--read-mark nil)
            (sly-message "REPL back to normal evaluation mode")))))))
 
-(sly-define-channel-method listener :prompt (package prompt
-                                                     error-level
-                                                     &optional condition)
+(sly-define-channel-method listener :prompt (&rest prompt-args)
   (with-current-buffer (sly-channel-get self 'buffer)
-    (sly-mrepl--insert-prompt package prompt error-level condition)))
+    (apply #'sly-mrepl--insert-prompt prompt-args)))
 
 (sly-define-channel-method listener :open-dedicated-output-stream
                            (port _coding-system)
@@ -458,7 +456,47 @@ In that case, moving a sexp backward does nothing."
                          (overlay-end sly-mrepl--last-prompt-overlay)
                          '(font-lock-face sly-mrepl-prompt-face))))
 
-(defun sly-mrepl--insert-prompt (package prompt error-level &optional 
condition)
+(defun sly-mrepl-default-prompt (_package
+                                 nickname
+                                 error-level
+                                 _entry-idx
+                                 _condition)
+  "Compute default SLY prompt string.
+Suitable for `sly-mrepl-prompt-formatter'."
+  (concat
+   (when (cl-plusp error-level)
+     (concat (sly-make-action-button
+              (format "[%d]" error-level)
+              #'sly-db-pop-to-debugger-maybe)
+             " "))
+   (propertize
+    (concat nickname "> ")
+    'face 'sly-mrepl-prompt-face
+    'font-lock-face 'sly-mrepl-prompt-face)))
+
+(defcustom sly-mrepl-prompt-formatter #'sly-mrepl-default-prompt
+  "Compute propertized string to use as REPL prompt.
+Value is a function passed at least 5 arguments with the
+following signature:
+
+(PACKAGE NICKNAME ERROR-LEVEL NEXT-ENTRY-IDX CONDITION &REST)
+
+PACKAGE is a string denoring the full name of the current
+package.  NICKNAME is the shortest or preferred nickname of
+PACKAGE, according to the Lisp variables
+SLYNK:*CANONICAL-PACKAGE-NICKNAMES* and
+SLYNK:*AUTO-ABBREVIATE-DOTTED-PACKAGES*.  ERROR-LEVEL is a
+integer counting the number of outstanding errors.
+NEXT-ENTRY-IDX is a number identifying future evaluation results
+for backreferencing purposes.  Depending on ERROR-LEVEL,
+CONDITION is either nil or a string containing the printed
+representation of the outstanding condition that caused the
+current ERROR-LEVEL."
+  :type 'function
+  :group 'sly)
+
+(defun sly-mrepl--insert-prompt (package nickname error-level next-entry-idx
+                                         &optional condition)
   (sly-mrepl--accept-process-output)
   (overlay-put sly-mrepl--last-prompt-overlay 'face 'bold)
   (when condition
@@ -468,16 +506,12 @@ In that case, moving a sexp backward does nothing."
   (let ((beg (marker-position (sly-mrepl--mark))))
     (sly-mrepl--insert
      (propertize
-      (concat
-       (when (cl-plusp error-level)
-         (concat (sly-make-action-button
-                  (format "[%d]" error-level)
-                  #'sly-db-pop-to-debugger-maybe)
-                 " "))
-       (propertize
-        (concat prompt "> ")
-        'face 'sly-mrepl-prompt-face
-        'font-lock-face 'sly-mrepl-prompt-face))
+      (funcall sly-mrepl-prompt-formatter
+               package
+               nickname
+               error-level
+               next-entry-idx
+               condition)
       'sly-mrepl--prompt (downcase package)))
     (move-overlay sly-mrepl--last-prompt-overlay beg (sly-mrepl--mark)))
   (sly-mrepl--ensure-prompt-face)
diff --git a/contrib/slynk-mrepl.lisp b/contrib/slynk-mrepl.lisp
index fc8af0a..32282f6 100644
--- a/contrib/slynk-mrepl.lisp
+++ b/contrib/slynk-mrepl.lisp
@@ -240,9 +240,11 @@ Set this to NIL to turn this feature off.")
           (send-prompt repl))))))
 
 (defun prompt-arguments (repl condition)
+  "Return (PACKAGE NICKNAME ELEVEL ENTRY-IDX &optional CONDITION)"
   `(,(package-name *package*)
     ,(package-string-for-prompt *package*)
     ,(length (mrepl-pending-errors repl))
+    ,(length *history*)
     ,@(when condition
         (list (write-to-string condition
                                :escape t
diff --git a/doc/sly.texi b/doc/sly.texi
index 0edafdc..7bcf8ea 100644
--- a/doc/sly.texi
+++ b/doc/sly.texi
@@ -2504,6 +2504,41 @@ inspector, etc..) are automatically killed.
 
 @end table
 
+The following customization variables affect the behaviour of the
+@REPL{} (@pxref{REPL}):
+
+@table @code
+
+@item sly-mrepl-shortcut
+The key to use to trigger the REPL's ``comma shortcut''.  We recommend
+you keep the default setting which is the comma (@code{,}) key, since
+there's special logic in the REPL to discern if you're typing a comma
+inside a backquoted list or not.
+
+@item sly-mrepl-prompt-formatter
+Holds a function that can be set from your Emacs init file
+(@pxref{Init File,Init File, Emacs Init File, emacs, The Emacs Manual})
+to change the way the prompt is rendered.  It takes a number of
+arguments describing the prompt and should return a propertized Elisp
+string.  See the default value, @code{sly-mrepl-default-prompt}, for how
+to implement such a prompt.
+
+@item sly-mrepl-history-file-name
+Holds a string designating the file to use for keeping the shared REPL
+histories persistently.  The default is to use a hidden file
+named @code{.sly-mrepl-history} in the user's home directory.
+
+@item sly-mrepl-prevent-duplicate-history
+A symbol.  If non-nil, prevent duplicate entries in input history.  If
+the non-nil value is the symbol @code{move}, the previously occuring
+entry is moved to a more recent spot.
+
+@item sly-mrepl-eli-like-history-navigation
+If non-NIL, navigate history like in ELI, Franz's Common Lisp IDE for
+Emacs.
+
+@end table
+
 @node Hooks
 @subsection Hooks
 



reply via email to

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