[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."
- [elpa] externals/hydra updated (4532f40ae4 -> 7081ee6d44), Stefan Monnier, 2022/10/25
- [elpa] externals/hydra a23046b7d5 06/46: hydra.el (hydra--hint-from-matrix): Refactor, Stefan Monnier, 2022/10/25
- [elpa] externals/hydra b12d37ac00 03/46: hydra.el (hydra--format): Detect macroexpand,
Stefan Monnier <=
- [elpa] externals/hydra 6eaf10f52c 05/46: hydra-test.el (hydra-format-5): Fix failing test, Stefan Monnier, 2022/10/25
- [elpa] externals/hydra 462202d7fc 11/46: hydra.el (hydra--doc): Fixup, Stefan Monnier, 2022/10/25
- [elpa] externals/hydra ab67b29835 01/46: Declare the third argument of `defhydra’ as a (potential) docstring., Stefan Monnier, 2022/10/25
- [elpa] externals/hydra 1deed8a00e 09/46: fix typo in readme, Stefan Monnier, 2022/10/25
- [elpa] externals/hydra 03eeea324c 10/46: Make first line of hydra docstrings more informative., Stefan Monnier, 2022/10/25
- [elpa] externals/hydra 62e0f37462 14/46: hydra-test.el: Fix tests for previous commit, Stefan Monnier, 2022/10/25
- [elpa] externals/hydra 5b8f662992 16/46: hydra.el (hydra--format): Allow e.g. "M-?" in docstring, Stefan Monnier, 2022/10/25
- [elpa] externals/hydra 44b42598ee 18/46: Fix Typos, Stefan Monnier, 2022/10/25
- [elpa] externals/hydra d071278fcc 20/46: hydra.el (hydra--format): Fix off-by-one, Stefan Monnier, 2022/10/25
- [elpa] externals/hydra 5c5b9ca326 21/46: Silence byte-compiler on Emacs 25, Stefan Monnier, 2022/10/25