aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiles Bader2004-01-01 04:20:43 +0000
committerMiles Bader2004-01-01 04:20:43 +0000
commit02c77ee91c2ba77634313783193bbfd18160ec52 (patch)
tree8fb4e0affcb3050d82069b98ee6b9e606bf7c20c
parent903a1a91c62ce450e1b19fb9af9cc0cad82a154f (diff)
downloademacs-02c77ee91c2ba77634313783193bbfd18160ec52.tar.gz
emacs-02c77ee91c2ba77634313783193bbfd18160ec52.zip
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-12
Add section on button package to lisp reference manual * lispref/display.texi (Buttons): New section.
-rw-r--r--lispref/ChangeLog4
-rw-r--r--lispref/display.texi363
2 files changed, 352 insertions, 15 deletions
diff --git a/lispref/ChangeLog b/lispref/ChangeLog
index 7619d6fe2c6..b3b4abf2460 100644
--- a/lispref/ChangeLog
+++ b/lispref/ChangeLog
@@ -1,3 +1,7 @@
12004-01-01 Miles Bader <miles@gnu.org>
2
3 * display.texi (Buttons): New section.
4
12003-12-31 Andreas Schwab <schwab@suse.de> 52003-12-31 Andreas Schwab <schwab@suse.de>
2 6
3 * numbers.texi (Math Functions): sqrt reports a domain-error 7 * numbers.texi (Math Functions): sqrt reports a domain-error
diff --git a/lispref/display.texi b/lispref/display.texi
index bd415b69697..25aea971638 100644
--- a/lispref/display.texi
+++ b/lispref/display.texi
@@ -20,18 +20,19 @@ that Emacs presents to the user.
20* Selective Display:: Hiding part of the buffer text (the old way). 20* Selective Display:: Hiding part of the buffer text (the old way).
21* Overlay Arrow:: Display of an arrow to indicate position. 21* Overlay Arrow:: Display of an arrow to indicate position.
22* Temporary Displays:: Displays that go away automatically. 22* Temporary Displays:: Displays that go away automatically.
23* Overlays:: Use overlays to highlight parts of the buffer. 23* Overlays:: Use overlays to highlight parts of the buffer.
24* Width:: How wide a character or string is on the screen. 24* Width:: How wide a character or string is on the screen.
25* Faces:: A face defines a graphics style for text characters: 25* Faces:: A face defines a graphics style for text characters:
26 font, colors, etc. 26 font, colors, etc.
27* Fringes:: Controlling window fringes. 27* Fringes:: Controlling window fringes.
28* Scroll Bars:: Controlling vertical scroll bars. 28* Scroll Bars:: Controlling vertical scroll bars.
29* Display Property:: Enabling special display features. 29* Display Property:: Enabling special display features.
30* Images:: Displaying images in Emacs buffers. 30* Images:: Displaying images in Emacs buffers.
31* Buttons:: Adding clickable buttons to Emacs buffers.
31* Blinking:: How Emacs shows the matching open parenthesis. 32* Blinking:: How Emacs shows the matching open parenthesis.
32* Inverse Video:: Specifying how the screen looks. 33* Inverse Video:: Specifying how the screen looks.
33* Usual Display:: The usual conventions for displaying nonprinting chars. 34* Usual Display:: The usual conventions for displaying nonprinting chars.
34* Display Tables:: How to specify other conventions. 35* Display Tables:: How to specify other conventions.
35* Beeping:: Audible signal to the user. 36* Beeping:: Audible signal to the user.
36* Window Systems:: Which window system is being used. 37* Window Systems:: Which window system is being used.
37@end menu 38@end menu
@@ -966,7 +967,7 @@ beginning and end. It also has properties that you can examine and set;
966these affect the display of the text within the overlay. 967these affect the display of the text within the overlay.
967 968
968@menu 969@menu
969* Overlay Properties:: How to read and set properties. 970* Overlay Properties:: How to read and set properties.
970 What properties do to the screen display. 971 What properties do to the screen display.
971* Managing Overlays:: Creating and moving overlays. 972* Managing Overlays:: Creating and moving overlays.
972* Finding Overlays:: Searching for overlays. 973* Finding Overlays:: Searching for overlays.
@@ -1424,10 +1425,10 @@ face name a special meaning in one frame if you wish.
1424* Standard Faces:: The faces Emacs normally comes with. 1425* Standard Faces:: The faces Emacs normally comes with.
1425* Defining Faces:: How to define a face with @code{defface}. 1426* Defining Faces:: How to define a face with @code{defface}.
1426* Face Attributes:: What is in a face? 1427* Face Attributes:: What is in a face?
1427* Attribute Functions:: Functions to examine and set face attributes. 1428* Attribute Functions:: Functions to examine and set face attributes.
1428* Merging Faces:: How Emacs combines the faces specified for a character. 1429* Merging Faces:: How Emacs combines the faces specified for a character.
1429* Font Selection:: Finding the best available font for a face. 1430* Font Selection:: Finding the best available font for a face.
1430* Face Functions:: How to define and examine faces. 1431* Face Functions:: How to define and examine faces.
1431* Auto Faces:: Hook for automatic face assignment. 1432* Auto Faces:: Hook for automatic face assignment.
1432* Font Lookup:: Looking up the names of available fonts 1433* Font Lookup:: Looking up the names of available fonts
1433 and information about them. 1434 and information about them.
@@ -2639,12 +2640,12 @@ this section describes several kinds of display specifications and what
2639they mean. 2640they mean.
2640 2641
2641@menu 2642@menu
2642* Specified Space:: Displaying one space with a specified width. 2643* Specified Space:: Displaying one space with a specified width.
2643* Other Display Specs:: Displaying an image; magnifying text; moving it 2644* Other Display Specs:: Displaying an image; magnifying text; moving it
2644 up or down on the page; adjusting the width 2645 up or down on the page; adjusting the width
2645 of spaces within text. 2646 of spaces within text.
2646* Display Margins:: Displaying text or images to the side of the main text. 2647* Display Margins:: Displaying text or images to the side of the main text.
2647* Conditional Display:: Making any of the above features conditional 2648* Conditional Display:: Making any of the above features conditional
2648 depending on some Lisp expression. 2649 depending on some Lisp expression.
2649@end menu 2650@end menu
2650 2651
@@ -3401,6 +3402,338 @@ only the cache for that frame is cleared. Otherwise all frames' caches
3401are cleared. 3402are cleared.
3402@end defun 3403@end defun
3403 3404
3405@node Buttons
3406@section Buttons
3407@cindex buttons in buffers
3408@cindex clickable buttons in buffers
3409
3410 The @emph{button} package defines functions for inserting and
3411manipulating clickable (with the mouse, or via keyboard commands)
3412buttons in Emacs buffers, such as might be used for help hyperlinks,
3413etc. Emacs uses buttons for the hyperlinks in help text and the like.
3414
3415A button is essentially a set of properties attached (via text
3416properties or overlays) to a region of text in an emacs buffer, which
3417are called its button properties. @xref{Button Properties}.
3418
3419One of the these properties (@code{action}) is a function, which will
3420be called when the user invokes it using the keyboard or the mouse.
3421The invoked function may then examine the button and use its other
3422properties as desired.
3423
3424In some ways the emacs button package duplicates functionality offered
3425by the widget package (@pxref{Top, , Introduction, widget, The Emacs
3426Widget Library}), but the button package has the advantage that it is
3427much faster, much smaller, and much simpler to use (for elisp
3428programmers---for users, the result is about the same). The extra
3429speed and space savings are useful mainly if you need to create many
3430buttons in a buffer (for instance an @code{*Apropos*} buffer uses
3431buttons to make entries clickable, and may contain many thousands of
3432entries).
3433
3434@menu
3435* Button Properties:: Button properties with special meanings.
3436* Button Types:: Defining common properties for classes of buttons.
3437* Making buttons:: Adding buttons to emacs buffers.
3438* Manipulating Buttons:: Getting and setting properties of buttons.
3439* Button Buffer Commands:: Buffer-wide commands and bindings for buttons.
3440* Manipulating Button Types::
3441@end menu
3442
3443@node Button Properties
3444@subsection Button Properties
3445@cindex button properties
3446
3447 Buttons have an associated list of properties defining their
3448appearance and behavior, and other arbitrary properties may be used
3449for application specific purposes.
3450
3451Some properties that have special meaning to the button package
3452include:
3453
3454@table @code
3455
3456@item action
3457The function to call when the user invokes the button, which is passed
3458the single argument @var{button}. By default this is @code{ignore},
3459which does nothing.
3460
3461@item mouse-action
3462This is similar to @code{action}, and when present, will be used
3463instead of @code{action} for button invocations resulting from
3464mouse-clicks (instead of the user hitting @key{RET}). If not
3465present, mouse-clicks use @code{action} instead.
3466
3467@item face
3468This is an emacs face controlling how buttons of this type are
3469displayed; by default this is the @code{button} face.
3470
3471@item mouse-face
3472This is an additional face which controls appearance during
3473mouse-overs (merged with the usual button face); by default this is
3474the usual emacs @code{highlight} face.
3475
3476@item keymap
3477The button's keymap, defining bindings active within the button
3478region. By default this is the usual button region keymap, stored
3479in the variable @code{button-map}, which defines @key{RET} and
3480@key{down-mouse-1} to invoke the button.
3481
3482@item type
3483The button-type of the button. When creating a button, this is
3484usually specified using the @code{:type} keyword argument.
3485@xref{Button Types}.
3486
3487@item help-echo
3488A string displayed by the emacs tooltip help system; by default,
3489@code{"mouse-2, RET: Push this button"}.
3490
3491@item button
3492All buttons have a non-@code{nil} @code{button} property, which may be useful
3493in finding regions of text that comprise buttons (which is what the
3494standard button functions do).
3495@end table
3496
3497There are other properties defined for the regions of text in a
3498button, but these are not generally interesting for typical uses.
3499
3500@node Button Types
3501@subsection Button Types
3502@cindex button types
3503
3504 Every button has a button @emph{type}, which defines default values
3505for the button's properties; button types are arranged in a hierarchy,
3506with specialized types inheriting from more general types, so that
3507it's easy to define special-purpose types of buttons for specific
3508tasks.
3509
3510@defun define-button-type name &rest properties
3511@tindex define-button-type
3512Define a `button type' called @var{name}. The remaining arguments
3513form a sequence of @var{property value} pairs, specifying default
3514property values for buttons with this type (a button's type may be set
3515by giving it a @code{type} property when creating the button, using
3516the @code{:type} keyword argument).
3517
3518In addition, the keyword argument @code{:supertype} may be used to
3519specify a button-type from which @var{name} inherits its default
3520property values. Note that this inheritance happens only when
3521@var{name} is defined; subsequent changes to a supertype are not
3522reflected in its subtypes.
3523@end defun
3524
3525Using @code{define-button-type} to define default properties for
3526buttons is not necessary, but it is is encouraged, since doing so
3527usually makes the resulting code clearer and more efficient.
3528
3529@node Making buttons
3530@subsection Making buttons
3531@cindex making buttons
3532
3533 Buttons are associated with a region of text, using an overlay or
3534text-properties to hold button-specific information, all of which are
3535initialized from the button's type (which defaults to the built-in
3536button type @code{button}). Like all emacs text, the appearance of
3537the button is governed by the @code{face} property; by default (via
3538the @code{face} property inherited from the @code{button} button-type)
3539this is a simple underline, like a typical web-page link.
3540
3541For convenience, there are two sorts of button-creation functions,
3542those that add button properties to an existing region of a buffer,
3543called @code{make-...button}, and those also insert the button text,
3544called @code{insert-...button}.
3545
3546The button-creation functions all take the @code{&rest} argument
3547@var{properties}, which should be a sequence of @var{property value}
3548pairs, specifying properties to add to the button; see @ref{Button
3549Properties}. In addition, the keyword argument @code{:type} may be
3550used to specify a button-type from which to inherit other properties;
3551see @ref{Button Types}. Any properties not explicitly specified
3552during creation will be inherited from the button's type (if the type
3553defines such a property).
3554
3555The following functions add a button using an overlay
3556(@pxref{Overlays}) to hold the button properties:
3557
3558@defun make-button beg end &rest properties
3559@tindex make-button
3560Make a button from @var{beg} to @var{end} in the current buffer.
3561@end defun
3562
3563@defun insert-button label &rest properties
3564@tindex insert-button
3565Insert a button with the label @var{label}.
3566@end defun
3567
3568The following functions are similar, but use emacs text-properties
3569(@pxref{Text Properties}) to hold the button properties, making the
3570button actually part of the text instead of being a property of the
3571buffer (using text-properties is usually faster than using overlays,
3572so this may be preferable when creating large numbers of buttons):
3573
3574@defun make-text-button beg end &rest properties
3575@tindex make-text-button
3576Make a button from @var{beg} to @var{end} in the current buffer, using
3577text-properties.
3578@end defun
3579
3580@defun insert-text-button label &rest properties
3581@tindex insert-text-button
3582Insert a button with the label @var{label}, using text-properties.
3583@end defun
3584
3585Buttons using text-properties retain no markers into the buffer are
3586retained, which is important for speed in cases where there are
3587extremely large numbers of buttons.
3588
3589@node Manipulating Buttons
3590@subsection Manipulating Buttons
3591@cindex manipulating buttons
3592
3593These are functions for getting and setting properties of buttons.
3594Often these are used by a button's invocation function to determine
3595what to do.
3596
3597Where a @var{button} parameter is specified, it means an object
3598referring to a specific button, either an overlay (for overlay
3599buttons), or a buffer-position or marker (for text property buttons).
3600Such an object is passed as the first argument to a button's
3601invocation function when it is invoked.
3602
3603@defun button-start button
3604@tindex button-start
3605Return the position at which @var{button} starts.
3606@end defun
3607
3608@defun button-end button
3609@tindex button-end
3610Return the position at which @var{button} ends.
3611@end defun
3612
3613@defun button-get button prop
3614@tindex button-get
3615Get the property of button @var{button} named @var{prop}.
3616@end defun
3617
3618@defun button-put button prop val
3619@tindex button-put
3620Set @var{button}'s @var{prop} property to @var{val}.
3621@end defun
3622
3623@defun button-activate button &optional use-mouse-action
3624@tindex button-activate
3625Call @var{button}'s @code{action} property (i.e., invoke it). If
3626@var{use-mouse-action} is non-@code{nil}, try to invoke the button's
3627@code{mouse-action} property instead of @code{action}, but if the
3628button has no @code{mouse-action} property, use @code{action} as
3629normal.
3630@end defun
3631
3632@defun button-label button
3633@tindex button-label
3634Return @var{button}'s text label.
3635@end defun
3636
3637@defun button-type button
3638@tindex button-type
3639Return @var{button}'s button-type.
3640@end defun
3641
3642@defun button-has-type-p button type
3643@tindex button-has-type-p
3644Return @code{t} if @var{button} has button-type @var{type}, or one of
3645@var{type}'s subtypes.
3646@end defun
3647
3648@defun button-at pos
3649@tindex button-at
3650Return the button at position @var{pos} in the current buffer, or @code{nil}.
3651@end defun
3652
3653@node Button Buffer Commands
3654@subsection Button Buffer Commands
3655@cindex button buffer commands
3656
3657These are commands and functions for locating and operating on
3658buttons in an emacs buffer.
3659
3660@code{push-button} is the command that a user uses to actually `push'
3661a button, and is bound by default in the button itself to @key{RET}
3662and to @key{mouse-down-1} using a region-specific keymap. Commands
3663that are useful outside the buttons itself, such as
3664@code{forward-button} and @code{backward-button} are additionally
3665available in the keymap stored in @code{button-buffer-map}; a mode
3666which uses buttons may want to use @code{button-buffer-map} as a
3667parent keymap for its keymap.
3668
3669@deffn Command push-button &optional pos use-mouse-action
3670@tindex push-button
3671Perform the action specified by a button at location @var{pos}.
3672@var{pos} may be either a buffer position or a mouse-event. If
3673@var{use-mouse-action} is non-@code{nil}, try to invoke the button's
3674@code{mouse-action} property instead of @code{action}, but if the
3675button has no @code{mouse-action} property, use @code{action} as
3676normal. @var{pos} defaults to point, except when `push-button' is
3677invoked interactively as the result of a mouse-event, in which case,
3678the mouse event is used. If there's no button at @var{pos}, do
3679nothing and return @code{nil}, otherwise return @code{t}.
3680@end deffn
3681
3682@deffn Command forward-button n &optional wrap display-message
3683@tindex forward-button
3684Move to the @var{n}th next button, or @var{n}th previous button if
3685@var{n} is negative. If @var{n} is zero, move to the start of any
3686button at point. If @var{wrap} is non-@code{nil}, moving past either
3687end of the buffer continues from the other end. If
3688@var{display-message} is non-@code{nil}, the button's help-echo string
3689is displayed. Any button with a non-@code{nil} `skip' property is
3690skipped over. Returns the button found.
3691@end deffn
3692
3693@deffn Command backward-button n &optional wrap display-message
3694@tindex backward-button
3695Move to the @var{n}th previous button, or @var{n}th next button if
3696@var{n} is negative. If @var{n} is zero, move to the start of any
3697button at point. If @var{wrap} is non-@code{nil}, moving past either
3698end of the buffer continues from the other end. If
3699@var{display-message} is non-@code{nil}, the button's help-echo string
3700is displayed. Any button with a non-@code{nil} `skip' property is
3701skipped over. Returns the button found.
3702@end deffn
3703
3704@defun next-button pos &optional count-current
3705@tindex next-button
3706Return the next button after position @var{pos} in the current buffer.
3707If @var{count-current} is non-@code{nil}, count any button at
3708@var{pos} in the search, instead of starting at the next button.
3709@end defun
3710
3711@defun previous-button pos &optional count-current
3712@tindex previous-button
3713Return the @var{n}th button before position @var{pos} in the current
3714buffer. If @var{count-current} is non-@code{nil}, count any button at
3715@var{pos} in the search, instead of starting at the next button.
3716@end defun
3717
3718@node Manipulating Button Types
3719@subsection Manipulating Button Types
3720@cindex manipulating button types
3721
3722@defun button-type-put type prop val
3723@tindex button-type-put
3724Set the button-type @var{type}'s @var{prop} property to @var{val}.
3725@end defun
3726
3727@defun button-type-get type prop
3728@tindex button-type-get
3729Get the property of button-type @var{type} named @var{prop}.
3730@end defun
3731
3732@defun button-type-subtype-p type supertype
3733@tindex button-type-subtype-p
3734Return @code{t} if button-type @var{type} is a subtype of @var{supertype}.
3735@end defun
3736
3404@node Blinking 3737@node Blinking
3405@section Blinking Parentheses 3738@section Blinking Parentheses
3406@cindex parenthesis matching 3739@cindex parenthesis matching
@@ -3595,9 +3928,9 @@ force redisplay of the mode line using a new display table, call
3595@code{force-mode-line-update} (@pxref{Mode Line Format}). 3928@code{force-mode-line-update} (@pxref{Mode Line Format}).
3596 3929
3597@menu 3930@menu
3598* Display Table Format:: What a display table consists of. 3931* Display Table Format:: What a display table consists of.
3599* Active Display Table:: How Emacs selects a display table to use. 3932* Active Display Table:: How Emacs selects a display table to use.
3600* Glyphs:: How to define a glyph, and what glyphs mean. 3933* Glyphs:: How to define a glyph, and what glyphs mean.
3601@end menu 3934@end menu
3602 3935
3603@node Display Table Format 3936@node Display Table Format