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