annotate lisp/w3/w3-props.el @ 136:b980b6286996 r20-2b2

Import from CVS: tag r20-2b2
author cvs
date Mon, 13 Aug 2007 09:31:12 +0200
parents
children 6608ceec7cf8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
136
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
1 ;;; w3-props.el --- Additional text property stuff
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
2 ;; Author: wmperry
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
3 ;; Created: 1997/04/20 19:19:14
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
4 ;; Version: 1.1
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
5 ;; Keywords: faces
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
6
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
7 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
8 ;;; Copyright (c) 1995, 1996 by William M. Perry (wmperry@cs.indiana.edu)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
9 ;;; Copyright (c) 1996, 1997 Free Software Foundation, Inc.
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
10 ;;;
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
11 ;;; This file is part of GNU Emacs.
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
12 ;;;
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
13 ;;; GNU Emacs is free software; you can redistribute it and/or modify
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
14 ;;; it under the terms of the GNU General Public License as published by
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
15 ;;; the Free Software Foundation; either version 2, or (at your option)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
16 ;;; any later version.
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
17 ;;;
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
18 ;;; GNU Emacs is distributed in the hope that it will be useful,
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
19 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
20 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
21 ;;; GNU General Public License for more details.
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
22 ;;;
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
23 ;;; You should have received a copy of the GNU General Public License
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
24 ;;; along with GNU Emacs; see the file COPYING. If not, write to the
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
25 ;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
26 ;;; Boston, MA 02111-1307, USA.
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
27 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
28
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
29 ;;; Additional text property functions.
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
30
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
31 ;; The following three text property functions are not generally available (and
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
32 ;; it's not certain that they should be) so they are inlined for speed.
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
33 ;; The case for `fillin-text-property' is simple; it may or not be generally
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
34 ;; useful. (Since it is used here, it is useful in at least one place.;-)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
35 ;; However, the case for `append-text-property' and `prepend-text-property' is
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
36 ;; more complicated. Should they remove duplicate property values or not? If
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
37 ;; so, should the first or last duplicate item remain? Or the one that was
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
38 ;; added? In our implementation, the first duplicate remains.
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
39
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
40 (defsubst fillin-text-property (start end setprop markprop value &optional object)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
41 "Fill in one property of the text from START to END.
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
42 Arguments PROP and VALUE specify the property and value to put where none are
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
43 already in place. Therefore existing property values are not overwritten.
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
44 Optional argument OBJECT is the string or buffer containing the text."
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
45 (let ((start (text-property-any start end markprop nil object)) next)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
46 (while start
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
47 (setq next (next-single-property-change start markprop object end))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
48 (put-text-property start next setprop value object)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
49 (put-text-property start next markprop value object)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
50 (setq start (text-property-any next end markprop nil object)))))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
51
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
52 (if (not (fboundp 'unique))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
53 (defsubst unique (list)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
54 "Uniquify LIST, deleting elements using `delq'.
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
55 Return the list with subsequent duplicate items removed by side effects."
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
56 (let ((list list))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
57 (while list
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
58 (setq list (setcdr list (delq (car list) (cdr list))))))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
59 list))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
60
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
61 ;; A generalisation of `facemenu-add-face' for any property, but without the
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
62 ;; removal of inactive faces via `facemenu-discard-redundant-faces' and special
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
63 ;; treatment of `default'. Uses `unique' to remove duplicate property values.
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
64 (defsubst prepend-text-property (start end prop value &optional object)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
65 "Prepend to one property of the text from START to END.
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
66 Arguments PROP and VALUE specify the property and value to prepend to the value
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
67 already in place. The resulting property values are always lists, and unique.
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
68 Optional argument OBJECT is the string or buffer containing the text."
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
69 (let ((val (if (listp value) value (list value))) next prev)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
70 (while (/= start end)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
71 (setq next (next-single-property-change start prop object end)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
72 prev (get-text-property start prop object))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
73 (put-text-property
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
74 start next prop
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
75 (unique (append val (if (listp prev) prev (list prev))))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
76 object)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
77 (setq start next))))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
78
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
79 (defsubst append-text-property (start end prop value &optional object)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
80 "Append to one property of the text from START to END.
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
81 Arguments PROP and VALUE specify the property and value to append to the value
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
82 already in place. The resulting property values are always lists, and unique.
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
83 Optional argument OBJECT is the string or buffer containing the text."
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
84 (let ((val (if (listp value) value (list value))) next prev)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
85 (while (/= start end)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
86 (setq next (next-single-property-change start prop object end)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
87 prev (get-text-property start prop object))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
88 (put-text-property
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
89 start next prop
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
90 (unique (append (if (listp prev) prev (list prev)) val))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
91 object)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
92 (setq start next))))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
93
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
94 (provide 'w3-props)