From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Dmitry Kurochkin Newsgroups: gmane.emacs.bugs Subject: bug#8898: add a function to change button label Date: Mon, 20 Jun 2011 00:26:43 +0400 Message-ID: <87aadd5zzw.fsf@gmail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: dough.gmane.org 1308515255 22941 80.91.229.12 (19 Jun 2011 20:27:35 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sun, 19 Jun 2011 20:27:35 +0000 (UTC) To: 8898@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Jun 19 22:27:28 2011 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1QYOab-0005hD-6u for geb-bug-gnu-emacs@m.gmane.org; Sun, 19 Jun 2011 22:27:25 +0200 Original-Received: from localhost ([::1]:54870 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QYOaa-00067c-EA for geb-bug-gnu-emacs@m.gmane.org; Sun, 19 Jun 2011 16:27:24 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:39873) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QYOaH-00066w-EE for bug-gnu-emacs@gnu.org; Sun, 19 Jun 2011 16:27:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QYOaF-0003KV-QF for bug-gnu-emacs@gnu.org; Sun, 19 Jun 2011 16:27:05 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:48632) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QYOaF-0003Jf-8T for bug-gnu-emacs@gnu.org; Sun, 19 Jun 2011 16:27:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.69) (envelope-from ) id 1QYOaE-0004yH-Mc; Sun, 19 Jun 2011 16:27:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Dmitry Kurochkin Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 19 Jun 2011 20:27:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 8898 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: submit@debbugs.gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.130851518119060 (code B ref -1); Sun, 19 Jun 2011 20:27:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 19 Jun 2011 20:26:21 +0000 Original-Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QYOZY-0004xN-Ma for submit@debbugs.gnu.org; Sun, 19 Jun 2011 16:26:21 -0400 Original-Received: from mail-bw0-f44.google.com ([209.85.214.44]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QYOZX-0004xB-2u for submit@debbugs.gnu.org; Sun, 19 Jun 2011 16:26:19 -0400 Original-Received: by bwz13 with SMTP id 13so3092450bwz.3 for ; Sun, 19 Jun 2011 13:26:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:to:subject:user-agent:date:message-id :mime-version:content-type; bh=T4ZaCtPKFWim0Vq8uEclQ4d09Wu5FdTiuY1BvqxfEoE=; b=ioRGqfhM5H9T3U46Ifox6lLTd0zxywYGfge4+GDcT6ziOOQIyRICAiuEbgqcmDfuIt IH1XqyicDs4XbuxI9L67rfDa7Pf4r+k0XYhuAB3KjP5eFhxud0rNl/owT6YFXPT9qbUB bzIdInvy+GbK8S4vEB/WMcxiK+unScg0vDGWM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:subject:user-agent:date:message-id:mime-version :content-type; b=bwd2+VrIiEhzoX9IWjCPaPkmPdrbT/z5800/kz4psFsYyp3t3zuLmSKoSqSJPbpADO EepJao6HGwU65tIQRtWjXgl9nldZRdgTaBSk7Py0P1q3az38hiz3f/hOrl0yJgJYOWwv ZMTTeNMXB6P8Smk0Jm7v6k2h/c1xO2cXMCKsQ= Original-Received: by 10.204.7.91 with SMTP id c27mr1872958bkc.67.1308515173121; Sun, 19 Jun 2011 13:26:13 -0700 (PDT) Original-Received: from localhost ([91.144.186.21]) by mx.google.com with ESMTPS id x6sm3840268bkv.0.2011.06.19.13.26.11 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 19 Jun 2011 13:26:12 -0700 (PDT) User-Agent: Notmuch/0.5-237-gf6d8cdb (http://notmuchmail.org) Emacs/23.3.1 (x86_64-pc-linux-gnu) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list Resent-Date: Sun, 19 Jun 2011 16:27:02 -0400 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:47332 Archived-At: --=-=-= 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 --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=button-set-label.patch 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'." --=-=-=--