comparison lispref/text.texi @ 90072:cb67264d6096

Revision: miles@gnu.org--gnu-2005/emacs--unicode--0--patch-2 Merge from emacs--cvs-trunk--0 Patches applied: * miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-83 - miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-84 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-3 - miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-4 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-5 Merge from gnus--rel--5.10 * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-6 - miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-11 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-12 Remove "-face" suffix from lazy-highlight face name * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-13 - miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-16 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-17 Merge from gnus--rel--5.10 * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-18 - miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-21 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-22 <no summary provided> * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-23 - miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-39 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-40 Fix regressions from latest reftex update * miles@gnu.org--gnu-2005/gnus--rel--5.10--base-0 tag of miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-82 * miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-1 Merge from emacs--cvs-trunk--0 * miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-2 Merge from miles@gnu.org--gnu-2004 * miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-3 Merge from emacs--cvs-trunk--0
author Miles Bader <miles@gnu.org>
date Sun, 16 Jan 2005 03:40:12 +0000
parents fb79180b618d 2a346f1b2a9f
children fa9654493afb
comparison
equal deleted inserted replaced
90071:f6b4d0ebf147 90072:cb67264d6096
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 * Links and Mouse-1:: How to make @key{Mouse-1} follow a link.
2434 * Fields:: The @code{field} property defines 2435 * Fields:: The @code{field} property defines
2435 fields within the buffer. 2436 fields within the buffer.
2436 * Not Intervals:: Why text properties do not use 2437 * Not Intervals:: Why text properties do not use
2437 Lisp-visible text intervals. 2438 Lisp-visible text intervals.
2438 @end menu 2439 @end menu
2824 @itemize @bullet 2825 @itemize @bullet
2825 @item 2826 @item
2826 A face name (a symbol or string). 2827 A face name (a symbol or string).
2827 2828
2828 @item 2829 @item
2829 Starting in Emacs 21, a property list of face attributes. This has the 2830 A property list of face attributes. This has the
2830 form (@var{keyword} @var{value} @dots{}), where each @var{keyword} is a 2831 form (@var{keyword} @var{value} @dots{}), where each @var{keyword} is a
2831 face attribute name and @var{value} is a meaningful value for that 2832 face attribute name and @var{value} is a meaningful value for that
2832 attribute. With this feature, you do not need to create a face each 2833 attribute. With this feature, you do not need to create a face each
2833 time you want to specify a particular attribute for certain text. 2834 time you want to specify a particular attribute for certain text.
2834 @xref{Face Attributes}. 2835 @xref{Face Attributes}.
3386 This method makes it possible to define different commands for various 3387 This method makes it possible to define different commands for various
3387 clickable pieces of text. Also, the major mode definition (or the 3388 clickable pieces of text. Also, the major mode definition (or the
3388 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
3389 buffer. 3390 buffer.
3390 3391
3392 @node Links and Mouse-1
3393 @subsection Links and Mouse-1
3394 @cindex follow links
3395 @cindex mouse-1
3396
3397 The normal Emacs command for activating text in read-only buffers is
3398 @key{Mouse-2}, which includes following textual links. However, most
3399 graphical applications use @key{Mouse-1} for following links. For
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
3402 customize this behaviour through the variable
3403 @code{mouse-1-click-follows-link}.
3404
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 indicate that
3407 @key{Mouse-1} should also follow the link, you should specify a
3408 @code{follow-link} condition either as a text property or as a key
3409 binding:
3410
3411 @table @asis
3412 @item @code{follow-link} property
3413 If the clickable text has a non-@code{nil} @code{follow-link} text or overlay
3414 property, that specifies the condition.
3415
3416 @item @code{follow-link} event
3417 If there is a binding for the @code{follow-link} event, either on the
3418 clickable text or in the local keymap, the binding is the condition.
3419 @end table
3420
3421 Regardless of how you set the @code{follow-link} condition, its
3422 value is used as follows to determine whether the given position is
3423 inside a link, and (if so) to compute an @dfn{action code} saying how
3424 @key{Mouse-1} should handle the link.
3425
3426 @table @asis
3427 @item @code{mouse-face}
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.
3430 The action code is always @code{t}.
3431
3432 For example, here is how Info mode handles @key{Mouse-1}:
3433
3434 @example
3435 (define-key Info-mode-map [follow-link] 'mouse-face)
3436 @end example
3437
3438 @item a function
3439 If the condition is a valid function, @var{func}, then a position
3440 @var{pos} is inside a link if @code{(@var{func} @var{pos})} evaluates
3441 to non-@code{nil}. The value returned by @var{func} serves as the
3442 action code.
3443
3444 For example, here is how pcvs enables @key{Mouse-1} to follow links on
3445 file names only:
3446
3447 @example
3448 (define-key map [follow-link]
3449 (lambda (pos)
3450 (if (eq (get-char-property pos 'face) 'cvs-filename-face) t)))
3451 @end example
3452
3453 @item anything else
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.
3458 @end table
3459
3460 @noindent
3461 The action code tells @key{Mouse-1} how to follow the link:
3462
3463 @table @asis
3464 @item a string or vector
3465 If the action code is a string or vector, the @key{Mouse-1} event is
3466 translated into the first element of the string or vector; i.e., the
3467 action of the @key{Mouse-1} click is the local or global binding of
3468 that character or symbol. Thus, if the action code is @code{"foo"},
3469 @key{Mouse-1} translates into @kbd{f}. If it is @code{[foo]},
3470 @key{Mouse-1} translates into @key{foo}.
3471
3472 @item anything else
3473 For any other non-@code{nil} action code, the @code{mouse-1} event is
3474 translated into a @code{mouse-2} event at the same position.
3475 @end table
3476
3477 To define @key{Mouse-1} to activate a button defined with
3478 @code{define-button-type}, give the button a @code{follow-link}
3479 property with a value as specified above to determine how to follow
3480 the link. For example, here is how Help mode handles @key{Mouse-1}:
3481
3482 @smallexample
3483 (define-button-type 'help-xref
3484 'follow-link t
3485 'action #'help-button-action)
3486 @end smallexample
3487
3488 To define @key{Mouse-1} on a widget defined with
3489 @code{define-widget}, give the widget a @code{:follow-link} property
3490 with a value as specified above to determine how to follow the link.
3491
3492 For example, here is how the @code{link} widget specifies that
3493 a @key{Mouse-1} click shall be translated to @key{RET}:
3494
3495 @smallexample
3496 (define-widget 'link 'item
3497 "An embedded link."
3498 :button-prefix 'widget-link-prefix
3499 :button-suffix 'widget-link-suffix
3500 :follow-link "\C-m"
3501 :help-echo "Follow the link."
3502 :format "%[%t%]")
3503 @end smallexample
3504
3505 @defun mouse-on-link-p pos
3506 @tindex mouse-on-link-p
3507 This function returns non-@code{nil} if position @var{pos} in the
3508 current buffer is on a link.
3509 @end defun
3510
3391 @node Fields 3511 @node Fields
3392 @subsection Defining and Using Fields 3512 @subsection Defining and Using Fields
3393 @cindex fields 3513 @cindex fields
3394 3514
3395 A field is a range of consecutive characters in the buffer that are 3515 A field is a range of consecutive characters in the buffer that are