]> code.delx.au - gnu-emacs-elpa/commitdiff
Make find-function work with defhydra
authorOleh Krehel <ohwoeowho@gmail.com>
Sun, 2 Aug 2015 12:38:31 +0000 (14:38 +0200)
committerOleh Krehel <ohwoeowho@gmail.com>
Sun, 2 Aug 2015 12:38:31 +0000 (14:38 +0200)
* hydra.el (find-function-search-for-symbol): New defadvice.

Fixes #153

hydra.el

index fa4f641d7ab22e4c5999338176d9f6278fe99b54..a9b4587c0a239ba3e0afe772114840297d96393a 100644 (file)
--- a/hydra.el
+++ b/hydra.el
@@ -250,6 +250,25 @@ Exitable only through a blue head.")
       (1 font-lock-keyword-face)
       (2 font-lock-type-face)))))
 
+;;* Find Function
+(eval-after-load 'find-func
+  '(defadvice find-function-search-for-symbol
+    (around hydra-around-find-function-search-for-symbol-advice
+     (symbol type library) activate)
+    "Navigate to hydras with `find-function-search-for-symbol'."
+    ad-do-it
+    ;; The orignial function returns (cons (current-buffer) (point))
+    ;; if it found the point.
+    (unless (cdr ad-return-value)
+      (with-current-buffer (find-file-noselect library)
+        (let ((sn (symbol-name symbol)))
+          (when (and (null type)
+                     (string-match "\\`\\(hydra-[a-z-A-Z0-9]+\\)/\\(.*\\)\\'" sn)
+                     (re-search-forward (concat "(defhydra " (match-string 1 sn))
+                                        nil t))
+            (goto-char (match-beginning 0)))
+          (cons (current-buffer) (point)))))))
+
 ;;* Universal Argument
 (defvar hydra-base-map
   (let ((map (make-sparse-keymap)))