annotate lisp/prim/extents.el @ 144:318232e2a3f0 r20-2b6

Import from CVS: tag r20-2b6
author cvs
date Mon, 13 Aug 2007 09:34:14 +0200
parents 131b0175ea99
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; extents.el --- miscellaneous extent functions not written in C
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;;;; Copyright (C) 1993, 1994 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Keywords: internal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;; You should have received a copy of the GNU General Public License
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
20 ;; along with XEmacs; see the file COPYING. If not, write to the
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 16
diff changeset
21 ;; Free Software Foundation, 59 Temple Place - Suite 330,
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
22 ;; Boston, MA 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;;; Synched up with: Not in FSF.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ; some help from stig@hackvan.com here.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;; an alternative to map-extents.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 (defun mapcar-extents (function &optional predicate buffer-or-string from to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 flags property value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 "Applies FUNCTION to all extents which overlap a region in BUFFER-OR-STRING.
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
32 The region is delimited by FROM and TO. FUNCTION is called with
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 one argument, the extent. A list of the values returned by FUNCTION
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 is returned. An optional PREDICATE may be used to further limit the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 extents over which FUNCTION is mapped. The optional arguments FLAGS,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 PROPERTY, and VALUE may also be used to control the extents passed to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 PREDICATE or FUNCTION. See also `map-extents'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 (let (*result*)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 (map-extents (if predicate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 #'(lambda (ex junk)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 (and (funcall predicate ex)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 (setq *result* (cons (funcall function ex)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 *result*)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 #'(lambda (ex junk)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 (setq *result* (cons (funcall function ex)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 *result*))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 buffer-or-string from to nil flags property value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (nreverse *result*)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 (defun extent-list (&optional buffer-or-string from to flags)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 "Return a list of the extents in BUFFER-OR-STRING.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 BUFFER-OR-STRING defaults to the current buffer if omitted.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 FROM and TO can be used to limit the range over which extents are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 returned; if omitted, all extents in the buffer or string are returned.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 More specifically, if a range is specified using FROM and TO, only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 extents that overlap the range (i.e. begin or end inside of the range)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 are included in the list. FROM and TO default to the beginning and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 end of BUFFER-OR-STRING, respectively.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 FLAGS controls how end cases are treated. For a discussion of this,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 and exactly what ``overlap'' means, see `map-extents'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 If you want to map a function over the extents in a buffer or string,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 consider using `map-extents' or `mapcar-extents' instead."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (mapcar-extents 'identity nil buffer-or-string from to flags))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (defun extent-string (extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 "Return the string delimited by the bounds of EXTENT."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (let ((object (extent-object extent)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (if (bufferp object)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (buffer-substring (extent-start-position extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (extent-end-position extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 object)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (substring object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (extent-start-position extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (extent-end-position extent)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (defun extent-descendants (extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 "Return a list of all descendants of EXTENT, including EXTENT.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 This recursively applies `extent-children' to any children of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 EXTENT, until no more children can be found."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (let ((children (extent-children extent)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (if children
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (apply 'nconc (mapcar 'extent-descendants children))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (list extent))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (defun set-extent-keymap (extent keymap)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 "Set EXTENT's `keymap' property to KEYMAP."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (set-extent-property extent 'keymap keymap))