2

I'm looking for a minor mode that would let me attach actions to text that matches some pattern.

Like, for example, match urls, emails and pathnames (or any other thing) and create buttons that run some command on click.

Think of it as of a customizable and generalized version of goto-address minor mode.

Does it exist already?

If it doesn't, I'll try to write it myself. How would you name the mode? I was thinking of something like matching-actions-mode, but I'm not sure.

Drew
  • 75,699
  • 9
  • 109
  • 225

2 Answers2

1

I am not very familiar with it, but AFAIK, the embark package provides such functionality. Although the README does not really emphasize it, its functionality should be usable from any normal buffer. Also, according to its README

Everything is easily configurable: determining the current target, classifying it, and deciding which actions are offered for each type in the classification. The above introduction just mentions part of the default configuration.

Additionaly, it defines a default target which you can 'trigger' using embark-dwim.

Finally, you can configure indicators to 'show' available targets.

As creating buttons indeed is equivalent to attaching actions to text, and optionally adding some 'button face', the embark functionality seems to fulfill your 'requirements'.

Overall, it looks to me that you could get your desired functionality by appropriately configuring Embark.

dalanicolai
  • 6,108
  • 7
  • 23
0

I think you are looking for buttons (https://www.gnu.org/software/emacs/manual/html_node/elisp/Buttons.html), and maybe specifically button-lock (https://github.com/rolandwalker/button-lock). I used this in a package to make functional text at https://github.com/jkitchin/scimax/blob/master/scimax-functional-text.el. I don't use it a lot, it was somewhat proof of concept code for me, but it sounds like the kind of thing you want.

John Kitchin
  • 11,555
  • 1
  • 19
  • 41