emacs-diffs
[Top][All Lists]
Advanced

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

master 08ee074a6f1 1/2: Add unbuttonize-region


From: Robert Pluim
Subject: master 08ee074a6f1 1/2: Add unbuttonize-region
Date: Fri, 11 Oct 2024 06:17:30 -0400 (EDT)

branch: master
commit 08ee074a6f140a82e327fba446c05c96fe64932c
Author: Robert Pluim <rpluim@gmail.com>
Commit: Robert Pluim <rpluim@gmail.com>

    Add unbuttonize-region
    
    * doc/lispref/display.texi (Making Buttons): Document it.
    * lisp/button.el (unbuttonize-region): New function, removes all
    buttons in the specified region.
---
 doc/lispref/display.texi |  5 +++++
 etc/NEWS                 |  6 ++++++
 lisp/button.el           | 14 +++++++++++++-
 3 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi
index 1948854003d..f877a6a5a27 100644
--- a/doc/lispref/display.texi
+++ b/doc/lispref/display.texi
@@ -7968,6 +7968,11 @@ between @var{start} and @var{end} into a button.  
Arguments
 @code{help-echo} property of the button.
 @end defun
 
+@defun unbuttonize-region start end
+This function removes all buttons between @var{start} and @var{end} in
+the current buffer (both overlay and text-property based ones).
+@end defun
+
 @node Manipulating Buttons
 @subsection Manipulating Buttons
 @cindex manipulating buttons
diff --git a/etc/NEWS b/etc/NEWS
index e14efad8199..3d77612f304 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -222,6 +222,12 @@ When called with a prefix argument, accepting, declining, 
or tentatively
 accepting an icalendar event will prompt for a comment to add to the
 response.
 
+** Button
+
++++
+*** New function 'unbuttonize-region'.
+It removes all the buttons in the specified region.
+
 ** Eshell
 
 ---
diff --git a/lisp/button.el b/lisp/button.el
index c0584729172..de6ea8d966c 100644
--- a/lisp/button.el
+++ b/lisp/button.el
@@ -663,10 +663,22 @@ itself will be used instead as the function argument.
 
 If HELP-ECHO, use that as the `help-echo' property.
 
-Also see `buttonize'."
+Also see `buttonize' and `unbuttonize-region'."
   (add-text-properties start end (button--properties callback data help-echo))
   (add-face-text-property start end 'button t))
 
+(defun unbuttonize-region (start end)
+  "Remove all the buttons between START and END.
+This removes both text-property and overlay based buttons."
+  (dolist (o (overlays-in start end))
+    (when (overlay-get o 'button)
+      (delete-overlay o)))
+  (with-silent-modifications
+    (remove-text-properties start end
+                            (button--properties nil nil nil))
+    (add-face-text-property start end
+                            'button nil)))
+
 (provide 'button)
 
 ;;; button.el ends here



reply via email to

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