annotate lisp/hyperbole/kotl/kprop-xe.el @ 26:441bb1e64a06 r19-15b96

Import from CVS: tag r19-15b96
author cvs
date Mon, 13 Aug 2007 08:51:32 +0200
parents 4103f0995bd7
children 131b0175ea99
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 ;;!emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; FILE: kprop-xe.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; SUMMARY: Koutline text property handling under XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; USAGE: XEmacs Lisp Library
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; KEYWORDS: outlines, wp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; AUTHOR: Bob Weiner
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
9 ;; ORG: InfoDock Associates
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; ORIG-DATE: 7/27/93
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
12 ;; LAST-MOD: 28-Feb-97 at 23:41:02 by Bob Weiner
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; This file is part of Hyperbole.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; Available for use and distribution under the same terms as GNU Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;;
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
17 ;; Copyright (C) 1993, 1994, 1995, 1997 Free Software Foundation, Inc.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; Developed with support from Motorola Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; DESCRIPTION:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; DESCRIP-END.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;;; Other required Elisp libraries
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 (require 'hversion)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;;; Public functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 0
diff changeset
33 ;; (get-text-property (pos prop &optional object))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 0
diff changeset
34 ;; Return the value of position POS's property PROP, in OBJECT.
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 0
diff changeset
35 ;; OBJECT is optional and defaults to the current buffer.
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 0
diff changeset
36 ;; If POSITION is at the end of OBJECT, the value is nil.
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 0
diff changeset
37 (fset 'kproperty:get 'get-text-property)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 (if (and hyperb:xemacs-p (or (>= emacs-minor-version 12)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 (> emacs-major-version 19)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 (defun kproperty:map (function property &optional value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 "Apply FUNCTION to each PROPERTY `eq' to VALUE in the current buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 FUNCTION is called with point preceding PROPERTY and receives PROPERTY as an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 argument."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 (let ((result))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (map-extents
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 (function (lambda (extent unused)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 (goto-char (or (extent-start-position extent) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (setq result (cons (funcall function extent) result))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 nil nil nil nil nil property value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 (nreverse result)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 (defun kproperty:map (function property &optional value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 "Apply FUNCTION to each PROPERTY `eq' to VALUE in the current buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 FUNCTION is called with point preceding PROPERTY and receives PROPERTY as an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 argument."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 (let ((result))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (map-extents
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (function (lambda (extent unused)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 (if (eq (extent-property extent property) value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 (progn (goto-char (or (extent-start-position extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (setq result (cons (funcall function extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 result))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (nreverse result))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 ;; (next-single-property-change (pos prop &optional object))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 ;; Return the position of next property change for a specific property.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 ;; Scans characters forward from POS till it finds
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 ;; a change in the PROP property, then returns the position of the change.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 ;; The optional third argument OBJECT is the string or buffer to scan.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 ;; Return nil if the property is constant all the way to the end of OBJECT.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 ;; If the value is non-nil, it is a position greater than POS, never equal.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (fset 'kproperty:next-single-change 'next-single-property-change)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 ;; (previous-single-property-change (pos prop &optional object))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 ;; Return the position of previous property change for a specific property.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 ;; Scans characters backward from POS till it finds
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 ;; a change in the PROP property, then returns the position of the change.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 ;; The optional third argument OBJECT is the string or buffer to scan.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 ;; Return nil if the property is constant all the way to the start of OBJECT.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 ;; If the value is non-nil, it is a position less than POS, never equal.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (fset 'kproperty:previous-single-change 'previous-single-property-change)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (fset 'kproperty:properties 'extent-properties-at)
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 kproperty:put (start end property-list &optional object)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 "From START to END, add PROPERTY-LIST properties to the text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 The optional fourth argument, OBJECT, is the string or buffer containing the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 text. Text inserted before or after this region does not inherit the added
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 properties."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 ;; Don't use text properties internally because they don't work as desired
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
96 ;; when copied to a string and then reinserted, at least in some versions
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
97 ;; of XEmacs.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (let ((extent (make-extent start end object)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (if (null extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (error "(kproperty:put): No extent at %d-%d to add properties %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 start end property-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (if (/= (mod (length property-list) 2) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (error "(kproperty:put): Property-list has odd number of elements, %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 property-list))
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
105 (set-extent-property extent 'text-prop (car property-list))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (set-extent-property extent 'duplicable t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (set-extent-property extent 'start-open t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (set-extent-property extent 'end-open t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (while property-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (set-extent-property
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 extent (car property-list) (car (cdr property-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (setq property-list (nthcdr 2 property-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 extent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (defun kproperty:remove (start end property-list &optional object)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 "From START to END, remove the text properties in PROPERTY-LIST.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 The optional fourth argument, OBJECT, is the string or buffer containing the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 text. PROPERTY-LIST should be a plist; if the value of a property is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 non-nil, then only a property with a matching value will be removed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 Returns t if any property was changed, nil otherwise."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 ;; Don't use text property functions internally because they only look for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 ;; closed extents, which kproperty does not use.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (let ((changed) property value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (while property-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (setq property (car property-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 value (car (cdr property-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 property-list (nthcdr 2 property-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (map-extents
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (function (lambda (extent maparg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (if (extent-live-p extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (progn (setq changed t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (delete-extent extent)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 object start end nil nil property value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 changed))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (defun kproperty:replace-separator (pos label-separator old-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 "Replace at POS the cell label separator with LABEL-SEPARATOR.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 OLD-SEP-LEN is the length of the separator being replaced."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (let (extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (while (setq pos (kproperty:next-single-change (point) 'kcell))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (goto-char pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (setq extent (extent-at pos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 ;; Replace label-separator while maintaining cell properties.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (insert label-separator)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (set-extent-endpoints extent pos (+ pos 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (delete-region (point) (+ (point) old-sep-len)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (defun kproperty:set (property value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 "Set PROPERTY of character at point to VALUE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (kproperty:put (point) (min (+ 2 (point)) (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (list property value)))