diff options
| author | Richard M. Stallman | 2005-01-12 05:14:03 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 2005-01-12 05:14:03 +0000 |
| commit | b503de7617324d063b726d144aea4f7b7efafff4 (patch) | |
| tree | 15aaac995ede09bca52242674ad2f6aa643f9547 | |
| parent | cf6e4adce84a6d2e70eb752dcb26d613006c227a (diff) | |
| download | emacs-b503de7617324d063b726d144aea4f7b7efafff4.tar.gz emacs-b503de7617324d063b726d144aea4f7b7efafff4.zip | |
(Enabling Mouse-1 to Follow Links): Rewrite.
| -rw-r--r-- | lispref/text.texi | 123 |
1 files changed, 61 insertions, 62 deletions
diff --git a/lispref/text.texi b/lispref/text.texi index e74303bb5dc..5c7b11953a3 100644 --- a/lispref/text.texi +++ b/lispref/text.texi | |||
| @@ -3394,57 +3394,54 @@ buffer. | |||
| 3394 | @subsection Enabling Mouse-1 to Follow Links | 3394 | @subsection Enabling Mouse-1 to Follow Links |
| 3395 | @cindex follow links | 3395 | @cindex follow links |
| 3396 | 3396 | ||
| 3397 | Traditionally, Emacs uses a @key{mouse-1} click to set point and a | 3397 | The normal Emacs command for activating text in read-only buffers is |
| 3398 | @key{mouse-2} click to follow a link, whereas most other applications | 3398 | @key{Mouse-2}, which includes following textual links. However, most |
| 3399 | use a @key{mouse-1} click for both purposes, depending on whether you | 3399 | graphical applications use @key{Mouse-1} for following links. For |
| 3400 | click outside or inside a link. | 3400 | compatibility, @key{Mouse-1} follows links in Emacs too, when you |
| 3401 | 3401 | click on a link quickly without moving the mouse. The user can | |
| 3402 | Starting with Emacs release 21.4, the user visible behaviour of a | 3402 | customize this behaviour through the variable |
| 3403 | @key{mouse-1} click on a link has been changed to match this | 3403 | @code{mouse-1-click-follows-link}. |
| 3404 | context-sentitive dual behaviour. The user can customize this | 3404 | |
| 3405 | behaviour through the variable @code{mouse-1-click-follows-link}. | 3405 | To define text as a link at the Lisp level, you should bind |
| 3406 | 3406 | @key{Mouse-2} to a command to follow the link. Then, to indicate | |
| 3407 | However, at the Lisp level, @key{mouse-2} is still used as the | 3407 | that @key{Mouse-1} should also follow the link, here is what you do: |
| 3408 | action for the clickable text corresponding to the link, and the | ||
| 3409 | clickable text must be explicitly marked as a link for a @key{mouse-1} | ||
| 3410 | click to follow the link. | ||
| 3411 | |||
| 3412 | There are several methods that can be used to identify a clickable | ||
| 3413 | text as a link: | ||
| 3414 | 3408 | ||
| 3415 | @table @asis | 3409 | @table @asis |
| 3416 | @item follow-link property | 3410 | @item @code{follow-link} property |
| 3417 | 3411 | If the clickable text has a non-@code{nil} @code{follow-link} text or overlay | |
| 3418 | If the clickable text has a non-nil @code{follow-link} text or overlay | ||
| 3419 | property, the value of that property determines what to do. | 3412 | property, the value of that property determines what to do. |
| 3420 | 3413 | ||
| 3421 | @item follow-link event | 3414 | @item @code{follow-link} event |
| 3422 | 3415 | If there is a binding for the @code{follow-link} event, either on | |
| 3423 | If there is a binding for the @code{follow-link} event, either on | ||
| 3424 | the clickable text or in the local keymap, the binding of that event | 3416 | the clickable text or in the local keymap, the binding of that event |
| 3425 | determines whether the mouse click position is inside a link: | 3417 | determines whether the mouse click position is inside a link. |
| 3418 | @end table | ||
| 3426 | 3419 | ||
| 3427 | @table @asis | 3420 | Regardless of where the @code{follow-link} value comes from, that |
| 3428 | @item mouse-face | 3421 | value is used according to the following table to determine whether |
| 3422 | the given position is inside a link, and (if so) to compute an | ||
| 3423 | @dfn{action code} saying how @key{Mouse-1} should handle the link. | ||
| 3429 | 3424 | ||
| 3430 | If the binding is @code{mouse-face}, the mouse click position is | 3425 | @table @asis |
| 3431 | inside a link if there is a non-nil @code{mouse-face} property at | 3426 | @item @code{mouse-face} |
| 3432 | that position. A value of @code{t} is used to determine what to do next. | 3427 | If the value is @code{mouse-face}, a position is inside a link if |
| 3428 | there is a non-@code{nil} @code{mouse-face} property at that position. | ||
| 3429 | The action code is always @code{t}. | ||
| 3433 | 3430 | ||
| 3434 | For example, here is how @key{mouse-1} are setup in info mode: | 3431 | For example, here is how Info mode handles @key{Mouse-1}: |
| 3435 | 3432 | ||
| 3436 | @example | 3433 | @example |
| 3437 | (define-key Info-mode-map [follow-link] 'mouse-face) | 3434 | (define-key Info-mode-map [follow-link] 'mouse-face) |
| 3438 | @end example | 3435 | @end example |
| 3439 | 3436 | ||
| 3440 | @item a function | 3437 | @item a function |
| 3438 | If the value is a function, @var{func}, then a position @var{pos} is | ||
| 3439 | inside a link if @code{(@var{func} @var{pos})} evaluates to | ||
| 3440 | non-@code{nil}. The value returned by @var{func} serves as the action | ||
| 3441 | code. | ||
| 3441 | 3442 | ||
| 3442 | If the binding is a function, @var{func}, the mouse click position, | 3443 | For example, here is how pcvs enables @key{Mouse-1} to follow links on |
| 3443 | @var{pos}, is inside a link if the call @code{(@var{func} @var{pos})} | 3444 | file names only: |
| 3444 | returns non-@code{nil}. The return value from that call determines | ||
| 3445 | what to do next. | ||
| 3446 | |||
| 3447 | For example, here is how pcvs enables @key{mouse-1} on file names only: | ||
| 3448 | 3445 | ||
| 3449 | @example | 3446 | @example |
| 3450 | (define-key map [follow-link] | 3447 | (define-key map [follow-link] |
| @@ -3452,46 +3449,48 @@ For example, here is how pcvs enables @key{mouse-1} on file names only: | |||
| 3452 | (if (eq (get-char-property pos 'face) 'cvs-filename-face) t))) | 3449 | (if (eq (get-char-property pos 'face) 'cvs-filename-face) t))) |
| 3453 | @end example | 3450 | @end example |
| 3454 | 3451 | ||
| 3455 | @item anthing else | 3452 | @item anything else |
| 3456 | 3453 | If the value is anything else, it is the action code. | |
| 3457 | If the binding is anything else, the binding determines what to do. | ||
| 3458 | @end table | ||
| 3459 | |||
| 3460 | @end table | 3454 | @end table |
| 3461 | 3455 | ||
| 3462 | @noindent | 3456 | @noindent |
| 3463 | The resulting value determined above is interpreted as follows: | 3457 | Here's how the action code determines what @key{Mouse-1} should do: |
| 3464 | 3458 | ||
| 3465 | @table @asis | 3459 | @table @asis |
| 3466 | @item a string | 3460 | @item a string |
| 3467 | 3461 | If the action code is a string, the @key{Mouse-1} event is translated | |
| 3468 | If the value is a string, the @key{mouse-1} event is translated into | 3462 | into the first character of the string, i.e., the action of the |
| 3469 | the first character of the string, i.e. the action of the @key{mouse-1} | 3463 | @key{Mouse-1} click is the local or global binding of that character. |
| 3470 | click is the local or global binding of that character. | 3464 | Thus, if the action code is @code{"foo"}, @key{Mouse-1} translates |
| 3465 | into @kbd{f}. | ||
| 3471 | 3466 | ||
| 3472 | @item a vector | 3467 | @item a vector |
| 3473 | 3468 | If the action code is is a vector, the @key{Mouse-1} event is | |
| 3474 | If the value is is a vector, the @key{mouse-1} event is translated | 3469 | translated into the first element of that vector, i.e,. the action of |
| 3475 | into the first element of that vector, i.e. the action of the | 3470 | the @key{Mouse-1} click is the local or global binding of that event. |
| 3476 | @key{mouse-1} click is the local or global binding of that event. | 3471 | Thus, if the action code is @code{[?f ?o ?o]}, @key{Mouse-1} |
| 3477 | 3472 | translates into @kbd{f}. | |
| 3478 | @item anthing else | 3473 | |
| 3479 | 3474 | @item anything else | |
| 3480 | For any other non-nil valule, the @key{mouse-1} event is translated | 3475 | For any other non-@code{nil} action code, the @code{mouse-1} event is |
| 3481 | into a @key{mouse-2} event at the same position. | 3476 | translated into a @code{mouse-2} event at the same position. |
| 3482 | @end table | 3477 | @end table |
| 3483 | 3478 | ||
| 3484 | To use @key{mouse-1} on a button defined with @code{define-button-type}, | 3479 | To define @key{Mouse-1} to activate a button defined with |
| 3485 | give the button a @code{follow-link} property with a value as | 3480 | @code{define-button-type}, give the button a @code{follow-link} |
| 3486 | specified above to determine how to follow the link. | 3481 | property with a value as specified above to determine how to follow |
| 3482 | the link. | ||
| 3483 | @c ??? That is not clear. This needs an example or an xref. | ||
| 3487 | 3484 | ||
| 3488 | To use @key{mouse-1} on a widget defined with @code{define-widget}, | 3485 | To define @key{Mouse-1} on a widget defined with |
| 3489 | give the widget a @code{:follow-link} property with a value | 3486 | @code{define-widget}, give the widget a @code{:follow-link} property |
| 3490 | as specified above to determine how to follow the link. | 3487 | 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. | ||
| 3491 | 3489 | ||
| 3492 | @defun mouse-on-link-p pos | 3490 | @defun mouse-on-link-p pos |
| 3493 | @tindex mouse-on-link-p | 3491 | @tindex mouse-on-link-p |
| 3494 | Return non-@code{nil} if @var{pos} is on a link in the current buffer. | 3492 | This function returns non-@code{nil} if position @var{pos} in the |
| 3493 | current buffer is on a link. | ||
| 3495 | @end defun | 3494 | @end defun |
| 3496 | 3495 | ||
| 3497 | @node Fields | 3496 | @node Fields |