emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master d71ee07852 1/3: Add new function buttonize-region


From: Lars Ingebrigtsen
Subject: master d71ee07852 1/3: Add new function buttonize-region
Date: Sat, 16 Apr 2022 09:42:17 -0400 (EDT)

branch: master
commit d71ee07852f15738b63d5cd9c5ccecd88a84a35a
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Add new function buttonize-region
    
    * lisp/button.el (buttonize-region): New function.
    (button--properties): Factored out.
    (buttonize): Use it.
---
 etc/NEWS       |  4 ++++
 lisp/button.el | 33 +++++++++++++++++++++++----------
 2 files changed, 27 insertions(+), 10 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index 6913f159c0..c9f8ae4630 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1377,6 +1377,10 @@ functions.
 
 * Lisp Changes in Emacs 29.1
 
++++
+** New convenience function 'buttonize-region'.
+This works like 'buttonize', but for a region instead of a string.
+
 +++
 ** 'macroexp-let2*' can omit 'test' arg and use single-var bindings.
 
diff --git a/lisp/button.el b/lisp/button.el
index 8a7751d00d..86cf4a9ae5 100644
--- a/lisp/button.el
+++ b/lisp/button.el
@@ -626,16 +626,29 @@ function argument.  If DATA isn't present (or is nil), 
the button
 itself will be used instead as the function argument.
 
 If HELP-ECHO, use that as the `help-echo' property."
-  (propertize string
-              'face 'button
-              'mouse-face 'highlight
-              'help-echo help-echo
-              'button t
-              'follow-link t
-              'category t
-              'button-data data
-              'keymap button-map
-              'action callback))
+  (apply #'propertize string
+         (button--properties callback data help-echo)))
+
+(defun button--properties (callback data help-echo)
+  (list 'face 'button
+        'font-lock-face 'button
+        'mouse-face 'highlight
+        'help-echo help-echo
+        'button t
+        'follow-link t
+        'category t
+        'button-data data
+        'keymap button-map
+        'action callback))
+
+(defun buttonize-region (start end callback &optional data help-echo)
+  "Make the region between START and END into a button.
+When clicked, CALLBACK will be called with the DATA as the
+function argument.  If DATA isn't present (or is nil), the button
+itself will be used instead as the function argument.
+
+If HELP-ECHO, use that as the `help-echo' property."
+  (add-text-properties start end (button--properties callback data help-echo)))
 
 (provide 'button)
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]