GNU bug report logs - #8898
add a function to change button label

Previous Next

Package: emacs;

Reported by: Dmitry Kurochkin <dmitry.kurochkin <at> gmail.com>

Date: Sun, 19 Jun 2011 20:27:02 UTC

Severity: wishlist

Tags: patch, wontfix

Found in version 24.0.50

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 8898 in the body.
You can then email your comments to 8898 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#8898; Package emacs. (Sun, 19 Jun 2011 20:27:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Dmitry Kurochkin <dmitry.kurochkin <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sun, 19 Jun 2011 20:27:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Dmitry Kurochkin <dmitry.kurochkin <at> gmail.com>
To: submit <at> debbugs.gnu.org
Subject: add a function to change button label
Date: Mon, 20 Jun 2011 00:26:43 +0400
[Message part 1 (text/plain, inline)]
Package: emacs
Version: 24.0.50
Tags: patch

In some cases it is very useful to change button text label.  Please
consider applying the attached patch that implements `button-set-label'
function to change button label.

Regards,
  Dmitry
[button-set-label.patch (text/x-diff, inline)]
Add `button-set-label' function to change button label.

=== modified file 'doc/lispref/display.texi'
--- doc/lispref/display.texi	2011-05-29 22:41:06 +0000
+++ doc/lispref/display.texi	2011-06-19 20:04:46 +0000
@@ -5046,40 +5046,44 @@ Return the position at which @var{button
 
 @defun button-get button prop
 Get the property of button @var{button} named @var{prop}.
 @end defun
 
 @defun button-put button prop val
 Set @var{button}'s @var{prop} property to @var{val}.
 @end defun
 
 @defun button-activate button &optional use-mouse-action
 Call @var{button}'s @code{action} property (i.e., invoke it).  If
 @var{use-mouse-action} is non-@code{nil}, try to invoke the button's
 @code{mouse-action} property instead of @code{action}; if the button
 has no @code{mouse-action} property, use @code{action} as normal.
 @end defun
 
 @defun button-label button
 Return @var{button}'s text label.
 @end defun
 
+@defun button-set-label button label
+Change @var{button}'s text label to @var{label}.
+@end defun
+
 @defun button-type button
 Return @var{button}'s button-type.
 @end defun
 
 @defun button-has-type-p button type
 Return @code{t} if @var{button} has button-type @var{type}, or one of
 @var{type}'s subtypes.
 @end defun
 
 @defun button-at pos
 Return the button at position @var{pos} in the current buffer, or @code{nil}.
 @end defun
 
 @defun button-type-put type prop val
 Set the button-type @var{type}'s @var{prop} property to @var{val}.
 @end defun
 
 @defun button-type-get type prop
 Get the property of button-type @var{type} named @var{prop}.
 @end defun

=== modified file 'lisp/button.el'
--- lisp/button.el	2011-01-25 04:08:28 +0000
+++ lisp/button.el	2011-06-19 20:08:33 +0000
@@ -216,40 +216,52 @@ changes to a supertype are not reflected
      prop val)))
 
 (defsubst button-activate (button &optional use-mouse-action)
   "Call BUTTON's action property.
 If USE-MOUSE-ACTION is non-nil, invoke the button's mouse-action
 instead of its normal action; if the button has no mouse-action,
 the normal action is used instead."
   (let ((action (or (and use-mouse-action (button-get button 'mouse-action))
 		    (button-get button 'action))))
     (if (markerp action)
 	(save-selected-window
 	  (select-window (display-buffer (marker-buffer action)))
 	  (goto-char action)
 	  (recenter 0))
       (funcall action button))))
 
 (defun button-label (button)
   "Return BUTTON's text label."
   (buffer-substring-no-properties (button-start button) (button-end button)))
 
+(defun button-set-label (button label)
+  "Change BUTTON's text label to LABEL."
+  (save-excursion
+    (let ((old-start (button-start button))
+          (old-end (button-end button)))
+      (goto-char old-end)
+      (insert label)
+      (if (overlayp button)
+          (move-overlay button old-end (point))
+        (add-text-properties old-end (point) (text-properties-at button)))
+      (delete-region old-start old-end))))
+
 (defsubst button-type (button)
   "Return BUTTON's button-type."
   (button-get button 'type))
 
 (defun button-has-type-p (button type)
   "Return t if BUTTON has button-type TYPE, or one of TYPE's subtypes."
   (button-type-subtype-p (button-get button 'type) type))
 
 
 ;; Creating overlay buttons
 
 (defun make-button (beg end &rest properties)
   "Make a button from BEG to END in the current buffer.
 The remaining arguments form a sequence of PROPERTY VALUE pairs,
 specifying properties to add to the button.
 In addition, the keyword argument :type may be used to specify a
 button-type from which to inherit other properties; see
 `define-button-type'.
 
 Also see `make-text-button', `insert-button'."


Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#8898; Package emacs. (Tue, 10 Apr 2012 23:53:01 GMT) Full text and rfc822 format available.

Message #8 received at 8898 <at> debbugs.gnu.org (full text, mbox):

From: Lars Magne Ingebrigtsen <larsi <at> gnus.org>
To: Dmitry Kurochkin <dmitry.kurochkin <at> gmail.com>
Cc: 8898 <at> debbugs.gnu.org
Subject: Re: bug#8898: add a function to change button label
Date: Wed, 11 Apr 2012 01:51:05 +0200
Dmitry Kurochkin <dmitry.kurochkin <at> gmail.com> writes:

> In some cases it is very useful to change button text label.  Please
> consider applying the attached patch that implements `button-set-label'
> function to change button label.

Looks good to me.

A patch of this size requires signing FSF copyright papers.  Do you have
such paperwork on file, and if not, would you be willing to sign such
paperwork?

-- 
(domestic pets only, the antidote for overdose, milk.)
  bloggy blog http://lars.ingebrigtsen.no/




Added tag(s) wontfix. Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Thu, 25 Feb 2016 06:46:02 GMT) Full text and rfc822 format available.

bug closed, send any further explanations to 8898 <at> debbugs.gnu.org and Dmitry Kurochkin <dmitry.kurochkin <at> gmail.com> Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Thu, 25 Feb 2016 06:46:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Thu, 24 Mar 2016 11:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 9 years and 110 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.