annotate lisp/enriched.el @ 10677:f614ba745b6a

(internal_last_event_frame, Vlast_event_frame): Deleted; now part of perdisplay. All uses changed. (MOUSE_ACTIVITY_AVAILABLE) Deleted. (find_active_event_queue): New arg check_mouse. All callers changed. (Vlast_event_frame): Change from DEFVAR_LISP to DEFVAR_DISPLAY.
author Karl Heuer <kwzh@gnu.org>
date Tue, 07 Feb 1995 02:07:03 +0000
parents 66c7e651194d
children c8790275a636
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9676
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1 ;;; enriched.el -- read and save files in text/enriched format
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
2 ;; Copyright (c) 1994 Free Software Foundation
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
3
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
4 ;; Author: Boris Goldowsky <boris@cs.rochester.edu>
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
5 ;; Keywords: wp, faces
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
6
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
7 ;; This file is part of GNU Emacs.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
8
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
10 ;; it under the terms of the GNU General Public License as published by
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
11 ;; the Free Software Foundation; either version 2, or (at your option)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
12 ;; any later version.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
13 ;;
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
14 ;; GNU Emacs is distributed in the hope that it will be useful,
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
17 ;; GNU General Public License for more details.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
18 ;;
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
19 ;; You should have received a copy of the GNU General Public License
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
20 ;; along with GNU Emacs; see the file COPYING. If not, write to
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
21 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
22
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
23 ;;; Commentary:
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
24 ;;
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
25 ;; This file implements reading, editing, and saving files with
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
26 ;; text-properties such as faces, levels of indentation, and true line breaks
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
27 ;; distinguished from newlines just used to fit text into the window.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
28 ;;
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
29 ;; The file format used is the MIME text/enriched format, which is a
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
30 ;; standard format defined in internet RFC 1563. All standard annotations are
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
31 ;; supported except for <smaller> and <bigger>, which are currently not
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
32 ;; possible to display.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
33 ;;
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
34 ;; A separate file, enriched.doc, contains further documentation and other
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
35 ;; important information about this code. It also serves as an example file
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
36 ;; in text/enriched format. It should be in the etc directory of your emacs
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
37 ;; distribution.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
38
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
39 (provide 'enriched)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
40 (if window-system (require 'facemenu))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
41
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
42 ;;;
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
43 ;;; Variables controlling the display
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
44 ;;;
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
45
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
46 (defvar enriched-verbose t
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
47 "*If non-nil, give status messages when reading and writing files.")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
48
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
49 (defvar enriched-default-right-margin 10
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
50 "*Default amount of space to leave on the right edge of the screen.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
51 This can be increased inside text by changing the 'right-margin text property.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
52 Measured in character widths. If the screen is narrower than this, it is
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
53 assumed to be 0.")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
54
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
55 (defvar enriched-fill-after-visiting t
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
56 "If t, fills paragraphs when reading in enriched documents.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
57 If nil, only fills when you explicitly request it. If the value is 'ask, then
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
58 it will query you whether to fill.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
59 Filling is never done if the current text-width is the same as the value
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
60 stored in the file.")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
61
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
62 (defvar enriched-auto-save-interval 1000
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
63 "*`Auto-save-interval' to use for `enriched-mode'.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
64 Auto-saving enriched files is slow, so you may wish to have them happen less
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
65 often. You can set this to nil to only do auto-saves when you are not
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
66 actively working.")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
67
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
68 ;;Unimplemented:
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
69 ;(defvar enriched-aggressive-auto-fill t
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
70 ; "*If t, try to keep things properly filled and justified always.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
71 ;Set this to nil if you have a slow terminal or prefer to justify on request.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
72 ;The difference between aggressive and non-aggressive is subtle right now, but
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
73 ;may become stronger in the future.")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
74
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
75 ;; Unimplemented:
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
76 ; (defvar enriched-keep-ignored-items nil
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
77 ; "*If t, keep track of codes that are not understood.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
78 ; Otherwise they are deleted on reading the file, and not written out.")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
79
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
80 ;;Unimplemented:
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
81 ;(defvar enriched-electric-indentation t
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
82 ; "*If t, newlines and following indentation stick together.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
83 ;Deleting a newline or any part of the indenation will delete the whole
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
84 ;stretch.")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
85
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
86 ;;;
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
87 ;;; Set up faces & display table
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
88 ;;;
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
89
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
90 ;; A slight cheat - all emacs's faces are fixed-width.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
91 ;; The idea is just to pick one that looks different from the default.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
92 (if (internal-find-face 'fixed)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
93 nil
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
94 (make-face 'fixed)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
95 (if window-system
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
96 (set-face-font 'fixed
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
97 (car (or (x-list-fonts "*fixed-medium*"
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
98 'default (selected-frame))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
99 (x-list-fonts "*fixed*"
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
100 'default (selected-frame)))))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
101
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
102 (if (internal-find-face 'excerpt)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
103 nil
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
104 (make-face 'excerpt)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
105 (if window-system
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
106 (make-face-italic 'excerpt)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
107
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
108 ;;; The following two faces should not appear on menu.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
109 (if (boundp 'facemenu-unlisted-faces)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
110 (setq facemenu-unlisted-faces
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
111 (append '(enriched-code-face enriched-indentation-face)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
112 facemenu-unlisted-faces)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
113
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
114 (if (internal-find-face 'enriched-code-face)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
115 nil
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
116 (make-face 'enriched-code-face)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
117 (if window-system
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
118 (set-face-background 'enriched-code-face
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
119 (if (x-display-color-p)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
120 "LightSteelBlue"
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
121 "gray35"))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
122
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
123 (if (internal-find-face 'enriched-indentation-face)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
124 nil
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
125 (make-face 'enriched-indentation-face)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
126 (if window-system
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
127 (set-face-background 'enriched-indentation-face
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
128 (if (x-display-color-p)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
129 "DarkSlateBlue"
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
130 "gray25"))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
131
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
132 (defvar enriched-display-table (make-display-table))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
133 (aset enriched-display-table ?\f (make-vector (1- (frame-width)) ?-))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
134
10519
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
135 ; (defvar enriched-show-codes nil "See the function of the same name")
9676
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
136
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
137 (defvar enriched-par-props '(left-margin right-margin justification
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
138 front-sticky)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
139 "Text-properties that usually apply to whole paragraphs.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
140 These are set front-sticky everywhere except at hard newlines.")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
141
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
142 ;;;
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
143 ;;; Variables controlling the file format
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
144 ;;; (bidirectional)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
145
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
146 (defvar enriched-initial-annotation
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
147 (lambda ()
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
148 (format "<param>-*-enriched-*-width:%d
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
149 </param>" (enriched-text-width)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
150 "What to insert at the start of a text/enriched file.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
151 If this is a string, it is inserted. If it is a list, it should be a lambda
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
152 expression, which is evaluated to get the string to insert.")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
153
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
154 (defvar enriched-annotation-format "<%s%s>"
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
155 "General format of enriched-text annotations.")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
156
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
157 (defvar enriched-annotation-regexp "<\\(/\\)?\\([-A-za-z0-9]+\\)>"
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
158 "Regular expression matching enriched-text annotations.")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
159
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
160 (defvar enriched-downcase-annotations t
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
161 "Set to t if case of annotations is irrelevant.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
162 In this case all annotations listed in enriched-annotation-list should be
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
163 lowercase, and annotations read from files will be downcased before being
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
164 compared to that list.")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
165
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
166 (defvar enriched-list-valued-properties '(face unknown)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
167 "List of properties whose values can be lists.")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
168
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
169 (defvar enriched-annotation-alist
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
170 '((face (bold-italic "bold" "italic")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
171 (bold "bold")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
172 (italic "italic")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
173 (underline "underline")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
174 (fixed "fixed")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
175 (excerpt "excerpt")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
176 (default )
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
177 (nil enriched-encode-other-face))
10519
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
178 (hard (nil enriched-encode-hard-newline))
9676
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
179 (left-margin (4 "indent"))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
180 (right-margin (4 "indentright"))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
181 (justification (none "nofill")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
182 (right "flushright")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
183 (left "flushleft")
10519
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
184 (full "flushboth")
9676
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
185 (center "center"))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
186 (PARAMETER (t "param")) ; Argument of preceding annotation
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
187 ;; The following are not part of the standard:
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
188 (FUNCTION (enriched-decode-foreground "x-color")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
189 (enriched-decode-background "x-bg-color"))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
190 (read-only (t "x-read-only"))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
191 (unknown (nil enriched-encode-unknown)) ;anything else found
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
192 ; (font-size (2 "bigger") ; unimplemented
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
193 ; (-2 "smaller"))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
194 )
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
195 "List of definitions of text/enriched annotations.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
196 Each element is a list whose car is a PROPERTY, and the following
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
197 elements are VALUES of that property followed by zero or more ANNOTATIONS.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
198 Whenever the property takes on that value, each of the annotations
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
199 will be inserted into the file. Only the name of the annotation
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
200 should be specified, it will be formatted by `enriched-make-annotation'.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
201 At the point that the property stops having that value, the matching
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
202 negated annotation will be inserted (it may actually be closed earlier and
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
203 reopened, if necessary, to keep proper nesting).
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
204
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
205 Conversely, when annotations are read, they are searched for in this list, and
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
206 the relevant text property is added to the buffer. The first match found whose
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
207 conditions are satisfied is used. If enriched-downcase-annotations is true,
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
208 then annotations in this list should be listed in lowercase, and annotations
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
209 read from the file will be downcased.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
210
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
211 If the VALUE is numeric, then it is assumed that there is a single annotation
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
212 and each occurrence of it increments the value of the property by that number.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
213 Thus, given the entry \(left-margin \(4 \"indent\")), `enriched-encode-region'
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
214 will insert two <indent> annotations if the left margin changes from 4 to 12.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
215
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
216 If the VALUE is nil, then instead of annotations, a function should be
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
217 specified. This function is used as a default: it is called for all
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
218 transitions not explicitly listed in the table. The function is called with
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
219 two arguments, the OLD and NEW values of the property. It should return a
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
220 list of annotations like `enriched-loc-annotations' does, or may directly
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
221 modify the buffer. Note that this only works for encoding; there must be some
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
222 other way of decoding the annotations thus produced.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
223
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
224 [For future expansion:] If the VALUE is a list, then the property's value will
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
225 be appended to the surrounding value of the property.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
226
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
227 For decoding, there are some special symbols that can be used in the
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
228 \"property\" slot. Annotations listed under the pseudo-property PARAMETER are
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
229 considered to be arguments of the immediately surrounding annotation; the text
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
230 between the opening and closing parameter annotations is deleted from the
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
231 buffer but saved as a string. The surrounding annotation should be listed
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
232 under the pseudo-property FUNCTION. Instead of inserting a text-property for
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
233 this annotation, enriched-decode-buffer will call the function listed in the
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
234 VALUE slot, with the first two arguments being the start and end locations and
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
235 the rest of the arguments being any PARAMETERs found in that region.")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
236
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
237 ;;; This is not needed for text/enriched format, since all annotations are in
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
238 ;;; a standard form:
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
239 ;(defvar enriched-special-annotations-alist nil
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
240 ; "List of annotations not formatted in the usual way.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
241 ;Each element has the form (ANNOTATION BEGIN END), where
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
242 ;ANNOTATION is the annotation's name, which is a symbol (normal
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
243 ;annotations are named with strings, special ones with symbols),
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
244 ;BEGIN is the literal string to insert as the opening annotation, and
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
245 ;END is the literal string to insert as the close.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
246 ;This is used only for encoding. Typically, each will have an entry in
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
247 ;enriched-decode-special-alist to deal with its decoding.")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
248
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
249 ;;; Encoding variables
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
250
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
251 (defvar enriched-encode-interesting-regexp "<"
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
252 "Regexp matching the start of something that may require encoding.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
253 All text-property changes are also considered \"interesting\".")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
254
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
255 (defvar enriched-encode-special-alist
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
256 '(("<" . (lambda () (insert-and-inherit "<"))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
257 "List of special operations for writing enriched files.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
258 Each element has the form \(STRING . FUNCTION).
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
259 Whenever one of the strings \(including its properties, if any)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
260 is found, the corresponding function is called.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
261 Match data is available to the function.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
262 See `enriched-decode-special-alist' for instructions on decoding special
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
263 items.")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
264
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
265 (defvar enriched-ignored-ok
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
266 '(front-sticky rear-nonsticky)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
267 "Properties that are not written into enriched files.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
268 Generally this list should only contain properties that just for enriched's
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
269 internal purposes; other properties that cannot be recorded will generate
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
270 a warning message to the user since information will be lost.")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
271
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
272 ;;; Decoding variables
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
273
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
274 (defvar enriched-decode-interesting-regexp "[<\n]"
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
275 "Regexp matching the start of something that may require decoding.")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
276
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
277 (defvar enriched-decode-special-alist
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
278 '(("<<" . (lambda () (delete-char 1) (forward-char 1)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
279 ("\n\n" . enriched-decode-hard-newline))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
280 "List of special operations for reading enriched files.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
281 Each element has the form \(STRING . FUNCTION).
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
282 Whenever one of the strings is found, the corresponding function is called,
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
283 with point at the beginning of the match and the match data is available to
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
284 the function. Should leave point where next search should start.")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
285
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
286 ;;; Internal variables
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
287
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
288 (defvar enriched-mode nil
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
289 "True if `enriched-mode' \(which see) is enabled.")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
290 (make-variable-buffer-local 'enriched-mode)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
291
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
292 (if (not (assq 'enriched-mode minor-mode-alist))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
293 (setq minor-mode-alist
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
294 (cons '(enriched-mode " Enriched")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
295 minor-mode-alist)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
296
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
297 (defvar enriched-mode-hooks nil
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
298 "Functions to run when entering `enriched-mode'.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
299 If you set variables in this hook, you should arrange for them to be restored
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
300 to their old values if enriched-mode is left. One way to do this is to add
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
301 them and their old values to `enriched-old-bindings'.")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
302
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
303 (defvar enriched-old-bindings nil
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
304 "Store old variable values that we change when entering mode.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
305 The value is a list of \(VAR VALUE VAR VALUE...).")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
306 (make-variable-buffer-local 'enriched-old-bindings)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
307
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
308 (defvar enriched-translated nil
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
309 "True if buffer has already been decoded.")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
310 (make-variable-buffer-local 'enriched-translated)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
311
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
312 (defvar enriched-text-width nil)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
313 (make-variable-buffer-local 'enriched-text-width)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
314
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
315 (defvar enriched-ignored-list nil)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
316
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
317 (defvar enriched-open-ans nil)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
318
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
319 ;;;
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
320 ;;; Functions defining the format of annotations
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
321 ;;;
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
322
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
323 (defun enriched-make-annotation (name positive)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
324 "Format an annotation called NAME.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
325 If POSITIVE is non-nil, this is the opening annotation, if nil, this is the
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
326 matching close."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
327 ;; Could be used for annotations not following standard form:
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
328 ; (if (symbolp name)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
329 ; (if positive
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
330 ; (elt (assq name enriched-special-annotations-alist) 1)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
331 ; (elt (assq name enriched-special-annotations-alist) 2)) )
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
332 (if (stringp name)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
333 (format enriched-annotation-format (if positive "" "/") name)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
334 ;; has parameters.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
335 (if positive
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
336 (let ((item (car name))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
337 (params (cdr name)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
338 (concat (format enriched-annotation-format "" item)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
339 (mapconcat (lambda (i) (concat "<param>" i "</param>"))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
340 params "")))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
341 (format enriched-annotation-format "/" (car name)))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
342
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
343 (defun enriched-annotation-name (a)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
344 "Find the name of an ANNOTATION."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
345 (save-match-data
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
346 (if (string-match enriched-annotation-regexp a)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
347 (substring a (match-beginning 2) (match-end 2)))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
348
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
349 (defun enriched-annotation-positive-p (a)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
350 "Returns t if ANNOTATION is positive (open),
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
351 or nil if it is a closing (negative) annotation."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
352 (save-match-data
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
353 (and (string-match enriched-annotation-regexp a)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
354 (not (match-beginning 1)))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
355
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
356 (defun enriched-encode-unknown (old new)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
357 "Deals with re-inserting unknown annotations."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
358 (cons (if old (list old))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
359 (if new (list new))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
360
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
361 (defun enriched-encode-hard-newline (old new)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
362 "Deal with encoding `hard-newline' property change."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
363 ;; This makes a sequence of N hard newlines into N+1 duplicates of the first
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
364 ;; one- so all property changes are put off until after all the newlines.
10519
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
365 (if (and new (current-justification)) ; no special processing inside NoFill
9676
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
366 (let* ((length (skip-chars-forward "\n"))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
367 (s (make-string length ?\n)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
368 (backward-delete-char (1- length))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
369 (add-text-properties 0 length (text-properties-at (1- (point))) s)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
370 (insert s)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
371 (backward-char (+ length 1)))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
372
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
373 (defun enriched-decode-hard-newline ()
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
374 "Deal with newlines while decoding file."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
375 (let ((nofill (equal "nofill" ; find out if we're in NoFill region
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
376 (enriched-which-assoc
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
377 '("nofill" "flushleft" "flushright" "center"
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
378 "flushboth")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
379 enriched-open-ans)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
380 (n (skip-chars-forward "\n")))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
381 (delete-char (- n))
10519
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
382 (newline (if nofill n (1- n)))))
9676
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
383
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
384 (defun enriched-encode-other-face (old new)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
385 "Generate annotations for random face change.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
386 One annotation each for foreground color, background color, italic, etc."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
387 (cons (and old (enriched-face-ans old))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
388 (and new (enriched-face-ans new))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
389
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
390 (defun enriched-face-ans (face)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
391 "Return annotations specifying FACE."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
392 (cond ((string-match "^fg:" (symbol-name face))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
393 (list (list "x-color" (substring (symbol-name face) 3))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
394 ((string-match "^bg:" (symbol-name face))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
395 (list (list "x-bg-color" (substring (symbol-name face) 3))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
396 ((let* ((fg (face-foreground face))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
397 (bg (face-background face))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
398 (props (face-font face t))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
399 (ans (cdr (enriched-annotate-change 'face nil props))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
400 (if fg (enriched-push (list "x-color" fg) ans))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
401 (if bg (enriched-push (list "x-bg-color" bg) ans))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
402 ans))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
403
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
404 (defun enriched-decode-foreground (from to color)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
405 (let ((face (intern (concat "fg:" color))))
9694
f8aa9230c3fa (enriched-mode): Add autoload cookie.
Boris Goldowsky <boris@gnu.org>
parents: 9677
diff changeset
406 (cond ((internal-find-face face))
f8aa9230c3fa (enriched-mode): Add autoload cookie.
Boris Goldowsky <boris@gnu.org>
parents: 9677
diff changeset
407 ((and window-system (facemenu-get-face face)))
f8aa9230c3fa (enriched-mode): Add autoload cookie.
Boris Goldowsky <boris@gnu.org>
parents: 9677
diff changeset
408 (window-system
f8aa9230c3fa (enriched-mode): Add autoload cookie.
Boris Goldowsky <boris@gnu.org>
parents: 9677
diff changeset
409 (enriched-warn "Color \"%s\" not defined:
f8aa9230c3fa (enriched-mode): Add autoload cookie.
Boris Goldowsky <boris@gnu.org>
parents: 9677
diff changeset
410 Try M-x set-face-foreground RET %s RET some-other-color" color face))
f8aa9230c3fa (enriched-mode): Add autoload cookie.
Boris Goldowsky <boris@gnu.org>
parents: 9677
diff changeset
411 ((make-face face)
f8aa9230c3fa (enriched-mode): Add autoload cookie.
Boris Goldowsky <boris@gnu.org>
parents: 9677
diff changeset
412 (enriched-warn "Color \"%s\" can't be displayed." color)))
9676
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
413 (list from to 'face face)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
414
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
415 (defun enriched-decode-background (from to color)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
416 (let ((face (intern (concat "bg:" color))))
9694
f8aa9230c3fa (enriched-mode): Add autoload cookie.
Boris Goldowsky <boris@gnu.org>
parents: 9677
diff changeset
417 (cond ((internal-find-face face))
f8aa9230c3fa (enriched-mode): Add autoload cookie.
Boris Goldowsky <boris@gnu.org>
parents: 9677
diff changeset
418 ((and window-system (facemenu-get-face face)))
f8aa9230c3fa (enriched-mode): Add autoload cookie.
Boris Goldowsky <boris@gnu.org>
parents: 9677
diff changeset
419 (window-system
f8aa9230c3fa (enriched-mode): Add autoload cookie.
Boris Goldowsky <boris@gnu.org>
parents: 9677
diff changeset
420 (enriched-warn "Color \"%s\" not defined:
f8aa9230c3fa (enriched-mode): Add autoload cookie.
Boris Goldowsky <boris@gnu.org>
parents: 9677
diff changeset
421 Try M-x set-face-background RET %s RET some-other-color" color face))
f8aa9230c3fa (enriched-mode): Add autoload cookie.
Boris Goldowsky <boris@gnu.org>
parents: 9677
diff changeset
422 ((make-face face)
f8aa9230c3fa (enriched-mode): Add autoload cookie.
Boris Goldowsky <boris@gnu.org>
parents: 9677
diff changeset
423 (enriched-warn "Color \"%s\" can't be displayed." color)))
9676
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
424 (list from to 'face face)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
425
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
426 ;;;
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
427 ;;; NOTE: Everything below this point is intended to be independent of the file
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
428 ;;; format, which is defined by the variables and functions above.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
429 ;;;
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
430
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
431 ;;;
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
432 ;;; Define the mode
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
433 ;;;
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
434
9694
f8aa9230c3fa (enriched-mode): Add autoload cookie.
Boris Goldowsky <boris@gnu.org>
parents: 9677
diff changeset
435 ;;;###autoload
9676
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
436 (defun enriched-mode (&optional arg notrans)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
437 "Minor mode for editing text/enriched files.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
438 These are files with embedded formatting information in the MIME standard
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
439 text/enriched format.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
440
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
441 Turning the mode on or off interactively will query whether the buffer
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
442 should be translated into or out of text/enriched format immediately.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
443 Noninteractively translation is done without query unless the optional
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
444 second argument NO-TRANS is non-nil.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
445 Turning mode on runs `enriched-mode-hooks'.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
446
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
447 More information about enriched-mode is available in the file
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
448 etc/enriched.doc in the Emacs distribution directory.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
449
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
450 Commands:
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
451
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
452 \\<enriched-mode-map>\\{enriched-mode-map}"
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
453 (interactive "P")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
454 (let ((mod (buffer-modified-p)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
455 (cond ((or (<= (prefix-numeric-value arg) 0)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
456 (and enriched-mode (null arg)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
457 ;; Turn mode off
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
458 (setq enriched-mode nil)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
459 (if (if (interactive-p)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
460 (y-or-n-p "Translate buffer into text/enriched format?")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
461 (not notrans))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
462 (progn (enriched-encode-region)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
463 (mapcar (lambda (x)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
464 (remove-text-properties
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
465 (point-min) (point-max)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
466 (list (if (consp x) (car x) x) nil)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
467 (append enriched-ignored-ok
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
468 enriched-annotation-alist))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
469 (setq enriched-translated nil)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
470 ;; restore old variable values
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
471 (while enriched-old-bindings
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
472 (funcall 'set (car enriched-old-bindings)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
473 (car (cdr enriched-old-bindings)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
474 (setq enriched-old-bindings (cdr (cdr enriched-old-bindings))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
475 (remove-hook 'write-region-annotate-functions
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
476 'enriched-annotate-function t)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
477 (remove-hook 'after-change-functions 'enriched-nogrow-hook t))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
478 (enriched-mode nil) ; Mode already on; do nothing.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
479 (t ; Turn mode on
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
480 ;; save old variable values before we change them.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
481 (setq enriched-mode t
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
482 enriched-old-bindings
10519
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
483 (list 'auto-save-interval auto-save-interval
9676
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
484 'buffer-display-table buffer-display-table
10519
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
485 'indent-line-function indent-line-function
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
486 'use-hard-newlines use-hard-newlines))
9676
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
487 (make-local-variable 'auto-save-interval)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
488 (make-local-variable 'indent-line-function)
10519
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
489 (make-local-variable 'use-hard-newlines)
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
490 (setq auto-save-interval enriched-auto-save-interval
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
491 indent-line-function 'indent-to-left-margin
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
492 buffer-display-table enriched-display-table
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
493 use-hard-newlines t) ; Weird in Center&FlushRight
9676
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
494 ;; Add hooks
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
495 (add-hook 'write-region-annotate-functions
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
496 'enriched-annotate-function)
10519
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
497 ; (add-hook 'after-change-functions 'enriched-nogrow-hook)
9676
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
498
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
499 (put-text-property (point-min) (point-max)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
500 'front-sticky enriched-par-props)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
501
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
502 (if (and (not enriched-translated)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
503 (if (interactive-p)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
504 (y-or-n-p "Does buffer need to be translated now? ")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
505 (not notrans)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
506 (progn (enriched-decode-region)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
507 (setq enriched-translated t)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
508 (run-hooks 'enriched-mode-hooks)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
509 (set-buffer-modified-p mod)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
510 (force-mode-line-update)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
511
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
512 ;;;
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
513 ;;; Keybindings
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
514 ;;;
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
515
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
516 (defvar enriched-mode-map nil
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
517 "Keymap for `enriched-mode'.")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
518
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
519 (if (null enriched-mode-map)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
520 (fset 'enriched-mode-map (setq enriched-mode-map (make-sparse-keymap))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
521
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
522 (if (not (assq 'enriched-mode minor-mode-map-alist))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
523 (setq minor-mode-map-alist
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
524 (cons (cons 'enriched-mode enriched-mode-map)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
525 minor-mode-map-alist)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
526
10519
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
527 (define-key enriched-mode-map "\C-a" 'move-to-left-margin)
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
528 (define-key enriched-mode-map "\C-j" 'newline)
9676
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
529 (define-key enriched-mode-map "\M-j" 'enriched-justification-menu-map)
10519
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
530 (define-key enriched-mode-map "\M-S" 'set-justification-center)
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
531 (define-key enriched-mode-map "\C-x\t" 'increment-left-margin)
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
532 (define-key enriched-mode-map "\C-c\C-l" 'set-left-margin)
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
533 (define-key enriched-mode-map "\C-c\C-r" 'set-right-margin)
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
534 ;;(define-key enriched-mode-map "\C-c\C-s" 'enriched-show-codes)
9676
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
535
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
536 ;;;
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
537 ;;; General list/stack manipulation
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
538 ;;;
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
539
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
540 (defmacro enriched-push (item stack)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
541 "Push ITEM onto STACK.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
542 STACK should be a symbol whose value is a list."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
543 (` (setq (, stack) (cons (, item) (, stack)))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
544
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
545 (defmacro enriched-pop (stack)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
546 "Remove and return first item on STACK."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
547 (` (let ((pop-item (car (, stack))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
548 (setq (, stack) (cdr (, stack)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
549 pop-item)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
550
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
551 (defun enriched-delq1 (cons list)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
552 "Remove the given CONS from LIST by side effect.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
553 Since CONS could be the first element of LIST, write
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
554 `(setq foo (enriched-delq1 element foo))' to be sure of changing the value
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
555 of `foo'."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
556 (if (eq cons list)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
557 (cdr list)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
558 (let ((p list))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
559 (while (not (eq (cdr p) cons))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
560 (if (null p) (error "enriched-delq1: Attempt to delete a non-element"))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
561 (setq p (cdr p)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
562 ;; Now (cdr p) is the cons to delete
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
563 (setcdr p (cdr cons))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
564 list)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
565
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
566 (defun enriched-make-list-uniq (list)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
567 "Destructively remove duplicates from LIST.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
568 Compares using `eq'."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
569 (let ((l list))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
570 (while l
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
571 (setq l (setcdr l (delq (car l) (cdr l)))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
572 list))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
573
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
574 (defun enriched-make-relatively-unique (a b)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
575 "Delete common elements of lists A and B, return as pair.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
576 Compares using `equal'."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
577 (let* ((acopy (copy-sequence a))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
578 (bcopy (copy-sequence b))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
579 (tail acopy))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
580 (while tail
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
581 (let ((dup (member (car tail) bcopy))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
582 (next (cdr tail)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
583 (if dup (setq acopy (enriched-delq1 tail acopy)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
584 bcopy (enriched-delq1 dup bcopy)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
585 (setq tail next)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
586 (cons acopy bcopy)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
587
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
588 (defun enriched-common-tail (a b)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
589 "Given two lists that have a common tail, return it.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
590 Compares with `equal', and returns the part of A that is equal to the
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
591 equivalent part of B. If even the last items of the two are not equal,
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
592 returns nil."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
593 (let ((la (length a))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
594 (lb (length b)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
595 ;; Make sure they are the same length
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
596 (while (> la lb)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
597 (setq a (cdr a)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
598 la (1- la)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
599 (while (> lb la)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
600 (setq b (cdr b)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
601 lb (1- lb))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
602 (while (not (equal a b))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
603 (setq a (cdr a)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
604 b (cdr b)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
605 a)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
606
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
607 (defun enriched-which-assoc (items list)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
608 "Return which one of ITEMS occurs first as a car of an element of LIST."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
609 (let (res)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
610 (while list
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
611 (if (setq res (member (car (car list)) items))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
612 (setq res (car res)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
613 list nil)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
614 (setq list (cdr list))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
615 res))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
616
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
617 (defun enriched-reorder (items order)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
618 "Arrange ITEMS to following partial ORDER.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
619 Elements of ITEMS equal to elements of ORDER will be rearranged to follow the
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
620 ORDER. Unmatched items will go last."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
621 (if order
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
622 (let ((item (member (car order) items)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
623 (if item
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
624 (cons (car item)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
625 (enriched-reorder (enriched-delq1 item items)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
626 (cdr order)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
627 (enriched-reorder items (cdr order))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
628 items))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
629
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
630 ;;;
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
631 ;;; Utility functions
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
632 ;;;
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
633
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
634 (defun enriched-get-face-attribute (attr face &optional frame)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
635 "Get an attribute of a face or list of faces.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
636 ATTRIBUTE should be one of the functions `face-font' `face-foreground',
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
637 `face-background', or `face-underline-p'. FACE can be a face or a list of
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
638 faces. If optional argument FRAME is given, report on the face in that frame.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
639 If FRAME is t, report on the defaults for the face in new frames. If FRAME is
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
640 omitted or nil, use the selected frame."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
641 (cond ((null face) nil)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
642 ((or (symbolp face) (internal-facep face)) (funcall attr face frame))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
643 ((funcall attr (car face) frame))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
644 ((enriched-get-face-attribute attr (cdr face) frame))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
645
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
646 (defun enriched-overlays-overlapping (begin end &optional test)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
647 "Return a list of the overlays which overlap the specified region.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
648 If optional arg TEST is given, it is called with each overlay as its
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
649 argument, and only those for which it is true are returned."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
650 (overlay-recenter begin)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
651 (let ((res nil)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
652 (overlays (cdr (overlay-lists)))) ; includes all ending after BEGIN
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
653 (while overlays
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
654 (if (and (< (overlay-start (car overlays)) end)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
655 (or (not test)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
656 (funcall test (car overlays))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
657 (enriched-push (car overlays) res))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
658 (setq overlays (cdr overlays)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
659 res))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
660
10519
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
661 ;(defun enriched-show-codes (&rest which)
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
662 ; "Enable or disable highlighting of special regions.
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
663 ;With argument null or `none', turns off highlighting.
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
664 ;If argument is `newline', turns on display of hard newlines.
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
665 ;If argument is `indent', highlights the automatic indentation at the beginning
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
666 ;of each line.
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
667 ;If argument is `margin', highlights all regions with non-standard margins."
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
668 ; (interactive
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
669 ; (list (intern (completing-read "Show which codes: "
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
670 ; '(("none") ("newline") ("indent") ("margin"))
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
671 ; nil t))))
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
672 ; (if (null which)
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
673 ; (setq enriched-show-codes nil)
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
674 ; (setq enriched-show-codes which))
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
675 ; ;; First delete current overlays
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
676 ; (let* ((ol (overlay-lists))
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
677 ; (overlays (append (car ol) (cdr ol))))
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
678 ; (while overlays
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
679 ; (if (eq (overlay-get (car overlays) 'face) 'enriched-code-face)
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
680 ; (delete-overlay (car overlays)))
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
681 ; (setq overlays (cdr overlays))))
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
682 ; ;; Now add new ones for each thing displayed.
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
683 ; (if (null which)
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
684 ; (message "Code display off."))
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
685 ; (while which
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
686 ; (cond ((eq (car which) 'margin)
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
687 ; (enriched-show-margin-codes))
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
688 ; ((eq (car which) 'indent)
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
689 ; (enriched-map-property-regions 'enriched-indentation
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
690 ; (lambda (v b e)
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
691 ; (if v (enriched-show-region-as-code b e 'indent)))))
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
692 ; ((eq (car which) 'newline)
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
693 ; (save-excursion
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
694 ; (goto-char (point-min))
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
695 ; (while (enriched-search-forward-with-props
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
696 ; enriched-hard-newline nil t)
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
697 ; (enriched-show-region-as-code (match-beginning 0) (match-end 0)
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
698 ; 'newline)))))
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
699 ; (setq which (cdr which))))
9676
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
700
10519
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
701 ;(defun enriched-show-margin-codes (&optional from to)
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
702 ; "Highlight regions with nonstandard left-margins.
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
703 ;See `enriched-show-codes'."
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
704 ; (enriched-map-property-regions 'left-margin
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
705 ; (lambda (v b e)
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
706 ; (if (and v (> v 0))
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
707 ; (enriched-show-region-as-code b e 'margin)))
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
708 ; from to)
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
709 ; (enriched-map-property-regions 'right-margin
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
710 ; (lambda (v b e)
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
711 ; (if (and v (> v 0))
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
712 ; (enriched-show-region-as-code b e 'margin)))
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
713 ; from to))
9676
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
714
10519
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
715 ;(defun enriched-show-region-as-code (from to type)
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
716 ; "Display region between FROM and TO as a code if TYPE is displayed.
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
717 ;Displays it only if TYPE is an element of `enriched-show-codes' or is t."
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
718 ; (if (or (eq t type) (memq type enriched-show-codes))
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
719 ; (let* ((old (enriched-overlays-overlapping
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
720 ; from to (lambda (o)
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
721 ; (eq 'enriched-code-face
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
722 ; (overlay-get o 'face)))))
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
723 ; (new (if old (move-overlay (car old) from to)
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
724 ; (make-overlay from to))))
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
725 ; (overlay-put new 'face 'enriched-code-face)
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
726 ; (overlay-put new 'front-nogrow t)
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
727 ; (if (eq type 'margin)
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
728 ; (overlay-put new 'rear-grow t))
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
729 ; (while (setq old (cdr old))
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
730 ; (delete-overlay (car old))))))
9676
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
731
10519
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
732 ;(defun enriched-nogrow-hook (beg end old-length)
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
733 ; "Implement front-nogrow and rear-grow for overlays.
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
734 ;Normally overlays have opposite inheritance properties than
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
735 ;text-properties: they will expand to include text inserted at their
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
736 ;beginning, but not text inserted at their end. However,
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
737 ;if this function is an element of `after-change-functions', then
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
738 ;overlays with a non-nil value of the `front-nogrow' property will not
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
739 ;expand to include text that is inserted just in front of them, and
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
740 ;overlays with a non-nil value of the `rear-grow' property will
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
741 ;expand to include text that is inserted just after them."
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
742 ; (if (not (zerop old-length))
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
743 ; nil ;; not an insertion
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
744 ; (let ((overlays (overlays-at end)) o)
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
745 ; (while overlays
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
746 ; (setq o (car overlays)
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
747 ; overlays (cdr overlays))
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
748 ; (if (and (overlay-get o 'front-nogrow)
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
749 ; (= beg (overlay-start o)))
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
750 ; (move-overlay o end (overlay-end o)))))
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
751 ; (let ((overlays (overlays-at (1- beg))) o)
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
752 ; (while overlays
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
753 ; (setq o (car overlays)
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
754 ; overlays (cdr overlays))
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
755 ; (if (and (overlay-get o 'rear-grow)
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
756 ; (= beg (overlay-end o)))
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
757 ; (move-overlay o (overlay-start o) end))))))
9676
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
758
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
759 (defun enriched-warn (&rest args)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
760 "Display a warning message.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
761 Arguments are given to `format' and the result is displayed in a buffer."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
762 (save-excursion
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
763 (let ((buf (current-buffer))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
764 (line (1+ (count-lines 1 (point))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
765 (mark (point-marker)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
766 (pop-to-buffer (get-buffer-create "*Enriched Warnings*"))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
767 (goto-char (point-max))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
768 (insert
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
769 ; (format "%s:%d: " (if (boundp 'enriched-file) enriched-file
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
770 ; (buffer-file-name buf))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
771 ; line)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
772 (apply (function format) args)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
773 "\n")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
774 (pop-to-buffer buf))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
775
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
776 (defun enriched-looking-at-with-props (string)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
777 "True if text at point is equal to STRING, including text props.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
778 This is a literal, not a regexp match.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
779 The buffer text must include all text properties that STRING has, in
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
780 the same places, but it is allowed to have others that STRING lacks."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
781 (let ((buffer-string (buffer-substring (point) (+ (point) (length string)))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
782 (and (string-equal string buffer-string)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
783 (enriched-text-properties-include string buffer-string))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
784
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
785 (defun enriched-search-forward-with-props
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
786 (string &optional bound noerror count)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
787 "Search forward for STRING, including its text properties.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
788 Set point to end of occurrence found, and return point.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
789 The match found must include all text properties that STRING has, in
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
790 the same places, but it is allowed to have others that STRING lacks.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
791 An optional second argument bounds the search; it is a buffer position.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
792 The match found must not extend after that position. nil is equivalent
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
793 to (point-max).
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
794 Optional third argument, if t, means if fail just return nil (no error).
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
795 If not nil and not t, move to limit of search and return nil.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
796 Optional fourth argument is repeat count--search for successive occurrences.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
797 See also the functions `match-beginning', `match-end' and `replace-match'."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
798 (interactive "sSearch for: ")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
799 (or bound (setq bound (point-max)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
800 (or count (setq count 1))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
801 (let ((start (point))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
802 (res t))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
803 (while (and res (> count 0))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
804 (while (and (setq res (search-forward string bound t))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
805 (not (enriched-text-properties-include
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
806 string (buffer-substring (match-beginning 0)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
807 (match-end 0))))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
808 (setq count (1- count)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
809 (cond (res)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
810 ((eq noerror t) (goto-char start) nil)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
811 (noerror (goto-char bound) nil)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
812 (t (goto-char start)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
813 (error "Search failed: %s" string)))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
814
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
815 (defun enriched-search-backward-with-props
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
816 (string &optional bound noerror count)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
817 "Search backward for STRING, including its text properties.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
818 Set point to the beginning of occurrence found, and return point.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
819 The match found must include all text properties that STRING has, in
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
820 the same places, but it is allowed to have others that STRING lacks.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
821 An optional second argument bounds the search; it is a buffer position.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
822 The match found must not start before that position. nil is equivalent
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
823 to (point-min).
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
824 Optional third argument, if t, means if fail just return nil (no error).
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
825 If not nil and not t, move to limit of search and return nil.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
826 Optional fourth argument is repeat count--search for successive occurrences.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
827 See also the functions `match-beginning', `match-end' and `replace-match'."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
828 (interactive "sSearch for: ")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
829 (or bound (setq bound (point-min)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
830 (or count (setq count 1))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
831 (let ((start (point))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
832 (res t))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
833 (while (and res (> count 0))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
834 (while (and (setq res (search-backward string bound t))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
835 (not (enriched-text-properties-include
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
836 string (buffer-substring (match-beginning 0)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
837 (match-end 0))))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
838 (setq count (1- count)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
839 (cond (res)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
840 ((eq noerror t) (goto-char start) nil)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
841 (noerror (goto-char bound) nil)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
842 (t (goto-char start)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
843 (error "Search failed: %s" string)))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
844
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
845 (defun enriched-text-properties-include (a b)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
846 "True if all of A's text-properties are also properties of B.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
847 They must match in property name, value, and position. B must be at least as
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
848 long as A, but comparison is done only up to the length of A."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
849 (let ((loc (length a)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
850 (catch 'fail
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
851 (while (>= loc 0)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
852 (let ((plist (text-properties-at loc a)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
853 (while plist
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
854 (if (not (equal (car (cdr plist))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
855 (get-text-property loc (car plist) b)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
856 (throw 'fail nil))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
857 (setq plist (cdr (cdr plist)))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
858 (setq loc (1- loc)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
859 t)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
860
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
861 (defun enriched-map-property-regions (prop func &optional from to)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
862 "Apply a function to regions of the buffer based on a text property.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
863 For each contiguous region of the buffer for which the value of PROPERTY is
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
864 eq, the FUNCTION will be called. Optional arguments FROM and TO specify the
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
865 region over which to scan.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
866
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
867 The specified function receives three arguments: the VALUE of the property in
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
868 the region, and the START and END of each region."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
869 (save-excursion
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
870 (save-restriction
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
871 (if to (narrow-to-region (point-min) to))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
872 (goto-char (or from (point-min)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
873 (let ((begin (point))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
874 end
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
875 (marker (make-marker))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
876 (val (get-text-property (point) prop)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
877 (while (setq end (text-property-not-all begin (point-max) prop val))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
878 (move-marker marker end)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
879 (funcall func val begin (marker-position marker))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
880 (setq begin (marker-position marker)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
881 val (get-text-property marker prop)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
882 (if (< begin (point-max))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
883 (funcall func val begin (point-max)))))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
884
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
885 (put 'enriched-map-property-regions 'lisp-indent-hook 1)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
886
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
887 (defun enriched-insert-annotations (list &optional offset)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
888 "Apply list of annotations to buffer as write-region would.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
889 Inserts each element of LIST of buffer annotations at its appropriate place.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
890 Use second arg OFFSET if the annotations' locations are not
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
891 relative to the beginning of the buffer: annotations will be inserted
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
892 at their location-OFFSET+1 \(ie, the offset is the character number of
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
893 the first character in the buffer)."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
894 (if (not offset)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
895 (setq offset 0)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
896 (setq offset (1- offset)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
897 (let ((l (reverse list)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
898 (while l
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
899 (goto-char (- (car (car l)) offset))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
900 (insert (cdr (car l)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
901 (setq l (cdr l)))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
902
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
903 ;;;
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
904 ;;; Indentation, Filling, Justification
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
905 ;;;
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
906
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
907 (defun enriched-text-width ()
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
908 "The width of unindented text in this window, in characters.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
909 This is the width of the window minus `enriched-default-right-margin'."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
910 (or enriched-text-width
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
911 (let ((ww (window-width)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
912 (setq enriched-text-width
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
913 (if (> ww enriched-default-right-margin)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
914 (- ww enriched-default-right-margin)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
915 ww)))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
916
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
917 (defun enriched-tag-indentation (from to)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
918 "Define region to be indentation."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
919 (add-text-properties from to '(enriched-indentation t
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
920 rear-nonsticky (enriched-indentation))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
921
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
922 (defun enriched-insert-indentation (&optional from to)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
923 "Indent and justify each line in the region."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
924 (save-excursion
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
925 (save-restriction
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
926 (if to (narrow-to-region (point-min) to))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
927 (goto-char (or from (point-min)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
928 (if (not (bolp)) (forward-line 1))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
929 (while (not (eobp))
10519
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
930 (indent-to (current-left-margin))
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
931 (justify-current-line t nil t)
9676
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
932 (forward-line 1)))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
933
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
934 (defun enriched-delete-indentation (&optional from to)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
935 "Remove indentation and justification from region.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
936 Does not alter the left-margin and right-margin text properties, so the
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
937 indentation can be reconstructed. Tries only to remove whitespace that was
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
938 added automatically, not spaces and tabs inserted by user."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
939 (save-excursion
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
940 (save-restriction
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
941 (if to (narrow-to-region (point-min) to))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
942 (if from
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
943 (progn (goto-char from)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
944 (if (not (bolp)) (forward-line 1))
10519
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
945 (setq from (point)))
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
946 (setq from (point-min)))
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
947 (delete-to-left-margin from (point-max))
9676
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
948 (enriched-map-property-regions 'justification
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
949 (lambda (v b e)
10519
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
950 (if (eq v 'full)
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
951 (canonically-space-region b e)))
9676
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
952 from nil))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
953
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
954 ;;;
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
955 ;;; Writing Files
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
956 ;;;
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
957
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
958 (defsubst enriched-open-annotation (name)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
959 (insert-and-inherit (enriched-make-annotation name t)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
960
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
961 (defsubst enriched-close-annotation (name)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
962 (insert-and-inherit (enriched-make-annotation name nil)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
963
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
964 (defun enriched-annotate-function (start end)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
965 "For use on write-region-annotations-functions.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
966 Makes a new buffer containing the region in text/enriched format."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
967 (if enriched-mode
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
968 (let (;(enriched-file (file-name-nondirectory buffer-file-name))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
969 (copy-buf (generate-new-buffer "*Enriched Temp*")))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
970 (copy-to-buffer copy-buf start end)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
971 (set-buffer copy-buf)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
972 (enriched-insert-annotations write-region-annotations-so-far start)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
973 (setq write-region-annotations-so-far nil)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
974 (enriched-encode-region)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
975 nil)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
976
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
977 (defun enriched-encode-region (&optional from to)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
978 "Transform buffer into text/enriched format."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
979 (if enriched-verbose (message "Enriched: encoding document..."))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
980 (setq enriched-ignored-list enriched-ignored-ok)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
981 (save-excursion
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
982 (save-restriction
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
983 (if to (narrow-to-region (point-min) to))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
984 (enriched-delete-indentation from to)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
985 (let ((enriched-open-ans nil)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
986 (inhibit-read-only t))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
987 (goto-char (or from (point-min)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
988 (insert (if (stringp enriched-initial-annotation)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
989 enriched-initial-annotation
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
990 (funcall enriched-initial-annotation)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
991 (while
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
992 (let* ((ans (enriched-loc-annotations (point)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
993 (neg-ans (enriched-reorder (car ans) enriched-open-ans))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
994 (pos-ans (cdr ans)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
995 ;; First do the negative (closing) annotations
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
996 (while neg-ans
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
997 (if (not (member (car neg-ans) enriched-open-ans))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
998 (enriched-warn "BUG DETECTED: Closing %s with open list=%s"
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
999 (enriched-pop neg-ans) enriched-open-ans)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1000 (while (not (equal (car neg-ans) (car enriched-open-ans)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1001 ;; To close anno. N, need to first close ans 1 to N-1,
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1002 ;; remembering to re-open them later.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1003 (enriched-push (car enriched-open-ans) pos-ans)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1004 (enriched-close-annotation (enriched-pop enriched-open-ans)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1005 ;; Now we can safely close this anno & remove from open list
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1006 (enriched-close-annotation (enriched-pop neg-ans))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1007 (enriched-pop enriched-open-ans)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1008 ;; Now deal with positive (opening) annotations
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1009 (while pos-ans
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1010 (enriched-push (car pos-ans) enriched-open-ans)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1011 (enriched-open-annotation (enriched-pop pos-ans)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1012 (enriched-move-to-next-property-change)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1013
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1014 ;; Close up shop...
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1015 (goto-char (point-max))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1016 (while enriched-open-ans
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1017 (enriched-close-annotation (enriched-pop enriched-open-ans)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1018 (if (not (= ?\n (char-after (1- (point)))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1019 (insert ?\n)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1020 (if (and enriched-verbose (> (length enriched-ignored-list)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1021 (length enriched-ignored-ok)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1022 (let ((not-ok nil))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1023 (while (not (eq enriched-ignored-list enriched-ignored-ok))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1024 (setq not-ok (cons (car enriched-ignored-list) not-ok)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1025 enriched-ignored-list (cdr enriched-ignored-list)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1026 (enriched-warn "Not recorded: %s" not-ok)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1027 (sit-for 1))))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1028
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1029 (defun enriched-move-to-next-property-change ()
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1030 "Advance point to next prop change, dealing with special items on the way.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1031 Returns the location, or nil."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1032 (let ((prop-change (next-property-change (point))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1033 (while (and (< (point) (or prop-change (point-max)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1034 (search-forward enriched-encode-interesting-regexp
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1035 prop-change 1))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1036 (goto-char (match-beginning 0))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1037 (let ((specials enriched-encode-special-alist))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1038 (while specials
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1039 (if (enriched-looking-at-with-props (car (car specials)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1040 (progn (goto-char (match-end 0))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1041 (funcall (cdr (car specials)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1042 (setq specials nil))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1043 (enriched-pop specials)))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1044 prop-change))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1045
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1046 (defun enriched-loc-annotations (loc)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1047 "Return annotation(s) needed at LOCATION.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1048 This includes any properties that change between LOC-1 and LOC.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1049 If LOC is at the beginning of the buffer, will generate annotations for any
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1050 non-nil properties there, plus the enriched-version annotation.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1051 Annotations are returned as a list. The car of the list is the list of
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1052 names of the annotations to close, and the cdr is the list of the names of the
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1053 annotations to open."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1054 (let* ((prev-loc (1- loc))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1055 (begin (< prev-loc (point-min)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1056 (before-plist (if begin nil (text-properties-at prev-loc)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1057 (after-plist (text-properties-at loc))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1058 negatives positives prop props)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1059 ;; make list of all property names involved
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1060 (while before-plist
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1061 (enriched-push (car before-plist) props)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1062 (setq before-plist (cdr (cdr before-plist))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1063 (while after-plist
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1064 (enriched-push (car after-plist) props)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1065 (setq after-plist (cdr (cdr after-plist))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1066 (setq props (enriched-make-list-uniq props))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1067
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1068 (while props
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1069 (setq prop (enriched-pop props))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1070 (if (memq prop enriched-ignored-list)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1071 nil ; If its been ignored before, ignore it now.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1072 (let ((before (if begin nil (get-text-property prev-loc prop)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1073 (after (get-text-property loc prop)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1074 (if (equal before after)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1075 nil ; no change; ignore
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1076 (let ((result (enriched-annotate-change prop before after)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1077 (setq negatives (nconc negatives (car result))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1078 positives (nconc positives (cdr result))))))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1079 (cons negatives positives)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1080
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1081 (defun enriched-annotate-change (prop old new)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1082 "Return annotations for PROPERTY changing from OLD to NEW.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1083 These are searched for in `enriched-annotation-list'.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1084 If NEW does not appear in the list, but there is a default function, then that
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1085 function is called.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1086 Annotations are returned as a list, as in `enriched-loc-annotations'."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1087 ;; If property is numeric, nil means 0
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1088 (if (or (consp old) (consp new))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1089 (let* ((old (if (listp old) old (list old)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1090 (new (if (listp new) new (list new)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1091 (tail (enriched-common-tail old new))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1092 close open)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1093 (while old
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1094 (setq close
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1095 (append (car (enriched-annotate-change prop (car old) nil))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1096 close)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1097 old (cdr old)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1098 (while new
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1099 (setq open
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1100 (append (cdr (enriched-annotate-change prop nil (car new)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1101 open)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1102 new (cdr new)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1103 (enriched-make-relatively-unique close open))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1104 (cond ((and (numberp old) (null new))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1105 (setq new 0))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1106 ((and (numberp new) (null old))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1107 (setq old 0)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1108 (let ((prop-alist (cdr (assoc prop enriched-annotation-alist)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1109 default)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1110 (cond ((null prop-alist) ; not found
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1111 (if (not (memq prop enriched-ignored-list))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1112 (enriched-push prop enriched-ignored-list))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1113 nil)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1114
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1115 ;; Numerical values: use the difference
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1116 ((and (numberp old) (numberp new))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1117 (let* ((entry (progn
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1118 (while (and (car (car prop-alist))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1119 (not (numberp (car (car prop-alist)))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1120 (enriched-pop prop-alist))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1121 (car prop-alist)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1122 (increment (car (car prop-alist)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1123 (n (ceiling (/ (float (- new old)) (float increment))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1124 (anno (car (cdr (car prop-alist)))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1125 (if (> n 0)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1126 (cons nil (make-list n anno))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1127 (cons (make-list (- n) anno) nil))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1128
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1129 ;; Standard annotation
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1130 (t (let ((close (and old (cdr (assoc old prop-alist))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1131 (open (and new (cdr (assoc new prop-alist)))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1132 (if (or close open)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1133 (enriched-make-relatively-unique close open)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1134 (let ((default (assoc nil prop-alist)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1135 (if default
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1136 (funcall (car (cdr default)) old new))))))))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1137
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1138 ;;;
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1139 ;;; Reading files
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1140 ;;;
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1141
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1142 (defun enriched-decode-region (&optional from to)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1143 "Decode text/enriched buffer into text with properties.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1144 This is the primary entry point for decoding."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1145 (if enriched-verbose (message "Enriched: decoding document..."))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1146 (save-excursion
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1147 (save-restriction
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1148 (if to (narrow-to-region (point-min) to))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1149 (goto-char (or from (point-min)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1150 (let ((file-width (enriched-get-file-width))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1151 (inhibit-read-only t)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1152 enriched-open-ans todo loc unknown-ans)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1153
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1154 (while (enriched-move-to-next-annotation)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1155 (let* ((loc (match-beginning 0))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1156 (anno (buffer-substring (match-beginning 0) (match-end 0)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1157 (name (enriched-annotation-name anno))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1158 (positive (enriched-annotation-positive-p anno)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1159
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1160 (if enriched-downcase-annotations
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1161 (setq name (downcase name)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1162
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1163 (delete-region (match-beginning 0) (match-end 0))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1164 (if positive
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1165 (enriched-push (list name loc) enriched-open-ans)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1166 ;; negative...
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1167 (let* ((top (car enriched-open-ans))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1168 (top-name (car top))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1169 (start (car (cdr top)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1170 (params (cdr (cdr top)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1171 (aalist enriched-annotation-alist)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1172 (matched nil))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1173 (if (not (equal name top-name))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1174 (error (format "Improper nesting in file: %s != %s"
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1175 name top)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1176 (while aalist
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1177 (let ((prop (car (car aalist)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1178 (alist (cdr (car aalist))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1179 (while alist
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1180 (let ((value (car (car alist)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1181 (ans (cdr (car alist))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1182 (if (member name ans)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1183 ;; Check if multiple annotations are satisfied
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1184 (if (member 'nil (mapcar
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1185 (lambda (r)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1186 (assoc r enriched-open-ans))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1187 ans))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1188 nil ; multiple ans not satisfied
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1189 ;; Yes, we got it:
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1190 (setq alist nil aalist nil matched t
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1191 enriched-open-ans (cdr enriched-open-ans))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1192 (cond
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1193 ((eq prop 'PARAMETER)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1194 ;; This is a parameter of the top open ann.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1195 (let ((nxt (enriched-pop enriched-open-ans)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1196 (if nxt
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1197 (enriched-push
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1198 (append
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1199 nxt
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1200 (list (buffer-substring start loc)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1201 enriched-open-ans))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1202 (delete-region start loc)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1203 ((eq prop 'FUNCTION)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1204 (let ((rtn (apply value start loc params)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1205 (if rtn (enriched-push rtn todo))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1206 (t
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1207 ;; Normal property/value pair
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1208 (enriched-push (list start loc prop value)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1209 todo))))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1210 (enriched-pop alist)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1211 (enriched-pop aalist))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1212 (if matched
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1213 nil
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1214 ;; Didn't find it
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1215 (enriched-pop enriched-open-ans)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1216 (enriched-push (list start loc 'unknown name) todo)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1217 (enriched-push name unknown-ans))))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1218
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1219 ;; Now actually add the properties
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1220
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1221 (while todo
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1222 (let* ((item (enriched-pop todo))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1223 (from (elt item 0))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1224 (to (elt item 1))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1225 (prop (elt item 2))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1226 (val (elt item 3)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1227
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1228 ; (if (and (eq prop 'IGNORE) ; 'IGNORE' pseudo-property was special
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1229 ; (eq val t))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1230 ; (delete-region from to))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1231 (put-text-property
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1232 from to prop
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1233 (cond ((numberp val)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1234 (+ val (or (get-text-property from prop) 0)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1235 ((memq prop enriched-list-valued-properties)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1236 (let ((prev (get-text-property from prop)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1237 (cons val (if (listp prev) prev (list prev)))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1238 (t val)))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1239
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1240 (if (or (and file-width ; possible reasons not to fill:
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1241 (= file-width (enriched-text-width))) ; correct wd.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1242 (null enriched-fill-after-visiting) ; never fill
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1243 (and (eq 'ask enriched-fill-after-visiting) ; asked & declined
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1244 (not (y-or-n-p "Reformat for current display width? "))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1245 ;; Minimally, we have to insert indentation and justification.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1246 (enriched-insert-indentation)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1247 (sit-for 1)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1248 (if enriched-verbose (message "Filling paragraphs..."))
10519
66c7e651194d (enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents: 9694
diff changeset
1249 (fill-region (point-min) (point-max))
9676
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1250 (if enriched-verbose (message nil)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1251
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1252 (if enriched-verbose
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1253 (progn
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1254 (message nil)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1255 (if unknown-ans
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1256 (enriched-warn "Unknown annotations: %s" unknown-ans))))))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1257
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1258 (defun enriched-get-file-width ()
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1259 "Look for file width information on this line."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1260 (save-excursion
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1261 (if (search-forward "width:" (save-excursion (end-of-line) (point)) t)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1262 (read (current-buffer)))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1263
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1264 (defun enriched-move-to-next-annotation ()
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1265 "Advances point to next annotation, dealing with special items on the way.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1266 Returns t if one was found, otherwise nil."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1267 (while (and (re-search-forward enriched-decode-interesting-regexp nil t)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1268 (goto-char (match-beginning 0))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1269 (not (looking-at enriched-annotation-regexp)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1270 (let ((regexps enriched-decode-special-alist))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1271 (while (and regexps
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1272 (not (looking-at (car (car regexps)))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1273 (enriched-pop regexps))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1274 (if regexps
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1275 (funcall (cdr (car regexps)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1276 (forward-char 1)))) ; nothing found
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1277 (not (eobp)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1278
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1279 ;;; enriched.el ends here