SiteMap Search ElispArea HowTo Glossary RecentChanges News Problems Suggestions

ButtonLockMode

Overview

Button-lock mode is a minor mode which provides simple facilities to define clickable text based on regular expressions. Button-lock piggybacks on font-lock, and is efficient.

Button-lock buttons (links) can execute any function.

See WikiNavMode for a user-friendly library built on top of button-lock mode.

Availability

Both button-lock mode and WikiNavMode are available at github:

https://github.com/rolandwalker/button-lock

and via EmacsWiki:

Lisp:button-lock.el

Example

Here’s a trivial example, showing how to use button-lock to activate hyperlinks in all buffers:

   (require 'button-lock)
   (global-button-lock-mode 1)
   (button-lock-set-global-button "\\<http://[^[:space:]\n]+"
                                  'browse-url-at-mouse
                                  :face 'link :policy 'prepend)

and here’s an interesting example, showing how to turn folding-mode delimiters into mouseable buttons:

   (require 'folding)
   (require 'button-lock)
   ; turn folding-mode delimiters into mouseable buttons
   (add-hook 'folding-mode-hook  #'(lambda ()
                                     (button-lock-mode 1)
                                     (button-lock-set-button
                                      (concat "^" (regexp-quote (car (folding-get-mode-marks))))
                                      'folding-toggle-show-hide)
                                     (button-lock-set-button
                                      (concat "^" (regexp-quote (cadr (folding-get-mode-marks))))
                                      'folding-toggle-show-hide)))

It is probably more interesting to use button-lock from another library than it is to use button-lock directly.

Compatibility and Requirements

Tested only on GNU Emacs version 24.1

No external dependencies

Bug in ButtonLockMode

There is a bug in ButtonLockMode. There is a defface for button-lock-button-face but the name used in the rest of the code is button-lock-face. A temporary solution is to put:

(defface button-lock-face
    '((t nil))
    "Face used to show active button-lock buttons.

The default is for buttons to inherit whatever properties are
already provided by font-lock."
    :group 'button-lock)

in your startup file. You can then customize the correct face and as a bonus it stops all those annoying messages about an invalid face. Does anyone know how I can contact the author?


CategoryModes CategoryHypermedia CategoryMouse CategoryExtensions