-
-
Notifications
You must be signed in to change notification settings - Fork 113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
hydra--around-find-function-search-for-symbol-advice breaks xref #413
Comments
Here's a repro:
Debugger entered--Lisp error:
The error does not come down to differences between Emacs versions, but rather differences in the version of Namely, the version on GNU-devel ELPA is the only to contain the following change: https://git.sv.gnu.org/cgit/emacs/elpa.git/commit/?id=54e9db2b02 Note the use of This is an unfortunate symptom of #408, i.e. that @monnier is the following fix for diff --git a/hydra.el b/hydra.el
index 5d5623c383..e6ee9f30e1 100644
--- a/hydra.el
+++ b/hydra.el
@@ -1,6 +1,6 @@
;;; hydra.el --- Make bindings that stick around. -*- lexical-binding: t -*-
-;; Copyright (C) 2015-2022 Free Software Foundation, Inc.
+;; Copyright (C) 2015-2022, 2024 Free Software Foundation, Inc.
;; Author: Oleh Krehel <[email protected]>
;; Maintainer: Oleh Krehel <[email protected]>
@@ -326,25 +326,28 @@ hydra-add-imenu
;; FIXME: Maybe we can dispense with this advice if `defhydra' adds appropriate
;; `definition-name' properties to the functions it defines?
+;; Note: Latest Emacs (at the time of writing, Emacs 30) is smart enough to find
+;; hydra definitions even without this advice or `definition-name'.
(advice-add 'find-function-search-for-symbol :around
#'hydra--around-find-function-search-for-symbol-advice)
(defun hydra--around-find-function-search-for-symbol-advice
- (orig-fun symbol type library)
+ (orig-fun symbol type library &rest args)
"Navigate to hydras with `find-function-search-for-symbol'."
- (let ((res (apply orig-fun symbol type library)))
- (when (symbolp symbol)
- ;; The original function returns (cons (current-buffer) (point))
- ;; if it found the point.
- (unless (cdr res)
- (with-current-buffer (find-file-noselect library)
- (let ((sn (symbol-name symbol)))
- (when (and (null type)
- (string-match "\\`\\(hydra-[[:alnum:]-]+\\)/\\(.*\\)\\'" sn)
- (re-search-forward (concat "(defhydra " (match-string 1 sn))
- nil t))
- (goto-char (match-beginning 0)))
- (cons (current-buffer) (point))))))
+ (let ((res (apply orig-fun symbol type library args)))
+ (when (and (symbolp symbol)
+ ;; Function definition.
+ (null type)
+ ;; Original function returns (BUFFER . POSITION)
+ ;; if it found POSITION; otherwise (BUFFER . nil).
+ (not (cdr res)))
+ (with-current-buffer (car res)
+ (let ((sn (symbol-name symbol)))
+ (save-excursion
+ (when (and (string-match "\\`\\(hydra-[[:alnum:]-]+\\)/.*\\'" sn)
+ (search-forward (concat "(defhydra " (match-string 1 sn))
+ nil t))
+ (setq res (cons (car res) (match-beginning 0))))))))
res))
;;* Universal Argument Thanks. |
In the meantime, the simplest workaround for anyone running into this error is to add the following to their (with-eval-after-load 'hydra
;; See URL `https://github.com/abo-abo/hydra/issues/413'.
(advice-remove 'find-function-search-for-symbol
'hydra--around-find-function-search-for-symbol-advice)) |
```diff
diff --git a/hydra.el b/hydra.el
index 5d5623c383..e6ee9f30e1 100644
--- a/hydra.el
+++ b/hydra.el
@@ -1,6 +1,6 @@
;;; hydra.el --- Make bindings that stick around. -*- lexical-binding: t -*-
-;; Copyright (C) 2015-2022 Free Software Foundation, Inc.
+;; Copyright (C) 2015-2022, 2024 Free Software Foundation, Inc.
Since our changes include
-;; Copyright (C) 2015-2019 Free Software Foundation, Inc.
+;; Copyright (C) 2015-2022 Free Software Foundation, Inc.
I'd just change the 2022 to 2024
@@ -326,25 +326,28 @@ hydra-add-imenu
;; FIXME: Maybe we can dispense with this advice if `defhydra' adds appropriate
;; `definition-name' properties to the functions it defines?
+;; Note: Latest Emacs (at the time of writing, Emacs 30) is smart enough to find
+;; hydra definitions even without this advice or `definition-name'.
(advice-add 'find-function-search-for-symbol :around
#'hydra--around-find-function-search-for-symbol-advice)
Interesting. Do you know which change in Emacs-30 gave us that?
Could we (when (fboundp ???)) to skip the advice when it's not needed?
(defun hydra--around-find-function-search-for-symbol-advice
- (orig-fun symbol type library)
+ (orig-fun symbol type library &rest args)
"Navigate to hydras with `find-function-search-for-symbol'."
- (let ((res (apply orig-fun symbol type library)))
- (when (symbolp symbol)
- ;; The original function returns (cons (current-buffer) (point))
- ;; if it found the point.
- (unless (cdr res)
- (with-current-buffer (find-file-noselect library)
- (let ((sn (symbol-name symbol)))
- (when (and (null type)
- (string-match "\\`\\(hydra-[[:alnum:]-]+\\)/\\(.*\\)\\'" sn)
- (re-search-forward (concat "(defhydra " (match-string 1 sn))
- nil t))
- (goto-char (match-beginning 0)))
- (cons (current-buffer) (point))))))
+ (let ((res (apply orig-fun symbol type library args)))
+ (when (and (symbolp symbol)
+ ;; Function definition.
+ (null type)
+ ;; Original function returns (BUFFER . POSITION)
+ ;; if it found POSITION; otherwise (BUFFER . nil).
+ (not (cdr res)))
+ (with-current-buffer (car res)
+ (let ((sn (symbol-name symbol)))
+ (save-excursion
+ (when (and (string-match "\\`\\(hydra-[[:alnum:]-]+\\)/.*\\'" sn)
+ (search-forward (concat "(defhydra " (match-string 1 sn))
+ nil t))
+ (setq res (cons (car res) (match-beginning 0))))))))
res))
Duh, yes, thanks. Tho maybe we should stick to fixing the missing `args`.
BTW, if we want to move the tests into the main `when` like you did, we
could also move the `string-match` test into it.
Stefan
|
abo-abo/hydra#413 means that I no longer consider any abo-abo packages stable.
With
hydra--around-find-function-search-for-symbol-advice
enabled none of the xref find definition functions work. I'm using emacs 28.2 on macOS 12.6 with the most recent version of hydra. I'm not sure what changed about emacs 28 to do this so I suspect it has to do with a commit in the last few months, perhaps one that backported to 28 from master.EDIT: the error message is always related to a c file and says "wrong-type-argument listp" and then a path to the c file.
The text was updated successfully, but these errors were encountered: