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

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

[elpa] externals/dape 9b835d66a7 3/3: Improve repl shorthand


From: ELPA Syncer
Subject: [elpa] externals/dape 9b835d66a7 3/3: Improve repl shorthand
Date: Mon, 4 Mar 2024 09:57:47 -0500 (EST)

branch: externals/dape
commit 9b835d66a706f8d642b128904607f5128c24997e
Author: Daniel Pettersson <daniel@dpettersson.net>
Commit: Daniel Pettersson <daniel@dpettersson.net>

    Improve repl shorthand
    
    - Add shorthand to completions
    - Support shorthand collision (shorthand sharing prefix chars)
---
 dape.el | 45 +++++++++++++++++++++++++++++----------------
 1 file changed, 29 insertions(+), 16 deletions(-)

diff --git a/dape.el b/dape.el
index 7180839103..1f2a323358 100644
--- a/dape.el
+++ b/dape.el
@@ -3897,6 +3897,17 @@ VARIABLE is expected to be the string representation of 
a varable."
         (funcall cb (propertize (gdb-table-string table " ")
                                 'dape--repl-variable variable))))))
 
+(defun dape--repl-shorthand-alist ()
+  "Return shorthanded version of `dape-repl-commands'."
+  (cl-loop with shorthand-alist = nil
+           for (str . command) in dape-repl-commands
+           for shorthand = (cl-loop for i from 1 upto (length str)
+                                    for shorthand = (substring str 0 i)
+                                    unless (assoc shorthand shorthand-alist)
+                                    return shorthand)
+           collect (cons shorthand command) into shorthand-alist
+           finally return shorthand-alist))
+
 (defun dape--repl-input-sender (dummy-process input)
   "Dape repl `comint-input-sender'.
 Send INPUT to DUMMY-PROCESS."
@@ -3912,9 +3923,7 @@ Send INPUT to DUMMY-PROCESS."
      ((setq cmd
             (or (alist-get input dape-repl-commands nil nil 'equal)
                 (and dape-repl-use-shorthand
-                     (cl-loop for (key . value) in dape-repl-commands
-                              when (equal (substring key 0 1) input)
-                              return value))))
+                     (cdr (assoc input (dape--repl-shorthand-alist))))))
       (dape--repl-insert-prompt)
       (call-interactively cmd))
      ;; Evaluate expression
@@ -3967,7 +3976,9 @@ Send INPUT to DUMMY-PROCESS."
                             (format " %s"
                                     (propertize (symbol-name (cdr cmd))
                                                 'face 
'font-lock-builtin-face))))
-                    dape-repl-commands))
+                    (append dape-repl-commands
+                            (when dape-repl-use-shorthand
+                              (dape--repl-shorthand-alist)))))
            done)
       (list
        (car bounds)
@@ -4073,18 +4084,20 @@ Send INPUT to DUMMY-PROCESS."
              "* Welcome to Dape REPL! *
 Available Dape commands: %s
 Empty input will rerun last command.\n"
-             (mapconcat 'identity
-                        (mapcar (lambda (cmd)
-                                  (let ((str (car cmd)))
-                                    (if dape-repl-use-shorthand
-                                        (concat
-                                         (propertize
-                                          (substring str 0 1)
-                                          'font-lock-face 'help-key-binding)
-                                         (substring str 1))
-                                      str)))
-                                dape-repl-commands)
-                        ", ")))
+             (mapconcat
+              (pcase-lambda (`(,str . ,command))
+                (setq str (concat str))
+                (when dape-repl-use-shorthand
+                  (set-text-properties
+                   0 (thread-last (dape--repl-shorthand-alist)
+                                  (rassoc command)
+                                  (car)
+                                  (length))
+                   '(font-lock-face help-key-binding)
+                   str))
+                str)
+              dape-repl-commands
+              ", ")))
     (set-marker (process-mark (get-buffer-process (current-buffer))) (point))
     (comint-output-filter (get-buffer-process (current-buffer))
                           dape--repl-prompt)))



reply via email to

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