diff options
| author | Thien-Thi Nguyen | 2006-07-31 20:33:33 +0000 |
|---|---|---|
| committer | Thien-Thi Nguyen | 2006-07-31 20:33:33 +0000 |
| commit | fc0ba1d08092f5daedde890cb26e01883ab8afeb (patch) | |
| tree | 4e7c1794134f78ec35d431f02b72182d71ebd74c /lispref/text.texi | |
| parent | a3483884d3891085d2f78c14dec9f8ff4aace770 (diff) | |
| download | emacs-fc0ba1d08092f5daedde890cb26e01883ab8afeb.tar.gz emacs-fc0ba1d08092f5daedde890cb26e01883ab8afeb.zip | |
(Clickable Text): Mention `help-echo' text property.
Update intro, examples and associated explanations.
Diffstat (limited to 'lispref/text.texi')
| -rw-r--r-- | lispref/text.texi | 60 |
1 files changed, 38 insertions, 22 deletions
diff --git a/lispref/text.texi b/lispref/text.texi index fccc72d3d0b..08e55f18f05 100644 --- a/lispref/text.texi +++ b/lispref/text.texi | |||
| @@ -3480,25 +3480,31 @@ being called over and over for the same text. | |||
| 3480 | @cindex clickable text | 3480 | @cindex clickable text |
| 3481 | 3481 | ||
| 3482 | There are two parts of setting up @dfn{clickable text} in a buffer: | 3482 | There are two parts of setting up @dfn{clickable text} in a buffer: |
| 3483 | (1) to make that text highlight when the mouse moves over it, and (2) | 3483 | (1) to indicate clickability when the mouse moves over the text, and (2) |
| 3484 | to make a mouse button do something when you click on that text. | 3484 | to make a mouse button do something when you click on that text. |
| 3485 | 3485 | ||
| 3486 | For highlighting, use the @code{mouse-face} text property. Here is | 3486 | Indicating clickability usually involves highlighting the text, and |
| 3487 | an example of how Dired does it: | 3487 | often involves displaying helpful information about the action, such |
| 3488 | as which mouse button to press, or a short summary of the action. | ||
| 3489 | This can be done with the @code{mouse-face} and @code{help-echo} | ||
| 3490 | text properties. @xref{Special Properties}. | ||
| 3491 | Here is an example of how Dired does it: | ||
| 3488 | 3492 | ||
| 3489 | @smallexample | 3493 | @smallexample |
| 3490 | (condition-case nil | 3494 | (condition-case nil |
| 3491 | (if (dired-move-to-filename) | 3495 | (if (dired-move-to-filename) |
| 3492 | (put-text-property (point) | 3496 | (add-text-properties |
| 3493 | (save-excursion | 3497 | (point) |
| 3494 | (dired-move-to-end-of-filename) | 3498 | (save-excursion |
| 3495 | (point)) | 3499 | (dired-move-to-end-of-filename) |
| 3496 | 'mouse-face 'highlight)) | 3500 | (point)) |
| 3501 | '(mouse-face highlight | ||
| 3502 | help-echo "mouse-2: visit this file in other window"))) | ||
| 3497 | (error nil)) | 3503 | (error nil)) |
| 3498 | @end smallexample | 3504 | @end smallexample |
| 3499 | 3505 | ||
| 3500 | @noindent | 3506 | @noindent |
| 3501 | The first two arguments to @code{put-text-property} specify the | 3507 | The first two arguments to @code{add-text-properties} specify the |
| 3502 | beginning and end of the text. | 3508 | beginning and end of the text. |
| 3503 | 3509 | ||
| 3504 | The usual way to make the mouse do something when you click it | 3510 | The usual way to make the mouse do something when you click it |
| @@ -3508,24 +3514,34 @@ is done by the command definition. Here is how Dired does it: | |||
| 3508 | 3514 | ||
| 3509 | @smallexample | 3515 | @smallexample |
| 3510 | (defun dired-mouse-find-file-other-window (event) | 3516 | (defun dired-mouse-find-file-other-window (event) |
| 3511 | "In dired, visit the file or directory name you click on." | 3517 | "In Dired, visit the file or directory name you click on." |
| 3512 | (interactive "e") | 3518 | (interactive "e") |
| 3513 | (let (file) | 3519 | (let (window pos file) |
| 3514 | (save-excursion | 3520 | (save-excursion |
| 3515 | (set-buffer (window-buffer (posn-window (event-end event)))) | 3521 | (setq window (posn-window (event-end event)) |
| 3516 | (save-excursion | 3522 | pos (posn-point (event-end event))) |
| 3517 | (goto-char (posn-point (event-end event))) | 3523 | (if (not (windowp window)) |
| 3518 | (setq file (dired-get-filename)))) | 3524 | (error "No file chosen")) |
| 3519 | (select-window (posn-window (event-end event))) | 3525 | (set-buffer (window-buffer window)) |
| 3520 | (find-file-other-window (file-name-sans-versions file t)))) | 3526 | (goto-char pos) |
| 3527 | (setq file (dired-get-file-for-visit))) | ||
| 3528 | (if (file-directory-p file) | ||
| 3529 | (or (and (cdr dired-subdir-alist) | ||
| 3530 | (dired-goto-subdir file)) | ||
| 3531 | (progn | ||
| 3532 | (select-window window) | ||
| 3533 | (dired-other-window file))) | ||
| 3534 | (select-window window) | ||
| 3535 | (find-file-other-window (file-name-sans-versions file t))))) | ||
| 3521 | @end smallexample | 3536 | @end smallexample |
| 3522 | 3537 | ||
| 3523 | @noindent | 3538 | @noindent |
| 3524 | The reason for the outer @code{save-excursion} construct is to avoid | 3539 | The reason for the @code{save-excursion} construct is to avoid |
| 3525 | changing the current buffer; the reason for the inner one is to avoid | 3540 | changing the current buffer. In this case, |
| 3526 | permanently altering point in the buffer you click on. In this case, | 3541 | Dired uses the functions @code{posn-window} and @code{posn-point} |
| 3527 | Dired uses the function @code{dired-get-filename} to determine which | 3542 | to determine which buffer the click happened in and where, and |
| 3528 | file to visit, based on the position found in the event. | 3543 | in that buffer, @code{dired-get-file-for-visit} to determine which |
| 3544 | file to visit. | ||
| 3529 | 3545 | ||
| 3530 | Instead of defining a mouse command for the major mode, you can define | 3546 | Instead of defining a mouse command for the major mode, you can define |
| 3531 | a key binding for the clickable text itself, using the @code{keymap} | 3547 | a key binding for the clickable text itself, using the @code{keymap} |