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

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

[elpa] externals/hydra b12d37ac00 03/46: hydra.el (hydra--format): Detec


From: Stefan Monnier
Subject: [elpa] externals/hydra b12d37ac00 03/46: hydra.el (hydra--format): Detect macroexpand
Date: Tue, 25 Oct 2022 22:27:19 -0400 (EDT)

branch: externals/hydra
commit b12d37ac00d4f677b7684ed1af7d04d996167dbb
Author: Oleh Krehel <ohwoeowho@gmail.com>
Commit: Oleh Krehel <ohwoeowho@gmail.com>

    hydra.el (hydra--format): Detect macroexpand
    
    When initiating `complete-symbol' while inside a `defhydra', a
    `macroexpand' will be called by elisp-mode.el.  This is problematic,
    since macroexpand is being called on incomplete code.
    
    Attempt to detect this. See `elisp--local-variables-completion-table',
    `elisp--local-variables'.
    
    Fixes #255
---
 hydra.el | 169 ++++++++++++++++++++++++++++++++-------------------------------
 1 file changed, 85 insertions(+), 84 deletions(-)

diff --git a/hydra.el b/hydra.el
index c8f9d92c20..2eff8feb3b 100644
--- a/hydra.el
+++ b/hydra.el
@@ -639,91 +639,92 @@ HEAD's binding is returned as a string wrapped with [] or 
{}."
 \"%`...\" expressions are extracted into \"%S\".
 _NAME, BODY, DOCSTRING and HEADS are parameters of `defhydra'.
 The expressions can be auto-expanded according to NAME."
-  (setq docstring (hydra--strip-align-markers docstring))
-  (setq docstring (replace-regexp-in-string "___" "_β_" docstring))
-  (let ((rest (if (eq (plist-get (cddr body) :hint) 'none)
-                  ""
-                (hydra--hint body heads)))
-        (start 0)
-        varlist
-        offset)
-    (while (setq start
-                 (string-match
-                  (format
-                   "\\(?:%%\\( 
?-?[0-9]*s?\\)\\(`[a-z-A-Z/0-9]+\\|(\\)\\)\\|\\(?:[_?]\\(%s\\)\\(%s\\)[_?]\\)"
-                   hydra-width-spec-regex
-                   hydra-key-regex)
-                  docstring start))
-      (cond ((eq ?? (aref (match-string 0 docstring) 0))
-             (let* ((key (match-string 4 docstring))
-                    (head (assoc key heads)))
-               (if head
-                   (progn
-                     (push (nth 2 head) varlist)
-                     (setq docstring
-                           (replace-match
-                            (or
-                             hydra-doc-format-spec
-                             (concat "%" (match-string 3 docstring) "s"))
-                            t nil docstring)))
-                 (setq start (match-end 0))
-                 (warn "Unrecognized key: ?%s?" key))))
-            ((eq ?_ (aref (match-string 0 docstring) 0))
-             (let* ((key (match-string 4 docstring))
-                    (key (if (equal key "β") "_" key))
-                    normal-key
-                    (head (or (assoc key heads)
-                              (when (setq normal-key
-                                          (cdr (assoc
-                                                key 
hydra-docstring-keys-translate-alist)))
-                                (assoc normal-key heads)))))
-               (if head
-                   (progn
-                     (push (hydra-fontify-head (if normal-key
-                                                   (cons key (cdr head))
-                                                 head)
-                                               body)
-                           varlist)
-                     (let ((replacement
-                            (or
-                             hydra-key-format-spec
-                             (concat "%" (match-string 3 docstring) "s"))))
+  (unless (memq 'elisp--witness--lisp (mapcar #'cadr heads))
+    (setq docstring (hydra--strip-align-markers docstring))
+    (setq docstring (replace-regexp-in-string "___" "_β_" docstring))
+    (let ((rest (if (eq (plist-get (cddr body) :hint) 'none)
+                    ""
+                  (hydra--hint body heads)))
+          (start 0)
+          varlist
+          offset)
+      (while (setq start
+                   (string-match
+                    (format
+                     "\\(?:%%\\( 
?-?[0-9]*s?\\)\\(`[a-z-A-Z/0-9]+\\|(\\)\\)\\|\\(?:[_?]\\(%s\\)\\(%s\\)[_?]\\)"
+                     hydra-width-spec-regex
+                     hydra-key-regex)
+                    docstring start))
+        (cond ((eq ?? (aref (match-string 0 docstring) 0))
+               (let* ((key (match-string 4 docstring))
+                      (head (assoc key heads)))
+                 (if head
+                     (progn
+                       (push (nth 2 head) varlist)
                        (setq docstring
-                             (replace-match replacement t nil docstring))
-                       (setq start (+ start (length replacement)))))
-                 (setq start (match-end 0))
-                 (warn "Unrecognized key: _%s_" key))))
-
-            (t
-             (let* ((varp (if (eq ?` (aref (match-string 2 docstring) 0)) 1 0))
-                    (spec (match-string 1 docstring))
-                    (lspec (length spec)))
-               (setq offset
-                     (with-temp-buffer
-                       (insert (substring docstring (+ 1 start varp
-                                                       (length spec))))
-                       (goto-char (point-min))
-                       (push (read (current-buffer)) varlist)
-                       (- (point) (point-min))))
-               (when (or (zerop lspec)
-                         (/= (aref spec (1- (length spec))) ?s))
-                 (setq spec (concat spec "S")))
-               (setq docstring
-                     (concat
-                      (substring docstring 0 start)
-                      "%" spec
-                      (substring docstring (+ start offset 1 lspec varp))))))))
-    (if (eq ?\n (aref docstring 0))
-        `(concat (format ,(substring docstring 1) ,@(nreverse varlist))
-                 ,rest)
-      (let ((r `(replace-regexp-in-string
-                 " +$" ""
-                 (concat ,docstring ": "
-                         (replace-regexp-in-string
-                          "\\(%\\)" "\\1\\1" ,rest)))))
-        (if (stringp rest)
-            `(format ,(eval r))
-          `(format ,r))))))
+                             (replace-match
+                              (or
+                               hydra-doc-format-spec
+                               (concat "%" (match-string 3 docstring) "s"))
+                              t nil docstring)))
+                   (setq start (match-end 0))
+                   (warn "Unrecognized key: ?%s?" key))))
+              ((eq ?_ (aref (match-string 0 docstring) 0))
+               (let* ((key (match-string 4 docstring))
+                      (key (if (equal key "β") "_" key))
+                      normal-key
+                      (head (or (assoc key heads)
+                                (when (setq normal-key
+                                            (cdr (assoc
+                                                  key 
hydra-docstring-keys-translate-alist)))
+                                  (assoc normal-key heads)))))
+                 (if head
+                     (progn
+                       (push (hydra-fontify-head (if normal-key
+                                                     (cons key (cdr head))
+                                                   head)
+                                                 body)
+                             varlist)
+                       (let ((replacement
+                              (or
+                               hydra-key-format-spec
+                               (concat "%" (match-string 3 docstring) "s"))))
+                         (setq docstring
+                               (replace-match replacement t nil docstring))
+                         (setq start (+ start (length replacement)))))
+                   (setq start (match-end 0))
+                   (warn "Unrecognized key: _%s_" key))))
+
+              (t
+               (let* ((varp (if (eq ?` (aref (match-string 2 docstring) 0)) 1 
0))
+                      (spec (match-string 1 docstring))
+                      (lspec (length spec)))
+                 (setq offset
+                       (with-temp-buffer
+                         (insert (substring docstring (+ 1 start varp
+                                                         (length spec))))
+                         (goto-char (point-min))
+                         (push (read (current-buffer)) varlist)
+                         (- (point) (point-min))))
+                 (when (or (zerop lspec)
+                           (/= (aref spec (1- (length spec))) ?s))
+                   (setq spec (concat spec "S")))
+                 (setq docstring
+                       (concat
+                        (substring docstring 0 start)
+                        "%" spec
+                        (substring docstring (+ start offset 1 lspec 
varp))))))))
+      (if (eq ?\n (aref docstring 0))
+          `(concat (format ,(substring docstring 1) ,@(nreverse varlist))
+                   ,rest)
+        (let ((r `(replace-regexp-in-string
+                   " +$" ""
+                   (concat ,docstring ": "
+                           (replace-regexp-in-string
+                            "\\(%\\)" "\\1\\1" ,rest)))))
+          (if (stringp rest)
+              `(format ,(eval r))
+            `(format ,r)))))))
 
 (defun hydra--complain (format-string &rest args)
   "Forward to (`message' FORMAT-STRING ARGS) unless `hydra-verbose' is nil."



reply via email to

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