8

I'm trying to create *Help* buffers in Emacs, documenting functions defined in other languages.

I can create a simple help buffer easily:

(defun wh/help-hello-world ()
  (interactive)
  (with-help-window (help-buffer)
    (princ "foo_bar is a function.\n\nIt does stuff.")))

However, I want to add a clickable link in my *Help* buffer, which Emacs seems to call a button. I can see describe-function-1 calls help-xref-button which creates a button.

However, if I call insert-text-button the same way help-xref-button creates buttons, then 'help-args seems to expect an elisp function and path.

(defun wh/help-hello-world-button ()
  (interactive)
  (let ((buf (help-buffer)))
    (with-help-window buf
      (princ "foo_bar is a function.\n\nIt does stuff."))
    (with-current-buffer buf
      (let ((inhibit-read-only t))
        (insert-text-button
         "example.txt"
         'type 'help-function-def
         'help-args '(button-type-subtype-p "/usr/share/emacs/24.5/lisp/button.el.gz"))))))

How can I create an Emacs button pointing to an arbitrary line in an arbitrary file?

Wilfred Hughes
  • 6,890
  • 2
  • 29
  • 59

1 Answers1

9

You can use both make-button or make-text-button. For example

(defun button-pressed (button)
  (message (format "Button pressed!")))

(define-button-type 'custom-button
  'action 'button-pressed
  'follow-link t
  'help-echo "Click Button"
  'help-args "test")

(make-button 1 10 :type 'custom-button)

This will create a button at char 1 to 10 in the current buffer.

Tephra
  • 821
  • 5
  • 14