Mercurial > emacs
comparison lispref/text.texi @ 59504:66f927c186ac
(Links and Mouse-1): Rename section from Enabling
Mouse-1 to Following Links. Change xrefs.
Add examples for define-button-type and define-widget.
author | Kim F. Storm <storm@cua.dk> |
---|---|
date | Wed, 12 Jan 2005 15:32:47 +0000 |
parents | d8cf3d034936 |
children | 8f17a7431c8a |
comparison
equal
deleted
inserted
replaced
59503:97fd558f25ad | 59504:66f927c186ac |
---|---|
2429 them back. | 2429 them back. |
2430 * Lazy Properties:: Computing text properties in a lazy fashion | 2430 * Lazy Properties:: Computing text properties in a lazy fashion |
2431 only when text is examined. | 2431 only when text is examined. |
2432 * Clickable Text:: Using text properties to make regions of text | 2432 * Clickable Text:: Using text properties to make regions of text |
2433 do something when you click on them. | 2433 do something when you click on them. |
2434 * Enabling Mouse-1 to Follow Links:: | 2434 * Links and Mouse-1:: How to make @key{Mouse-1} follow a link. |
2435 How to make @key{mouse-1} follow a link. | |
2436 * Fields:: The @code{field} property defines | 2435 * Fields:: The @code{field} property defines |
2437 fields within the buffer. | 2436 fields within the buffer. |
2438 * Not Intervals:: Why text properties do not use | 2437 * Not Intervals:: Why text properties do not use |
2439 Lisp-visible text intervals. | 2438 Lisp-visible text intervals. |
2440 @end menu | 2439 @end menu |
3388 This method makes it possible to define different commands for various | 3387 This method makes it possible to define different commands for various |
3389 clickable pieces of text. Also, the major mode definition (or the | 3388 clickable pieces of text. Also, the major mode definition (or the |
3390 global definition) remains available for the rest of the text in the | 3389 global definition) remains available for the rest of the text in the |
3391 buffer. | 3390 buffer. |
3392 | 3391 |
3393 @node Enabling Mouse-1 to Follow Links | 3392 @node Links and Mouse-1 |
3394 @subsection Enabling Mouse-1 to Follow Links | 3393 @subsection Links and Mouse-1 |
3395 @cindex follow links | 3394 @cindex follow links |
3395 @cindex mouse-1 | |
3396 | 3396 |
3397 The normal Emacs command for activating text in read-only buffers is | 3397 The normal Emacs command for activating text in read-only buffers is |
3398 @key{Mouse-2}, which includes following textual links. However, most | 3398 @key{Mouse-2}, which includes following textual links. However, most |
3399 graphical applications use @key{Mouse-1} for following links. For | 3399 graphical applications use @key{Mouse-1} for following links. For |
3400 compatibility, @key{Mouse-1} follows links in Emacs too, when you | 3400 compatibility, @key{Mouse-1} follows links in Emacs too, when you |
3401 click on a link quickly without moving the mouse. The user can | 3401 click on a link quickly without moving the mouse. The user can |
3402 customize this behaviour through the variable | 3402 customize this behaviour through the variable |
3403 @code{mouse-1-click-follows-link}. | 3403 @code{mouse-1-click-follows-link}. |
3404 | 3404 |
3405 To define text as a link at the Lisp level, you should bind | 3405 To define text as a link at the Lisp level, you should bind the |
3406 @key{Mouse-2} to a command to follow the link. Then, to indicate | 3406 @code{mouse-2} event to a command to follow the link. Then, to |
3407 that @key{Mouse-1} should also follow the link, here is what you do: | 3407 indicate that @key{Mouse-1} should also follow the link, here is what |
3408 you do: | |
3408 | 3409 |
3409 @table @asis | 3410 @table @asis |
3410 @item @code{follow-link} property | 3411 @item @code{follow-link} property |
3411 If the clickable text has a non-@code{nil} @code{follow-link} text or overlay | 3412 If the clickable text has a non-@code{nil} @code{follow-link} text or overlay |
3412 property, the value of that property determines what to do. | 3413 property, the value of that property determines what to do. |
3477 @end table | 3478 @end table |
3478 | 3479 |
3479 To define @key{Mouse-1} to activate a button defined with | 3480 To define @key{Mouse-1} to activate a button defined with |
3480 @code{define-button-type}, give the button a @code{follow-link} | 3481 @code{define-button-type}, give the button a @code{follow-link} |
3481 property with a value as specified above to determine how to follow | 3482 property with a value as specified above to determine how to follow |
3482 the link. | 3483 the link. For example, here is how Help mode handles @key{Mouse-1}: |
3483 @c ??? That is not clear. This needs an example or an xref. | 3484 |
3485 @smallexample | |
3486 (define-button-type 'help-xref | |
3487 'follow-link t | |
3488 'action #'help-button-action) | |
3489 @end smallexample | |
3484 | 3490 |
3485 To define @key{Mouse-1} on a widget defined with | 3491 To define @key{Mouse-1} on a widget defined with |
3486 @code{define-widget}, give the widget a @code{:follow-link} property | 3492 @code{define-widget}, give the widget a @code{:follow-link} property |
3487 with a value as specified above to determine how to follow the link. | 3493 with a value as specified above to determine how to follow the link. |
3488 @c ??? That is not clear. This needs an example or an xref. | 3494 |
3495 For example, here is how the @code{link} widget specifies that | |
3496 a @key{Mouse-1} click shall be translated to @key{RET}: | |
3497 | |
3498 @smallexample | |
3499 (define-widget 'link 'item | |
3500 "An embedded link." | |
3501 :button-prefix 'widget-link-prefix | |
3502 :button-suffix 'widget-link-suffix | |
3503 :follow-link "\C-m" | |
3504 :help-echo "Follow the link." | |
3505 :format "%[%t%]") | |
3506 @end smallexample | |
3489 | 3507 |
3490 @defun mouse-on-link-p pos | 3508 @defun mouse-on-link-p pos |
3491 @tindex mouse-on-link-p | 3509 @tindex mouse-on-link-p |
3492 This function returns non-@code{nil} if position @var{pos} in the | 3510 This function returns non-@code{nil} if position @var{pos} in the |
3493 current buffer is on a link. | 3511 current buffer is on a link. |