unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Dmitry Kurochkin <dmitry.kurochkin@gmail.com>
To: 8898@debbugs.gnu.org
Subject: bug#8898: add a function to change button label
Date: Mon, 20 Jun 2011 00:26:43 +0400	[thread overview]
Message-ID: <87aadd5zzw.fsf@gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 238 bytes --]

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

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: button-set-label.patch --]
[-- Type: text/x-diff, Size: 3656 bytes --]

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))
 
 \f
 ;; 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'."


             reply	other threads:[~2011-06-19 20:26 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-19 20:26 Dmitry Kurochkin [this message]
2012-04-10 23:51 ` bug#8898: add a function to change button label Lars Magne Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87aadd5zzw.fsf@gmail.com \
    --to=dmitry.kurochkin@gmail.com \
    --cc=8898@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).