Mercurial > emacs
comparison lispref/text.texi @ 59524:8f17a7431c8a
(Links and Mouse-1): Clarify text.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Thu, 13 Jan 2005 19:59:22 +0000 |
parents | 66f927c186ac |
children | 2a346f1b2a9f |
comparison
equal
deleted
inserted
replaced
59523:72a78ee72ab9 | 59524:8f17a7431c8a |
---|---|
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 the | 3405 To define text as a link at the Lisp level, you should bind the |
3406 @code{mouse-2} event to a command to follow the link. Then, to | 3406 @code{mouse-2} event to a command to follow the link. Then, to indicate that |
3407 indicate that @key{Mouse-1} should also follow the link, here is what | 3407 @key{Mouse-1} should also follow the link, you should specify a |
3408 you do: | 3408 @code{follow-link} condition either as a text property or as a key |
3409 binding: | |
3409 | 3410 |
3410 @table @asis | 3411 @table @asis |
3411 @item @code{follow-link} property | 3412 @item @code{follow-link} property |
3412 If the clickable text has a non-@code{nil} @code{follow-link} text or overlay | 3413 If the clickable text has a non-@code{nil} @code{follow-link} text or overlay |
3413 property, the value of that property determines what to do. | 3414 property, that specifies the condition. |
3414 | 3415 |
3415 @item @code{follow-link} event | 3416 @item @code{follow-link} event |
3416 If there is a binding for the @code{follow-link} event, either on | 3417 If there is a binding for the @code{follow-link} event, either on the |
3417 the clickable text or in the local keymap, the binding of that event | 3418 clickable text or in the local keymap, the binding is the condition. |
3418 determines whether the mouse click position is inside a link. | |
3419 @end table | 3419 @end table |
3420 | 3420 |
3421 Regardless of where the @code{follow-link} value comes from, that | 3421 Regardless of how you set the @code{follow-link} condition, its |
3422 value is used according to the following table to determine whether | 3422 value is used as follows to determine whether the given position is |
3423 the given position is inside a link, and (if so) to compute an | 3423 inside a link, and (if so) to compute an @dfn{action code} saying how |
3424 @dfn{action code} saying how @key{Mouse-1} should handle the link. | 3424 @key{Mouse-1} should handle the link. |
3425 | 3425 |
3426 @table @asis | 3426 @table @asis |
3427 @item @code{mouse-face} | 3427 @item @code{mouse-face} |
3428 If the value is @code{mouse-face}, a position is inside a link if | 3428 If the condition is @code{mouse-face}, a position is inside a link if |
3429 there is a non-@code{nil} @code{mouse-face} property at that position. | 3429 there is a non-@code{nil} @code{mouse-face} property at that position. |
3430 The action code is always @code{t}. | 3430 The action code is always @code{t}. |
3431 | 3431 |
3432 For example, here is how Info mode handles @key{Mouse-1}: | 3432 For example, here is how Info mode handles @key{Mouse-1}: |
3433 | 3433 |
3434 @example | 3434 @example |
3435 (define-key Info-mode-map [follow-link] 'mouse-face) | 3435 (define-key Info-mode-map [follow-link] 'mouse-face) |
3436 @end example | 3436 @end example |
3437 | 3437 |
3438 @item a function | 3438 @item a function |
3439 If the value is a function, @var{func}, then a position @var{pos} is | 3439 If the condition is a valid function, @var{func}, then a position |
3440 inside a link if @code{(@var{func} @var{pos})} evaluates to | 3440 @var{pos} is inside a link if @code{(@var{func} @var{pos})} evaluates |
3441 non-@code{nil}. The value returned by @var{func} serves as the action | 3441 to non-@code{nil}. The value returned by @var{func} serves as the |
3442 code. | 3442 action code. |
3443 | 3443 |
3444 For example, here is how pcvs enables @key{Mouse-1} to follow links on | 3444 For example, here is how pcvs enables @key{Mouse-1} to follow links on |
3445 file names only: | 3445 file names only: |
3446 | 3446 |
3447 @example | 3447 @example |
3449 (lambda (pos) | 3449 (lambda (pos) |
3450 (if (eq (get-char-property pos 'face) 'cvs-filename-face) t))) | 3450 (if (eq (get-char-property pos 'face) 'cvs-filename-face) t))) |
3451 @end example | 3451 @end example |
3452 | 3452 |
3453 @item anything else | 3453 @item anything else |
3454 If the value is anything else, it is the action code. | 3454 If the condition value is anything else, then the position is inside a |
3455 link and the condition itself is the action code. Clearly you should | |
3456 only specify this kind of condition on the text that constitutes a | |
3457 link. | |
3455 @end table | 3458 @end table |
3456 | 3459 |
3457 @noindent | 3460 @noindent |
3458 Here's how the action code determines what @key{Mouse-1} should do: | 3461 The action code tells @key{Mouse-1} how to follow the link: |
3459 | 3462 |
3460 @table @asis | 3463 @table @asis |
3461 @item a string | 3464 @item a string |
3462 If the action code is a string, the @key{Mouse-1} event is translated | 3465 If the action code is a string or vector, the @key{Mouse-1} event is |
3463 into the first character of the string, i.e., the action of the | 3466 translated into the first element of the string or vector; i.e., the |
3464 @key{Mouse-1} click is the local or global binding of that character. | 3467 action of the @key{Mouse-1} click is the local or global binding of |
3465 Thus, if the action code is @code{"foo"}, @key{Mouse-1} translates | 3468 that character. Thus, if the action code is @code{"foo"}, |
3466 into @kbd{f}. | 3469 @key{Mouse-1} translates into @kbd{f}. If it is @code{[foo]}, |
3467 | 3470 @key{Mouse-1} translates into @key{foo}. |
3468 @item a vector | |
3469 If the action code is is a vector, the @key{Mouse-1} event is | |
3470 translated into the first element of that vector, i.e,. the action of | |
3471 the @key{Mouse-1} click is the local or global binding of that event. | |
3472 Thus, if the action code is @code{[?f ?o ?o]}, @key{Mouse-1} | |
3473 translates into @kbd{f}. | |
3474 | 3471 |
3475 @item anything else | 3472 @item anything else |
3476 For any other non-@code{nil} action code, the @code{mouse-1} event is | 3473 For any other non-@code{nil} action code, the @code{mouse-1} event is |
3477 translated into a @code{mouse-2} event at the same position. | 3474 translated into a @code{mouse-2} event at the same position. |
3478 @end table | 3475 @end table |