Subject: Re: bug#20664: 25.0.50; Customize: Link option or face name to the source definition

From: Oleh Krehel <[email-masked]>
Date: Wed, 27 May 2015 15:19:52 +0200

Drew Adams <[email-masked]> writes:

> Feature request.  In Customize, for options and faces.  Put a link on
> the option/face name, so that following the link takes you to the source
> code (defcustom or defface).

Please check the patch. 

>From bea177aff8de195d428106003fab8b8498e7aae8 Mon Sep 17 00:00:00 2001
From: Oleh Krehel <[email-masked]>
Date: Wed, 27 May 2015 15:06:42 +0200
Subject: [PATCH] Allow to follow to face definition in Customize

* lisp/cus-edit.el (custom-face-value-create): Make the face name into
  a button that calls `find-face-definition'.

(Bug#20664)
---
 lisp/cus-edit.el | 29 ++++++++++++++++-------------
 1 file changed, 16 insertions(+), 13 deletions(-)

diff --git a/lisp/cus-edit.el b/lisp/cus-edit.el
index 1d9a9d6..246f08e 100644
--- a/lisp/cus-edit.el
+++ b/lisp/cus-edit.el
@@ -3483,19 +3483,22 @@ the present value is saved to its :shown-value property instead."
 	  (widget-put widget :buttons buttons))
 
       ;; Draw an ordinary `custom-face' widget
-      (let ((opoint (point)))
-	;; Visibility indicator.
-	(push (widget-create-child-and-convert
-	       widget 'custom-visibility
-	       :help-echo "Hide or show this face."
-	       :on "Hide" :off "Show"
-	       :on-glyph "down" :off-glyph "right"
-	       :action 'custom-toggle-hide-face
-	       (not hiddenp))
-	      buttons)
-	;; Face name (tag).
-	(insert " " tag)
-	(widget-specify-sample widget opoint (point)))
+      (let (opoint)
+        ;; Visibility indicator.
+        (push (widget-create-child-and-convert
+               widget 'custom-visibility
+               :help-echo "Hide or show this face."
+               :on "Hide" :off "Show"
+               :on-glyph "down" :off-glyph "right"
+               :action 'custom-toggle-hide-face
+               (not hiddenp))
+              buttons)
+        (setq opoint (point))
+        ;; Face name (tag).
+        (insert " " tag)
+        (make-button opoint (point)
+                     'follow-link t
+                     'action (lambda (&rest _x) (find-face-definition symbol))))
       (insert
        (cond ((eq custom-buffer-style 'face) " ")
 	     ((string-match-p "face\\'" tag)   ":")
-- 
1.8.4

With this patch, "RET" works as expected, while "<mouse-1>" is giving an
error for a reason I don't understand.  In order to make it work for the
mouse, I have to do something contorted instead of a plain
`make-button':

(define-key (overlay-get
             (make-button opoint (point)
                          'follow-link t
                          'action (lambda (&rest _x) (find-face-definition symbol)))
             'keymap) [down-mouse-1]
  (lambda ()
    (interactive)
    (let ((button (button-at (point))))
      (when button
        (button-activate button)
        t))))

Maybe someone can suggest a better way.

Oleh