GNU bug report logs - #12817
24.2; The button library does not work on the header line

Previous Next

Package: emacs;

Reported by: Damien Cassou <damien.cassou <at> gmail.com>

Date: Tue, 6 Nov 2012 17:05:01 UTC

Severity: normal

Found in version 24.2

Done: Stefan Monnier <monnier <at> iro.umontreal.ca>

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 12817 in the body.
You can then email your comments to 12817 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 bug-gnu-emacs <at> gnu.org:
bug#12817; Package emacs. (Tue, 06 Nov 2012 17:05:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Damien Cassou <damien.cassou <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Tue, 06 Nov 2012 17:05:01 GMT) Full text and rfc822 format available.

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

From: Damien Cassou <damien.cassou <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 24.2; The button library does not work on the header line
Date: Tue, 06 Nov 2012 17:59:35 +0100
Hi,

the button library does not work if a button is created on the
header-line:

  (require 'button)

  (defun my-button-action (button)
    (message "HERE I AM"))

  (define-button-type 'my-button-type
    'action #'my-button-action
    'follow-link t)

  (setq test-button (copy-sequence "CLICK ME"))

  (make-text-button test-button nil
                    'type 'my-button-type)

  (setq header-line-format test-button)

After evaluating these lines, a button appear with the text "CLICK ME"
in blue and underlined. But clicking this button does nothing. I was
expecting that clicking the button would trigger 'my-button-action and
display the message "HERE I AM".

There is a library that makes 'button work on header-line: 
https://raw.github.com/tarsius/header-button/master/header-button.el

Thank you

In GNU Emacs 24.2.1 (i686-pc-linux-gnu, GTK+ Version 2.24.13)
 of 2012-11-06 on dubnium, modified by Debian
Windowing system distributor `The X.Org Foundation', version 11.0.11300000
Configured using:
 `configure '--build' 'i686-linux-gnu' '--build' 'i686-linux-gnu'
 '--prefix=/usr' '--sharedstatedir=/var/lib' '--libexecdir=/usr/lib'
 '--localstatedir=/var/lib' '--infodir=/usr/share/info'
 '--mandir=/usr/share/man' '--with-pop=yes'
 '--enable-locallisppath=/etc/emacs24:/etc/emacs:/usr/local/share/emacs/24.2/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/24.2/site-lisp:/usr/share/emacs/site-lisp'
 '--with-crt-dir=/usr/lib/i386-linux-gnu' '--with-x=yes'
 '--with-x-toolkit=gtk' '--with-toolkit-scroll-bars'
 'build_alias=i686-linux-gnu' 'CFLAGS=-g -O2 -fstack-protector
 --param=ssp-buffer-size=4 -Wformat -Werror=format-security -Wall'
 'LDFLAGS=-Wl,-Bsymbolic-functions -Wl,-z,relro'
 'CPPFLAGS=-D_FORTIFY_SOURCE=2''

Important settings:
  value of $LC_ALL: nil
  value of $LC_COLLATE: nil
  value of $LC_CTYPE: nil
  value of $LC_MESSAGES: nil
  value of $LC_MONETARY: nil
  value of $LC_NUMERIC: nil
  value of $LC_TIME: nil
  value of $LANG: en_US.UTF-8
  value of $XMODIFIERS: nil
  locale-coding-system: utf-8-unix
  default enable-multibyte-characters: t

Major mode: Lisp Interaction

Minor modes in effect:
  tooltip-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  transient-mark-mode: t

Recent input:
<help-echo> <down-mouse-1> <mouse-1> <down-mouse-4> 
<mouse-4> <double-down-mouse-4> <double-mouse-4> <triple-down-mouse-4> 
<triple-mouse-4> C-n C-n C-n C-n C-n C-n C-n C-n C-n 
C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-M-x C-l C-l 
C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n 
C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-M-x C-n 
C-n C-n C-n C-n C-n C-n C-n C-M-x C-n C-l C-l C-n C-n 
C-n C-n C-n C-a C-SPC M-> C-w C-y M-y C-p C-k C-M-x 
C-y C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p 
C-p C-p C-p C-p C-l C-a C-SPC C-n C-n C-f C-f C-x r 
k C-p C-p <tab> C-n <tab> C-n <tab> M-v M-v C-v C-v 
C-l C-p C-p C-p C-e C-n C-a C-k C-n C-SPC C-n C-n C-f 
C-f C-f C-x r k C-p <tab> C-n <tab> C-e C-x C-e q C-p 
C-p C-p C-p C-x C-e C-n C-n C-n C-n C-e C-x C-e <help-echo> 
<down-mouse-1> <mouse-1> <down-mouse-1> <mouse-1> <help-echo> 
<down-mouse-1> <mouse-1> C-n C-n C-n C-n C-a C-SPC 
C-n C-n C-n C-f C-f C-f C-x r k C-e C-x C-e <help-echo> 
<help-echo> <help-echo> <down-mouse-1> <mouse-1> <help-echo> 
<down-mouse-4> <mouse-4> <down-mouse-4> <mouse-4> <down-mouse-4> 
<mouse-4> <down-mouse-4> <mouse-4> <down-mouse-4> <mouse-4> 
<down-mouse-4> <mouse-4> <double-down-mouse-4> <double-mouse-4> 
<triple-down-mouse-4> <triple-mouse-4> <triple-down-mouse-4> 
<triple-mouse-4> <down-mouse-1> <mouse-movement> <drag-mouse-1> 
C-x 1 <down-mouse-1> <mouse-movement> <mouse-1> <help-echo> 
<down-mouse-1> <mouse-1> <help-echo> <down-mouse-1> 
<mouse-1> <help-echo> <down-mouse-1> <mouse-1> <help-echo> 
<down-mouse-1> <mouse-1> <help-echo> <down-mouse-1> 
<mouse-1> <help-echo> <down-mouse-5> <mouse-5> <double-down-mouse-5> 
<double-mouse-5> <triple-down-mouse-5> <triple-mouse-5> 
<down-mouse-1> <mouse-1> <down-mouse-1> <mouse-1> C-p 
C-p C-SPC C-p C-p C-p C-p C-a C-w C-x C-o C-n C-SPC 
M-> <f2> <f2> <f2> C-x 1 C-x 1 C-p C-p C-p <tab> C-n 
<tab> C-n <tab> <down-mouse-1> <mouse-1> C-h k <f2> 
<f2> C-x 1 <down-mouse-1> <mouse-1> C-l <down-mouse-1> 
<mouse-movement> <drag-mouse-1> M-x r e p o r t - e 
m a <tab> <tab> <return>

Recent messages:
This button labeled `No me!' belongs to category `my-header-button'
byte-code: Beginning of buffer
Mark set
This button labeled `Click me!' belongs to category `header-button' [2 times]
This button labeled `No me!' belongs to category `my-header-button'
Mark set [2 times]
Autoscrolling is on.
Type C-x 1 to delete the help window.
Mark set
Making completion list...

Load-path shadows:
/usr/share/emacs/24.2/site-lisp/cmake-data/cmake-mode hides /usr/share/emacs/site-lisp/cmake-mode
/usr/share/emacs/24.2/site-lisp/dictionaries-common/flyspell hides /usr/share/emacs/24.2/lisp/textmodes/flyspell
/usr/share/emacs/24.2/site-lisp/dictionaries-common/ispell hides /usr/share/emacs/24.2/lisp/textmodes/ispell

Features:
(shadow sort gnus-util mail-extr emacsbug message format-spec rfc822 mml
mml-sec mm-decode mm-bodies mm-encode mail-parse rfc2231 mailabbrev
gmm-utils mailheader sendmail regexp-opt rfc2047 rfc2045 ietf-drums
mm-util mail-prsvr mail-utils two-column debug rect help-mode view
help-fns find-func jka-compr info easymenu edmacro kmacro cl time-date
tooltip ediff-hook vc-hooks lisp-float-type mwheel x-win x-dnd tool-bar
dnd fontset image fringe lisp-mode register page menu-bar rfn-eshadow
timer select scroll-bar mouse jit-lock font-lock syntax facemenu
font-core frame cham georgian utf-8-lang misc-lang vietnamese tibetan
thai tai-viet lao korean japanese hebrew greek romanian slovak czech
european ethiopic indian cyrillic chinese case-table epa-hook
jka-cmpr-hook help simple abbrev minibuffer loaddefs button faces
cus-face files text-properties overlay sha1 md5 base64 format env
code-pages mule custom widget hashtable-print-readable backquote
make-network-process dbusbind dynamic-setting system-font-setting
font-render-setting move-toolbar gtk x-toolkit x multi-tty emacs)




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#12817; Package emacs. (Tue, 04 Dec 2012 20:20:02 GMT) Full text and rfc822 format available.

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

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Damien Cassou <damien.cassou <at> gmail.com>
Cc: 12817 <at> debbugs.gnu.org
Subject: Re: bug#12817: 24.2;
	The button library does not work on the header line
Date: Tue, 04 Dec 2012 15:19:46 -0500
> the button library does not work if a button is created on the header-line:

>   (require 'button)
>   (defun my-button-action (button)
>     (message "HERE I AM"))
>   (define-button-type 'my-button-type
>     'action #'my-button-action
>     'follow-link t)
>   (setq test-button (copy-sequence "CLICK ME"))
>   (make-text-button test-button nil
>                     'type 'my-button-type)
>   (setq header-line-format test-button)

> After evaluating these lines, a button appear with the text "CLICK ME"
> in blue and underlined. But clicking this button does nothing. I was
> expecting that clicking the button would trigger 'my-button-action and
> display the message "HERE I AM".

Sounds like a reasonable expectation.

> There is a library that makes 'button work on header-line: 
> https://raw.github.com/tarsius/header-button/master/header-button.el

Would someone be able to turn the above code into a patch to button.el
that makes your sample code work (i.e. make `make-text-button' work in
a header, instead of introducing an ad-hoc `header-button-format')?


        Stefan


PS: BTW, the "follow-link does not work here" comment points at
a misfeature of follow-link, indeed.  I think `follow-link' should be
implemented in function-key-map rather than in mouse-drag-region.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#12817; Package emacs. (Wed, 05 Dec 2012 20:40:01 GMT) Full text and rfc822 format available.

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

From: Jonas Bernoulli <jonas <at> bernoul.li>
To: 12817 <at> debbugs.gnu.org
Cc: Damien Cassou <damien.cassou <at> gmail.com>
Subject: Re: bug#12817: 24.2;
	The button library does not work on the header line
Date: Wed, 05 Dec 2012 21:39:15 +0100
[Message part 1 (text/plain, inline)]
The attached patch allows inserting buttons into the header-line as well
as the mode-line.  I haven't tested it much but it appears to work.

As you suggested it doesn't use a function such as
`header-button-format'.  Instead `make-text-button' was changed to
return a useful value when BEG is a string: the propertized string.

,----
| (setq header-line-format
|       (make-text-button "test" nil
|                         'action (lambda (button)
|                                   (message "Button: %s" button))))
`----

The above is enough now to insert a button in the header-line or
mode-line.  No need for an intermediate variable to hold the string.
Additionally the following changes are needed so that clicking the
button actually does something.

Add an additional kind of "button object" that is used internally and
passed to the button action function: "area buttons" (analogously to
`posn-area').  Normally these have the form (STRING . STRING-POS), where
STRING is the propertized string and STRING-POS is list of the form
returned by `event-start'.  STRING-POS might be useful in actions but
isn't used internally.  Area button objects can also be just a string.

[mode-line mouse-2] and [header-line mouse-2] are bound to push-button
just like [mouse-2].  [follow-link] is not actually used at all.  (I
think it was used instead of [mouse-2] in the past, but I might be
wrong).

I don't know whether binding these events might cause problems for
regular buttons, but it does not appear to be the case.

(Maybe using follow-link instead and extending it to work in the
header-line and mode-line would be better; but I know to little about
that.  The little I do know tells me doing so would probably not be
worth the effort.)

`push-button', `button-get', `button-put', `button-label' are taught to
deal with area buttons.  Using `button-start', `button-end' and
`button-at' with an area button causes an error.  Of the "button
creating functions" only `make-text-button' is useful for area buttons.
`[next|previous|forward|backward]-button' also cannot be used.

The patch is against 24.3.50 from a few days ago but if necessary I can
redo it against a different version.

[0001-area-buttons.patch (text/x-diff, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#12817; Package emacs. (Thu, 06 Dec 2012 07:39:01 GMT) Full text and rfc822 format available.

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

From: Damien Cassou <damien.cassou <at> gmail.com>
To: Jonas Bernoulli <jonas <at> bernoul.li>
Cc: 12817 <at> debbugs.gnu.org
Subject: Re: bug#12817: 24.2;
	The button library does not work on the header line
Date: Thu, 6 Dec 2012 08:38:01 +0100
[Message part 1 (text/plain, inline)]
Thank you very much Jonas

Damien Cassou
http://damiencassou.seasidehosting.st
On Dec 5, 2012 9:39 PM, "Jonas Bernoulli" <jonas <at> bernoul.li> wrote:

> The attached patch allows inserting buttons into the header-line as well
> as the mode-line.  I haven't tested it much but it appears to work.
>
> As you suggested it doesn't use a function such as
> `header-button-format'.  Instead `make-text-button' was changed to
> return a useful value when BEG is a string: the propertized string.
>
> ,----
> | (setq header-line-format
> |       (make-text-button "test" nil
> |                         'action (lambda (button)
> |                                   (message "Button: %s" button))))
> `----
>
> The above is enough now to insert a button in the header-line or
> mode-line.  No need for an intermediate variable to hold the string.
> Additionally the following changes are needed so that clicking the
> button actually does something.
>
> Add an additional kind of "button object" that is used internally and
> passed to the button action function: "area buttons" (analogously to
> `posn-area').  Normally these have the form (STRING . STRING-POS), where
> STRING is the propertized string and STRING-POS is list of the form
> returned by `event-start'.  STRING-POS might be useful in actions but
> isn't used internally.  Area button objects can also be just a string.
>
> [mode-line mouse-2] and [header-line mouse-2] are bound to push-button
> just like [mouse-2].  [follow-link] is not actually used at all.  (I
> think it was used instead of [mouse-2] in the past, but I might be
> wrong).
>
> I don't know whether binding these events might cause problems for
> regular buttons, but it does not appear to be the case.
>
> (Maybe using follow-link instead and extending it to work in the
> header-line and mode-line would be better; but I know to little about
> that.  The little I do know tells me doing so would probably not be
> worth the effort.)
>
> `push-button', `button-get', `button-put', `button-label' are taught to
> deal with area buttons.  Using `button-start', `button-end' and
> `button-at' with an area button causes an error.  Of the "button
> creating functions" only `make-text-button' is useful for area buttons.
> `[next|previous|forward|backward]-button' also cannot be used.
>
> The patch is against 24.3.50 from a few days ago but if necessary I can
> redo it against a different version.
>
>
[Message part 2 (text/html, inline)]

Reply sent to Stefan Monnier <monnier <at> iro.umontreal.ca>:
You have taken responsibility. (Thu, 06 Dec 2012 20:12:01 GMT) Full text and rfc822 format available.

Notification sent to Damien Cassou <damien.cassou <at> gmail.com>:
bug acknowledged by developer. (Thu, 06 Dec 2012 20:12:02 GMT) Full text and rfc822 format available.

Message #19 received at 12817-done <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Jonas Bernoulli <jonas <at> bernoul.li>
Cc: 12817-done <at> debbugs.gnu.org, Damien Cassou <damien.cassou <at> gmail.com>
Subject: Re: bug#12817: 24.2;
	The button library does not work on the header line
Date: Thu, 06 Dec 2012 15:11:30 -0500
> The attached patch allows inserting buttons into the header-line as well
> as the mode-line.  I haven't tested it much but it appears to work.
> As you suggested it doesn't use a function such as
> `header-button-format'.  Instead `make-text-button' was changed to
> return a useful value when BEG is a string: the propertized string.

Thanks, installed, after simplifying it a bit to just use STRING rather
than (STRING . STRING-POS).


        Stefan




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Fri, 04 Jan 2013 12:24:02 GMT) Full text and rfc822 format available.

This bug report was last modified 12 years and 229 days ago.

Previous Next


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