Changeset 4140 for trunk/lispref/text.texi
- Timestamp:
- 08/10/06 11:19:54 (2 years ago)
- Files:
-
- trunk/lispref/text.texi (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lispref/text.texi
r4131 r4140 3481 3481 3482 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 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 3487 an example of how Dired does it: 3486 Indicating clickability usually involves highlighting the text, and 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 3493 @smallexample 3490 3494 (condition-case nil 3491 3495 (if (dired-move-to-filename) 3492 (put-text-property (point) 3493 (save-excursion 3494 (dired-move-to-end-of-filename) 3495 (point)) 3496 'mouse-face 'highlight)) 3496 (add-text-properties 3497 (point) 3498 (save-excursion 3499 (dired-move-to-end-of-filename) 3500 (point)) 3501 '(mouse-face highlight 3502 help-echo "mouse-2: visit this file in other window"))) 3497 3503 (error nil)) 3498 3504 @end smallexample 3499 3505 3500 3506 @noindent 3501 The first two arguments to @code{ put-text-property} specify the3507 The first two arguments to @code{add-text-properties} specify the 3502 3508 beginning and end of the text. 3503 3509 … … 3509 3515 @smallexample 3510 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 3518 (interactive "e") 3513 (let ( file)3519 (let (window pos file) 3514 3520 (save-excursion 3515 (set-buffer (window-buffer (posn-window (event-end event)))) 3516 (save-excursion 3517 (goto-char (posn-point (event-end event))) 3518 (setq file (dired-get-filename)))) 3519 (select-window (posn-window (event-end event))) 3520 (find-file-other-window (file-name-sans-versions file t)))) 3521 (setq window (posn-window (event-end event)) 3522 pos (posn-point (event-end event))) 3523 (if (not (windowp window)) 3524 (error "No file chosen")) 3525 (set-buffer (window-buffer window)) 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 3536 @end smallexample 3522 3537 3523 3538 @noindent 3524 The reason for the outer @code{save-excursion} construct is to avoid 3525 changing the current buffer; the reason for the inner one is to avoid 3526 permanently altering point in the buffer you click on. In this case, 3527 Dired uses the function @code{dired-get-filename} to determine which 3528 file to visit, based on the position found in the event. 3539 The reason for the @code{save-excursion} construct is to avoid 3540 changing the current buffer. In this case, 3541 Dired uses the functions @code{posn-window} and @code{posn-point} 3542 to determine which buffer the click happened in and where, and 3543 in that buffer, @code{dired-get-file-for-visit} to determine which 3544 file to visit. 3529 3545 3530 3546 Instead of defining a mouse command for the major mode, you can define … … 3698 3714 3699 3715 In all of these functions, if @var{pos} is omitted or @code{nil}, the 3700 value of point is used by default. 3716 value of point is used by default. If narrowing is in effect, then 3717 @var{pos} should fall within the accessible portion. @xref{Narrowing}. 3701 3718 3702 3719 @defun field-beginning &optional pos escape-from-edge limit
