annotate lisp/hyperbole/kotl/kprop-xe.el @ 0:376386a54a3c r19-14

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