annotate lisp/hyperbole/kotl/kprop-em.el @ 123:c77884c6318d

Added tag r20-1b14 for changeset d2f30a177268
author cvs
date Mon, 13 Aug 2007 09:26:04 +0200
parents 376386a54a3c
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 ;;!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-em.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; SUMMARY: Koutline text property handling under Emacs 19.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; USAGE: GNU Emacs 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 20:59:54 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 (fset 'kproperty:get 'get-text-property)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 (defun kproperty:map (function property value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 "Apply FUNCTION to each PROPERTY `eq' to VALUE in the current buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 FUNCTION is called with point preceding PROPERTY and receives the list of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 properties at point as an argument. FUNCTION may not modify this list of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 properties."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 (let ((result)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 (start (point-min)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 (while (setq start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 (text-property-any start (point-max) property value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 (goto-char start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 (setq result (cons (funcall function (text-properties-at start))
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 (nreverse result)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 (fset 'kproperty:next-single-change 'next-single-property-change)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 (fset 'kproperty:previous-single-change 'previous-single-property-change)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 (fset 'kproperty:properties 'text-properties-at)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 (defun kproperty:put (start end property-list &optional object)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 "From START to END, add PROPERTY-LIST properties to the text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 The optional fourth argument, OBJECT, is the string or buffer containing the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 text. Text inserted before or after this region does not inherit the added
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 properties."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (add-text-properties
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 start end (append property-list '(rear-nonsticky t)) object))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 (defun kproperty:remove (start end property-list &optional object)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 "From START to END, remove the text properties in PROPERTY-LIST.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 The optional fourth argument, OBJECT, is the string or buffer containing the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 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
67 non-nil, then only a property with a matching value will be removed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 Returns t if any property was changed, nil otherwise."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (let ((changed) plist property value next)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (while property-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (setq property (car property-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 value (car (cdr property-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 plist (list property value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 property-list (nthcdr 2 property-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 next start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (while (setq next (text-property-any next end property value object))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (remove-text-properties next (1+ next) plist object)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (setq changed t next (1+ next))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 changed))
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 kproperty:replace-separator (pos label-separator old-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 "Replace at POS the cell label separator with LABEL-SEPARATOR.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 OLD-SEP-LEN is the length of the separator being replaced."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (let (properties)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (while (setq pos (kproperty:next-single-change (point) 'kcell))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (goto-char pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (setq properties (text-properties-at pos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 ;; Replace label-separator while maintaining cell properties.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (insert label-separator)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (add-text-properties pos (+ pos 2) properties)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (delete-region (point) (+ (point) old-sep-len)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (defun kproperty:set (property value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 "Set PROPERTY of character at point to VALUE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (kproperty:put (point) (min (+ 2 (point)) (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (list property value)))