annotate lisp/prim/extents.el @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children ac2d302a0011
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
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; along with XEmacs; see the file COPYING. If not, write to the Free
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;;; Synched up with: Not in FSF.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ; some help from stig@hackvan.com here.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;; an alternative to map-extents.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 (defun mapcar-extents (function &optional predicate buffer-or-string from to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 flags property value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 "Applies FUNCTION to all extents which overlap a region in BUFFER-OR-STRING.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 The region is is delimited by FROM and TO. FUNCTION is called with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 one argument, the extent. A list of the values returned by FUNCTION
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 is returned. An optional PREDICATE may be used to further limit the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 extents over which FUNCTION is mapped. The optional arguments FLAGS,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 PROPERTY, and VALUE may also be used to control the extents passed to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 PREDICATE or FUNCTION. See also `map-extents'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 (let (*result*)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 (map-extents (if predicate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 #'(lambda (ex junk)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 (and (funcall predicate ex)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 (setq *result* (cons (funcall function ex)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 *result*)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 #'(lambda (ex junk)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 (setq *result* (cons (funcall function ex)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 *result*))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 buffer-or-string from to nil flags property value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 (nreverse *result*)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 (defun extent-list (&optional buffer-or-string from to flags)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 "Return a list of the extents in BUFFER-OR-STRING.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 BUFFER-OR-STRING defaults to the current buffer if omitted.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 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
55 returned; if omitted, all extents in the buffer or string are returned.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 More specifically, if a range is specified using FROM and TO, only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 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
59 are included in the list. FROM and TO default to the beginning and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 end of BUFFER-OR-STRING, respectively.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 FLAGS controls how end cases are treated. For a discussion of this,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 and exactly what ``overlap'' means, see `map-extents'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 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
66 consider using `map-extents' or `mapcar-extents' instead."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (mapcar-extents 'identity nil buffer-or-string from to flags))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (defun extent-string (extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 "Return the string delimited by the bounds of EXTENT."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (let ((object (extent-object extent)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (if (bufferp object)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (buffer-substring (extent-start-position extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (extent-end-position extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 object)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (substring object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (extent-start-position extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (extent-end-position extent)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (defun extent-descendants (extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 "Return a list of all descendants of EXTENT, including EXTENT.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 This recursively applies `extent-children' to any children of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 EXTENT, until no more children can be found."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (let ((children (extent-children extent)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (if children
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (apply 'nconc (mapcar 'extent-descendants children))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (list extent))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (defun set-extent-keymap (extent keymap)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 "Set EXTENT's `keymap' property to KEYMAP."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (set-extent-property extent 'keymap keymap))