annotate lisp/enriched.el @ 9865:9ca8b94a9f07

(vi-kill-region): Pass args to kill-region. (vi-mark-region): Don't pass unexpected args.
author Karl Heuer <kwzh@gnu.org>
date Wed, 09 Nov 1994 06:10:46 +0000
parents f8aa9230c3fa
children 66c7e651194d
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-indent-increment 4
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
56 "*Number of columns to indent for an <Indent> annotation.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
57 Should agree with the definition of <Indent> in enriched-annotation-alist.")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
58
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
59 (defvar enriched-fill-after-visiting t
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
60 "If t, fills paragraphs when reading in enriched documents.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
61 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
62 it will query you whether to fill.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
63 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
64 stored in the file.")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
65
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
66 (defvar enriched-default-justification 'left
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
67 "*Method of justifying text not otherwise specified.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
68 Can be `left' `right' `both' `center' or `none'.")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
69
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
70 (defvar enriched-auto-save-interval 1000
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
71 "*`Auto-save-interval' to use for `enriched-mode'.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
72 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
73 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
74 actively working.")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
75
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
76 ;;Unimplemented:
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
77 ;(defvar enriched-aggressive-auto-fill t
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
78 ; "*If t, try to keep things properly filled and justified always.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
79 ;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
80 ;The difference between aggressive and non-aggressive is subtle right now, but
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
81 ;may become stronger in the future.")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
82
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
83 ;; Unimplemented:
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
84 ; (defvar enriched-keep-ignored-items nil
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
85 ; "*If t, keep track of codes that are not understood.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
86 ; Otherwise they are deleted on reading the file, and not written out.")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
87
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
88 ;;Unimplemented:
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
89 ;(defvar enriched-electric-indentation t
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
90 ; "*If t, newlines and following indentation stick together.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
91 ;Deleting a newline or any part of the indenation will delete the whole
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
92 ;stretch.")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
93
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
94 ;;;
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
95 ;;; Set up faces & display table
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
96 ;;;
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
97
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
98 ;; A slight cheat - all emacs's faces are fixed-width.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
99 ;; The idea is just to pick one that looks different from the default.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
100 (if (internal-find-face 'fixed)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
101 nil
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
102 (make-face 'fixed)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
103 (if window-system
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
104 (set-face-font 'fixed
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
105 (car (or (x-list-fonts "*fixed-medium*"
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
106 'default (selected-frame))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
107 (x-list-fonts "*fixed*"
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
108 'default (selected-frame)))))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
109
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
110 (if (internal-find-face 'excerpt)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
111 nil
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
112 (make-face 'excerpt)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
113 (if window-system
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
114 (make-face-italic 'excerpt)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
115
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
116 ;;; The following two faces should not appear on menu.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
117 (if (boundp 'facemenu-unlisted-faces)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
118 (setq facemenu-unlisted-faces
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
119 (append '(enriched-code-face enriched-indentation-face)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
120 facemenu-unlisted-faces)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
121
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
122 (if (internal-find-face 'enriched-code-face)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
123 nil
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
124 (make-face 'enriched-code-face)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
125 (if window-system
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
126 (set-face-background 'enriched-code-face
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
127 (if (x-display-color-p)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
128 "LightSteelBlue"
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
129 "gray35"))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
130
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
131 (if (internal-find-face 'enriched-indentation-face)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
132 nil
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
133 (make-face 'enriched-indentation-face)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
134 (if window-system
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
135 (set-face-background 'enriched-indentation-face
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
136 (if (x-display-color-p)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
137 "DarkSlateBlue"
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
138 "gray25"))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
139
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
140 (defvar enriched-display-table (make-display-table))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
141 (aset enriched-display-table ?\f (make-vector (1- (frame-width)) ?-))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
142
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
143 (defvar enriched-hard-newline
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
144 (let ((s "\n"))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
145 (put-text-property 0 1 'hard-newline t s)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
146 s)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
147 "String used to indicate hard newline in a enriched buffer.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
148 This is a newline with the `hard-newline' property set.")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
149
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
150 (defvar enriched-show-codes nil "See the function of the same name")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
151
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
152 (defvar enriched-par-props '(left-margin right-margin justification
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
153 front-sticky)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
154 "Text-properties that usually apply to whole paragraphs.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
155 These are set front-sticky everywhere except at hard newlines.")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
156
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
157 ;;;
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
158 ;;; Variables controlling the file format
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
159 ;;; (bidirectional)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
160
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
161 (defvar enriched-initial-annotation
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
162 (lambda ()
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
163 (format "<param>-*-enriched-*-width:%d
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
164 </param>" (enriched-text-width)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
165 "What to insert at the start of a text/enriched file.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
166 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
167 expression, which is evaluated to get the string to insert.")
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-format "<%s%s>"
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
170 "General format of enriched-text annotations.")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
171
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
172 (defvar enriched-annotation-regexp "<\\(/\\)?\\([-A-za-z0-9]+\\)>"
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
173 "Regular expression matching enriched-text annotations.")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
174
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
175 (defvar enriched-downcase-annotations t
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
176 "Set to t if case of annotations is irrelevant.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
177 In this case all annotations listed in enriched-annotation-list should be
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
178 lowercase, and annotations read from files will be downcased before being
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
179 compared to that list.")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
180
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
181 (defvar enriched-list-valued-properties '(face unknown)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
182 "List of properties whose values can be lists.")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
183
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
184 (defvar enriched-annotation-alist
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
185 '((face (bold-italic "bold" "italic")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
186 (bold "bold")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
187 (italic "italic")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
188 (underline "underline")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
189 (fixed "fixed")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
190 (excerpt "excerpt")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
191 (default )
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
192 (nil enriched-encode-other-face))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
193 (hard-newline (nil enriched-encode-hard-newline))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
194 (left-margin (4 "indent"))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
195 (right-margin (4 "indentright"))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
196 (justification (none "nofill")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
197 (right "flushright")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
198 (left "flushleft")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
199 (both "flushboth")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
200 (center "center"))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
201 (PARAMETER (t "param")) ; Argument of preceding annotation
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
202 ;; The following are not part of the standard:
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
203 (FUNCTION (enriched-decode-foreground "x-color")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
204 (enriched-decode-background "x-bg-color"))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
205 (read-only (t "x-read-only"))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
206 (unknown (nil enriched-encode-unknown)) ;anything else found
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
207 ; (font-size (2 "bigger") ; unimplemented
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
208 ; (-2 "smaller"))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
209 )
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
210 "List of definitions of text/enriched annotations.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
211 Each element is a list whose car is a PROPERTY, and the following
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
212 elements are VALUES of that property followed by zero or more ANNOTATIONS.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
213 Whenever the property takes on that value, each of the annotations
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
214 will be inserted into the file. Only the name of the annotation
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
215 should be specified, it will be formatted by `enriched-make-annotation'.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
216 At the point that the property stops having that value, the matching
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
217 negated annotation will be inserted (it may actually be closed earlier and
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
218 reopened, if necessary, to keep proper nesting).
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
219
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
220 Conversely, when annotations are read, they are searched for in this list, and
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
221 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
222 conditions are satisfied is used. If enriched-downcase-annotations is true,
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
223 then annotations in this list should be listed in lowercase, and annotations
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
224 read from the file will be downcased.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
225
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
226 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
227 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
228 Thus, given the entry \(left-margin \(4 \"indent\")), `enriched-encode-region'
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
229 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
230
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
231 If the VALUE is nil, then instead of annotations, a function should be
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
232 specified. This function is used as a default: it is called for all
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
233 transitions not explicitly listed in the table. The function is called with
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
234 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
235 list of annotations like `enriched-loc-annotations' does, or may directly
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
236 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
237 other way of decoding the annotations thus produced.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
238
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
239 [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
240 be appended to the surrounding value of the property.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
241
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
242 For decoding, there are some special symbols that can be used in the
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
243 \"property\" slot. Annotations listed under the pseudo-property PARAMETER are
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
244 considered to be arguments of the immediately surrounding annotation; the text
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
245 between the opening and closing parameter annotations is deleted from the
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
246 buffer but saved as a string. The surrounding annotation should be listed
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
247 under the pseudo-property FUNCTION. Instead of inserting a text-property for
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
248 this annotation, enriched-decode-buffer will call the function listed in the
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
249 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
250 the rest of the arguments being any PARAMETERs found in that region.")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
251
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
252 ;;; This is not needed for text/enriched format, since all annotations are in
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
253 ;;; a standard form:
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
254 ;(defvar enriched-special-annotations-alist nil
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
255 ; "List of annotations not formatted in the usual way.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
256 ;Each element has the form (ANNOTATION BEGIN END), where
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
257 ;ANNOTATION is the annotation's name, which is a symbol (normal
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
258 ;annotations are named with strings, special ones with symbols),
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
259 ;BEGIN is the literal string to insert as the opening annotation, and
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
260 ;END is the literal string to insert as the close.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
261 ;This is used only for encoding. Typically, each will have an entry in
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
262 ;enriched-decode-special-alist to deal with its decoding.")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
263
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
264 ;;; Encoding variables
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
265
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
266 (defvar enriched-encode-interesting-regexp "<"
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
267 "Regexp matching the start of something that may require encoding.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
268 All text-property changes are also considered \"interesting\".")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
269
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
270 (defvar enriched-encode-special-alist
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
271 '(("<" . (lambda () (insert-and-inherit "<"))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
272 "List of special operations for writing enriched files.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
273 Each element has the form \(STRING . FUNCTION).
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
274 Whenever one of the strings \(including its properties, if any)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
275 is found, the corresponding function is called.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
276 Match data is available to the function.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
277 See `enriched-decode-special-alist' for instructions on decoding special
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
278 items.")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
279
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
280 (defvar enriched-ignored-ok
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
281 '(front-sticky rear-nonsticky)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
282 "Properties that are not written into enriched files.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
283 Generally this list should only contain properties that just for enriched's
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
284 internal purposes; other properties that cannot be recorded will generate
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
285 a warning message to the user since information will be lost.")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
286
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
287 ;;; Decoding variables
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
288
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
289 (defvar enriched-decode-interesting-regexp "[<\n]"
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
290 "Regexp matching the start of something that may require decoding.")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
291
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
292 (defvar enriched-decode-special-alist
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
293 '(("<<" . (lambda () (delete-char 1) (forward-char 1)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
294 ("\n\n" . enriched-decode-hard-newline))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
295 "List of special operations for reading enriched files.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
296 Each element has the form \(STRING . FUNCTION).
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
297 Whenever one of the strings is found, the corresponding function is called,
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
298 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
299 the function. Should leave point where next search should start.")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
300
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
301 ;;; Internal variables
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-mode nil
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
304 "True if `enriched-mode' \(which see) is enabled.")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
305 (make-variable-buffer-local 'enriched-mode)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
306
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
307 (if (not (assq 'enriched-mode minor-mode-alist))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
308 (setq minor-mode-alist
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
309 (cons '(enriched-mode " Enriched")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
310 minor-mode-alist)))
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-mode-hooks nil
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
313 "Functions to run when entering `enriched-mode'.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
314 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
315 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
316 them and their old values to `enriched-old-bindings'.")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
317
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
318 (defvar enriched-old-bindings nil
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
319 "Store old variable values that we change when entering mode.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
320 The value is a list of \(VAR VALUE VAR VALUE...).")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
321 (make-variable-buffer-local 'enriched-old-bindings)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
322
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
323 (defvar enriched-translated nil
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
324 "True if buffer has already been decoded.")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
325 (make-variable-buffer-local 'enriched-translated)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
326
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
327 (defvar enriched-text-width nil)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
328 (make-variable-buffer-local 'enriched-text-width)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
329
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
330 (defvar enriched-ignored-list nil)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
331
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
332 (defvar enriched-open-ans nil)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
333
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
334 ;;;
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
335 ;;; Functions defining the format of annotations
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
336 ;;;
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
337
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
338 (defun enriched-make-annotation (name positive)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
339 "Format an annotation called NAME.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
340 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
341 matching close."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
342 ;; Could be used for annotations not following standard form:
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
343 ; (if (symbolp name)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
344 ; (if positive
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
345 ; (elt (assq name enriched-special-annotations-alist) 1)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
346 ; (elt (assq name enriched-special-annotations-alist) 2)) )
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
347 (if (stringp name)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
348 (format enriched-annotation-format (if positive "" "/") name)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
349 ;; has parameters.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
350 (if positive
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
351 (let ((item (car name))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
352 (params (cdr name)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
353 (concat (format enriched-annotation-format "" item)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
354 (mapconcat (lambda (i) (concat "<param>" i "</param>"))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
355 params "")))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
356 (format enriched-annotation-format "/" (car name)))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
357
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
358 (defun enriched-annotation-name (a)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
359 "Find the name of an ANNOTATION."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
360 (save-match-data
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
361 (if (string-match enriched-annotation-regexp a)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
362 (substring a (match-beginning 2) (match-end 2)))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
363
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
364 (defun enriched-annotation-positive-p (a)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
365 "Returns t if ANNOTATION is positive (open),
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
366 or nil if it is a closing (negative) annotation."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
367 (save-match-data
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
368 (and (string-match enriched-annotation-regexp a)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
369 (not (match-beginning 1)))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
370
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
371 (defun enriched-encode-unknown (old new)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
372 "Deals with re-inserting unknown annotations."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
373 (cons (if old (list old))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
374 (if new (list new))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
375
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
376 (defun enriched-encode-hard-newline (old new)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
377 "Deal with encoding `hard-newline' property change."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
378 ;; 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
379 ;; one- so all property changes are put off until after all the newlines.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
380 (if (and new (enriched-justification)) ; no special processing inside NoFill
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
381 (let* ((length (skip-chars-forward "\n"))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
382 (s (make-string length ?\n)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
383 (backward-delete-char (1- length))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
384 (add-text-properties 0 length (text-properties-at (1- (point))) s)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
385 (insert s)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
386 (backward-char (+ length 1)))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
387
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
388 (defun enriched-decode-hard-newline ()
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
389 "Deal with newlines while decoding file."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
390 ;; We label double newlines as `hard' and single ones as soft even in NoFill
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
391 ;; regions; otherwise the paragraph functions would not do anything
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
392 ;; reasonable in NoFill regions.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
393 (let ((nofill (equal "nofill" ; find out if we're in NoFill region
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
394 (enriched-which-assoc
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
395 '("nofill" "flushleft" "flushright" "center"
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
396 "flushboth")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
397 enriched-open-ans)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
398 (n (skip-chars-forward "\n")))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
399 (delete-char (- n))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
400 (enriched-insert-hard-newline (if nofill n (1- n)))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
401
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
402 (defun enriched-encode-other-face (old new)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
403 "Generate annotations for random face change.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
404 One annotation each for foreground color, background color, italic, etc."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
405 (cons (and old (enriched-face-ans old))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
406 (and new (enriched-face-ans new))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
407
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
408 (defun enriched-face-ans (face)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
409 "Return annotations specifying FACE."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
410 (cond ((string-match "^fg:" (symbol-name face))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
411 (list (list "x-color" (substring (symbol-name face) 3))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
412 ((string-match "^bg:" (symbol-name face))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
413 (list (list "x-bg-color" (substring (symbol-name face) 3))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
414 ((let* ((fg (face-foreground face))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
415 (bg (face-background face))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
416 (props (face-font face t))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
417 (ans (cdr (enriched-annotate-change 'face nil props))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
418 (if fg (enriched-push (list "x-color" fg) ans))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
419 (if bg (enriched-push (list "x-bg-color" bg) ans))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
420 ans))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
421
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
422 (defun enriched-decode-foreground (from to color)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
423 (let ((face (intern (concat "fg:" color))))
9694
f8aa9230c3fa (enriched-mode): Add autoload cookie.
Boris Goldowsky <boris@gnu.org>
parents: 9677
diff changeset
424 (cond ((internal-find-face face))
f8aa9230c3fa (enriched-mode): Add autoload cookie.
Boris Goldowsky <boris@gnu.org>
parents: 9677
diff changeset
425 ((and window-system (facemenu-get-face face)))
f8aa9230c3fa (enriched-mode): Add autoload cookie.
Boris Goldowsky <boris@gnu.org>
parents: 9677
diff changeset
426 (window-system
f8aa9230c3fa (enriched-mode): Add autoload cookie.
Boris Goldowsky <boris@gnu.org>
parents: 9677
diff changeset
427 (enriched-warn "Color \"%s\" not defined:
f8aa9230c3fa (enriched-mode): Add autoload cookie.
Boris Goldowsky <boris@gnu.org>
parents: 9677
diff changeset
428 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
429 ((make-face face)
f8aa9230c3fa (enriched-mode): Add autoload cookie.
Boris Goldowsky <boris@gnu.org>
parents: 9677
diff changeset
430 (enriched-warn "Color \"%s\" can't be displayed." color)))
9676
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
431 (list from to 'face face)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
432
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
433 (defun enriched-decode-background (from to color)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
434 (let ((face (intern (concat "bg:" color))))
9694
f8aa9230c3fa (enriched-mode): Add autoload cookie.
Boris Goldowsky <boris@gnu.org>
parents: 9677
diff changeset
435 (cond ((internal-find-face face))
f8aa9230c3fa (enriched-mode): Add autoload cookie.
Boris Goldowsky <boris@gnu.org>
parents: 9677
diff changeset
436 ((and window-system (facemenu-get-face face)))
f8aa9230c3fa (enriched-mode): Add autoload cookie.
Boris Goldowsky <boris@gnu.org>
parents: 9677
diff changeset
437 (window-system
f8aa9230c3fa (enriched-mode): Add autoload cookie.
Boris Goldowsky <boris@gnu.org>
parents: 9677
diff changeset
438 (enriched-warn "Color \"%s\" not defined:
f8aa9230c3fa (enriched-mode): Add autoload cookie.
Boris Goldowsky <boris@gnu.org>
parents: 9677
diff changeset
439 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
440 ((make-face face)
f8aa9230c3fa (enriched-mode): Add autoload cookie.
Boris Goldowsky <boris@gnu.org>
parents: 9677
diff changeset
441 (enriched-warn "Color \"%s\" can't be displayed." color)))
9676
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
442 (list from to 'face face)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
443
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
444 ;;;
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
445 ;;; NOTE: Everything below this point is intended to be independent of the file
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
446 ;;; format, which is defined by the variables and functions above.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
447 ;;;
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
448
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
449 ;;;
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
450 ;;; Define the mode
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
451 ;;;
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
452
9694
f8aa9230c3fa (enriched-mode): Add autoload cookie.
Boris Goldowsky <boris@gnu.org>
parents: 9677
diff changeset
453 ;;;###autoload
9676
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
454 (defun enriched-mode (&optional arg notrans)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
455 "Minor mode for editing text/enriched files.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
456 These are files with embedded formatting information in the MIME standard
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
457 text/enriched format.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
458
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
459 Turning the mode on or off interactively will query whether the buffer
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
460 should be translated into or out of text/enriched format immediately.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
461 Noninteractively translation is done without query unless the optional
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
462 second argument NO-TRANS is non-nil.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
463 Turning mode on runs `enriched-mode-hooks'.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
464
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
465 More information about enriched-mode is available in the file
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
466 etc/enriched.doc in the Emacs distribution directory.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
467
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
468 Commands:
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
469
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
470 \\<enriched-mode-map>\\{enriched-mode-map}"
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
471 (interactive "P")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
472 (let ((mod (buffer-modified-p)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
473 (cond ((or (<= (prefix-numeric-value arg) 0)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
474 (and enriched-mode (null arg)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
475 ;; Turn mode off
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
476 (setq enriched-mode nil)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
477 (if (if (interactive-p)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
478 (y-or-n-p "Translate buffer into text/enriched format?")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
479 (not notrans))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
480 (progn (enriched-encode-region)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
481 (mapcar (lambda (x)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
482 (remove-text-properties
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
483 (point-min) (point-max)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
484 (list (if (consp x) (car x) x) nil)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
485 (append enriched-ignored-ok
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
486 enriched-annotation-alist))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
487 (setq enriched-translated nil)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
488 ;; restore old variable values
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
489 (while enriched-old-bindings
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
490 (funcall 'set (car enriched-old-bindings)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
491 (car (cdr enriched-old-bindings)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
492 (setq enriched-old-bindings (cdr (cdr enriched-old-bindings))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
493 (remove-hook 'write-region-annotate-functions
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
494 'enriched-annotate-function t)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
495 (remove-hook 'after-change-functions 'enriched-nogrow-hook t))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
496 (enriched-mode nil) ; Mode already on; do nothing.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
497 (t ; Turn mode on
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
498 ;; save old variable values before we change them.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
499 (setq enriched-mode t
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
500 enriched-old-bindings
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
501 (list 'indent-line-function indent-line-function
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
502 'auto-fill-function auto-fill-function
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
503 'buffer-display-table buffer-display-table
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
504 'fill-column fill-column
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
505 'auto-save-interval auto-save-interval
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
506 'sentence-end-double-space sentence-end-double-space))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
507 (make-local-variable 'auto-fill-function)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
508 (make-local-variable 'auto-save-interval)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
509 (make-local-variable 'indent-line-function)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
510 (make-local-variable 'sentence-end-double-space)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
511 (setq buffer-display-table enriched-display-table
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
512 indent-line-function 'enriched-indent-line
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
513 auto-fill-function 'enriched-auto-fill-function
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
514 fill-column 0 ; always run auto-fill-function
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
515 auto-save-interval enriched-auto-save-interval
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
516 sentence-end-double-space nil) ; Weird in Center&FlushRight
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
517 ;; Add hooks
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
518 (add-hook 'write-region-annotate-functions
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
519 'enriched-annotate-function)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
520 (add-hook 'after-change-functions 'enriched-nogrow-hook)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
521
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
522 (put-text-property (point-min) (point-max)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
523 'front-sticky enriched-par-props)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
524
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
525 (if (and (not enriched-translated)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
526 (if (interactive-p)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
527 (y-or-n-p "Does buffer need to be translated now? ")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
528 (not notrans)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
529 (progn (enriched-decode-region)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
530 (setq enriched-translated t)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
531 (run-hooks 'enriched-mode-hooks)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
532 (set-buffer-modified-p mod)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
533 (force-mode-line-update)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
534
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
535 ;;;
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
536 ;;; Keybindings
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
537 ;;;
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
538
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
539 (defvar enriched-mode-map nil
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
540 "Keymap for `enriched-mode'.")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
541
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
542 (if (null enriched-mode-map)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
543 (fset 'enriched-mode-map (setq enriched-mode-map (make-sparse-keymap))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
544
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
545 (if (not (assq 'enriched-mode minor-mode-map-alist))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
546 (setq minor-mode-map-alist
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
547 (cons (cons 'enriched-mode enriched-mode-map)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
548 minor-mode-map-alist)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
549
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
550 (define-key enriched-mode-map "\r" 'enriched-newline)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
551 (define-key enriched-mode-map "\n" 'enriched-newline)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
552 (define-key enriched-mode-map "\C-a" 'enriched-beginning-of-line)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
553 (define-key enriched-mode-map "\C-o" 'enriched-open-line)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
554 (define-key enriched-mode-map "\M-{" 'enriched-backward-paragraph)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
555 (define-key enriched-mode-map "\M-}" 'enriched-forward-paragraph)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
556 (define-key enriched-mode-map "\M-q" 'enriched-fill-paragraph)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
557 (define-key enriched-mode-map "\M-S" 'enriched-set-justification-center)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
558 (define-key enriched-mode-map "\C-x\t" 'enriched-change-left-margin)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
559 (define-key enriched-mode-map "\C-c\C-l" 'enriched-set-left-margin)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
560 (define-key enriched-mode-map "\C-c\C-r" 'enriched-set-right-margin)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
561 (define-key enriched-mode-map "\C-c\C-s" 'enriched-show-codes)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
562 (define-key enriched-mode-map "\M-j" 'enriched-justification-menu-map)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
563
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
564 ;;; These extend the "Face" menu.
9677
8ff145bf72cf Don't try to make menu bindings when window-system==nil.
Boris Goldowsky <boris@gnu.org>
parents: 9676
diff changeset
565 (let ((menu (and window-system (car (where-is-internal facemenu-menu)))))
9676
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
566 (if (null menu)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
567 nil
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
568 (define-key enriched-mode-map
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
569 (apply 'vector (append menu '(Sep-faces))) '("------"))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
570 (define-key enriched-mode-map
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
571 (apply 'vector (append menu '(Justification)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
572 (cons "Justification" 'enriched-justification-menu-map))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
573 (define-key enriched-mode-map
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
574 (apply 'vector (append menu '(Indentation)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
575 (cons "Indentation" 'enriched-indentation-menu-map))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
576
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
577 ;;; The "Indentation" sub-menu:
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
578
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
579 (defvar enriched-indentation-menu-map (make-sparse-keymap "Indentation")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
580 "Submenu for indentation commands.")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
581 (defalias 'enriched-indentation-menu-map enriched-indentation-menu-map)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
582
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
583 (define-key enriched-indentation-menu-map [UnIndentRight]
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
584 (cons "UnIndentRight" 'enriched-unindent-right))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
585 (define-key enriched-indentation-menu-map [IndentRight]
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
586 (cons "IndentRight" 'enriched-indent-right))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
587 (define-key enriched-indentation-menu-map [Unindent]
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
588 (cons "UnIndent" 'enriched-unindent))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
589 (define-key enriched-indentation-menu-map [Indent]
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
590 (cons "Indent" ' enriched-indent))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
591
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
592 ;;; The "Justification" sub-menu:
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
593 (defvar enriched-justification-menu-map (make-sparse-keymap "Justification")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
594 "Submenu for text justification commands.")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
595 (defalias 'enriched-justification-menu-map enriched-justification-menu-map)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
596
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
597 (define-key enriched-justification-menu-map [?c]
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
598 (cons "Center" 'enriched-set-justification-center))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
599 (define-key enriched-justification-menu-map [?b]
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
600 (cons "Flush Both" 'enriched-set-justification-both))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
601 (define-key enriched-justification-menu-map [?r]
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
602 (cons "Flush Right" 'enriched-set-justification-right))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
603 (define-key enriched-justification-menu-map [?l]
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
604 (cons "Flush Left" 'enriched-set-justification-left))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
605 (define-key enriched-justification-menu-map [?u]
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
606 (cons "Unfilled" 'enriched-set-nofill))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
607
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
608 ;;;
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
609 ;;; Interactive Functions
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
610 ;;;
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
611
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
612 (defun enriched-newline (n)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
613 "Insert N hard newlines.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
614 These are newlines that will not be affected by paragraph filling or
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
615 justification; they are used for necessary line breaks or to separate
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
616 paragraphs."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
617 (interactive "*p")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
618 (enriched-auto-fill-function)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
619 (while (> n 0)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
620 (enriched-insert-hard-newline 1)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
621 (end-of-line 0)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
622 (enriched-justify-line)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
623 (beginning-of-line 2)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
624 (setq n (1- n)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
625 (enriched-indent-line))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
626
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
627 (defun enriched-open-line (arg)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
628 "Inserts a newline and leave point before it.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
629 With arg N, inserts N newlines. Makes sure all lines are properly indented."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
630 (interactive "*p")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
631 (save-excursion
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
632 (enriched-newline arg))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
633 (enriched-auto-fill-function)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
634 (end-of-line))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
635
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
636 (defun enriched-beginning-of-line (&optional n)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
637 "Move point to the beginning of the text part of the current line.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
638 This is after all indentation due to left-margin setting or center or right
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
639 justification, but before any literal spaces or tabs used for indentation.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
640 With argument ARG not nil or 1, move forward ARG - 1 lines first.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
641 If scan reaches end of buffer, stop there without error."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
642 (interactive "p")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
643 (beginning-of-line n)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
644 ; (if (interactive-p) (enriched-justify-line))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
645 (goto-char
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
646 (or (text-property-any (point) (point-max) 'enriched-indentation nil)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
647 (point-max))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
648
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
649 (defun enriched-backward-paragraph (n)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
650 "Move backward N paragraphs.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
651 Hard newlines are considered to be the only paragraph separators."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
652 (interactive "p")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
653 (enriched-forward-paragraph (- n)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
654
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
655 (defun enriched-forward-paragraph (n)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
656 "Move forward N paragraphs.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
657 Hard newlines are considered to be the only paragraph separators."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
658 (interactive "p")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
659 (if (> n 0)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
660 (while (> n 0)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
661 (skip-chars-forward " \t\n")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
662 (enriched-end-of-paragraph)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
663 (setq n (1- n)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
664 (while (< n 0)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
665 (skip-chars-backward " \t\n")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
666 (enriched-beginning-of-paragraph)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
667 (setq n (1+ n)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
668 (enriched-beginning-of-line)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
669
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
670 (defun enriched-fill-paragraph ()
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
671 "Make the current paragraph fit between its left and right margins."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
672 (interactive)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
673 (save-excursion
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
674 (enriched-fill-region-as-paragraph (enriched-beginning-of-paragraph)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
675 (enriched-end-of-paragraph))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
676
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
677 (defun enriched-indent (b e)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
678 "Make the left margin of the region larger."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
679 (interactive "r")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
680 (enriched-change-left-margin b e enriched-indent-increment))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
681
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
682 (defun enriched-unindent (b e)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
683 "Make the left margin of the region smaller."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
684 (interactive "r")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
685 (enriched-change-left-margin b e (- enriched-indent-increment)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
686
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
687 (defun enriched-indent-right (b e)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
688 "Make the right margin of the region larger."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
689 (interactive "r")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
690 (enriched-change-right-margin b e enriched-indent-increment))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
691
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
692 (defun enriched-unindent-right (b e)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
693 "Make the right margin of the region smaller."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
694 (interactive "r")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
695 (enriched-change-right-margin b e (- enriched-indent-increment)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
696
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
697 (defun enriched-set-nofill (b e)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
698 "Disable automatic filling in the region.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
699 Actually applies to all lines ending in the region.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
700 If mark is not active, applies to the current line."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
701 (interactive (enriched-region-pars))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
702 (enriched-set-justification b e 'none))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
703
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
704 (defun enriched-set-justification-left (b e)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
705 "Declare the region to be left-justified.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
706 This is usually the default, but see `enriched-default-justification'."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
707 (interactive (enriched-region-pars))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
708 (enriched-set-justification b e 'left))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
709
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
710 (defun enriched-set-justification-right (b e)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
711 "Declare paragraphs in the region to be right-justified:
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
712 Flush at the right margin and ragged on the left.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
713 If mark is not active, applies to the current paragraph."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
714 (interactive (enriched-region-pars))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
715 (enriched-set-justification b e 'right))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
716
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
717 (defun enriched-set-justification-both (b e)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
718 "Declare the region to be fully justified.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
719 If mark is not active, applies to the current paragraph."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
720 (interactive (enriched-region-pars))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
721 (enriched-set-justification b e 'both))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
722
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
723 (defun enriched-set-justification-center (b e)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
724 "Make each line in the region centered.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
725 If mark is not active, applies to the current paragraph."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
726 (interactive (enriched-region-pars))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
727 (enriched-set-justification b e 'center))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
728
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
729 ;;;
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
730 ;;; General list/stack manipulation
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
731 ;;;
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
732
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
733 (defmacro enriched-push (item stack)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
734 "Push ITEM onto STACK.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
735 STACK should be a symbol whose value is a list."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
736 (` (setq (, stack) (cons (, item) (, stack)))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
737
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
738 (defmacro enriched-pop (stack)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
739 "Remove and return first item on STACK."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
740 (` (let ((pop-item (car (, stack))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
741 (setq (, stack) (cdr (, stack)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
742 pop-item)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
743
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
744 (defun enriched-delq1 (cons list)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
745 "Remove the given CONS from LIST by side effect.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
746 Since CONS could be the first element of LIST, write
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
747 `(setq foo (enriched-delq1 element foo))' to be sure of changing the value
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
748 of `foo'."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
749 (if (eq cons list)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
750 (cdr list)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
751 (let ((p list))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
752 (while (not (eq (cdr p) cons))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
753 (if (null p) (error "enriched-delq1: Attempt to delete a non-element"))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
754 (setq p (cdr p)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
755 ;; Now (cdr p) is the cons to delete
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
756 (setcdr p (cdr cons))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
757 list)))
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-make-list-uniq (list)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
760 "Destructively remove duplicates from LIST.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
761 Compares using `eq'."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
762 (let ((l list))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
763 (while l
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
764 (setq l (setcdr l (delq (car l) (cdr l)))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
765 list))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
766
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
767 (defun enriched-make-relatively-unique (a b)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
768 "Delete common elements of lists A and B, return as pair.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
769 Compares using `equal'."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
770 (let* ((acopy (copy-sequence a))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
771 (bcopy (copy-sequence b))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
772 (tail acopy))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
773 (while tail
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
774 (let ((dup (member (car tail) bcopy))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
775 (next (cdr tail)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
776 (if dup (setq acopy (enriched-delq1 tail acopy)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
777 bcopy (enriched-delq1 dup bcopy)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
778 (setq tail next)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
779 (cons acopy bcopy)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
780
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
781 (defun enriched-common-tail (a b)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
782 "Given two lists that have a common tail, return it.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
783 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
784 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
785 returns nil."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
786 (let ((la (length a))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
787 (lb (length b)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
788 ;; Make sure they are the same length
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
789 (while (> la lb)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
790 (setq a (cdr a)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
791 la (1- la)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
792 (while (> lb la)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
793 (setq b (cdr b)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
794 lb (1- lb))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
795 (while (not (equal a b))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
796 (setq a (cdr a)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
797 b (cdr b)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
798 a)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
799
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
800 (defun enriched-which-assoc (items list)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
801 "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
802 (let (res)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
803 (while list
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
804 (if (setq res (member (car (car list)) items))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
805 (setq res (car res)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
806 list nil)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
807 (setq list (cdr list))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
808 res))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
809
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
810 (defun enriched-reorder (items order)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
811 "Arrange ITEMS to following partial ORDER.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
812 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
813 ORDER. Unmatched items will go last."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
814 (if order
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
815 (let ((item (member (car order) items)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
816 (if item
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
817 (cons (car item)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
818 (enriched-reorder (enriched-delq1 item items)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
819 (cdr order)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
820 (enriched-reorder items (cdr order))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
821 items))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
822
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
823 ;;;
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
824 ;;; Utility functions
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
825 ;;;
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
826
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
827 (defun enriched-get-face-attribute (attr face &optional frame)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
828 "Get an attribute of a face or list of faces.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
829 ATTRIBUTE should be one of the functions `face-font' `face-foreground',
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
830 `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
831 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
832 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
833 omitted or nil, use the selected frame."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
834 (cond ((null face) nil)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
835 ((or (symbolp face) (internal-facep face)) (funcall attr face frame))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
836 ((funcall attr (car face) frame))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
837 ((enriched-get-face-attribute attr (cdr face) frame))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
838
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
839 (defun enriched-region-pars ()
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
840 "Return region expanded to begin and end at paragraph breaks.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
841 If the region is not active, this is just the current paragraph.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
842 A paragraph does not count as overlapping the region if only whitespace is
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
843 overlapping. Return value is a list of two numers, the beginning and end of
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
844 the defined region."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
845 (save-excursion
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
846 (let* ((b (progn (if mark-active (goto-char (region-beginning)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
847 (enriched-beginning-of-paragraph)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
848 (e (progn (if mark-active (progn (goto-char (region-end))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
849 (skip-chars-backward " \t\n" b)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
850 (min (point-max)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
851 (1+ (enriched-end-of-paragraph))))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
852 (list b e))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
853
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
854 (defun enriched-end-of-paragraph ()
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
855 "Move to the end of the current paragraph.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
856 Only hard newlines delimit paragraphs. Returns point."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
857 (interactive)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
858 (if (not (bolp)) (backward-char 1))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
859 (if (enriched-search-forward-with-props enriched-hard-newline nil 1)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
860 (backward-char 1))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
861 (point))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
862
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
863 (defun enriched-beginning-of-paragraph ()
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
864 "Move to beginning of the current paragraph.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
865 Only hard newlines delimit paragraphs. Returns point."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
866 (interactive)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
867 (if (not (eolp)) (forward-char 1))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
868 (if (enriched-search-backward-with-props enriched-hard-newline nil 1)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
869 (forward-char 1))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
870 (point))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
871
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
872 (defun enriched-overlays-overlapping (begin end &optional test)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
873 "Return a list of the overlays which overlap the specified region.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
874 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
875 argument, and only those for which it is true are returned."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
876 (overlay-recenter begin)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
877 (let ((res nil)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
878 (overlays (cdr (overlay-lists)))) ; includes all ending after BEGIN
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
879 (while overlays
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
880 (if (and (< (overlay-start (car overlays)) end)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
881 (or (not test)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
882 (funcall test (car overlays))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
883 (enriched-push (car overlays) res))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
884 (setq overlays (cdr overlays)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
885 res))
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-show-codes (&rest which)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
888 "Enable or disable highlighting of special regions.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
889 With argument null or `none', turns off highlighting.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
890 If argument is `newline', turns on display of hard newlines.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
891 If argument is `indent', highlights the automatic indentation at the beginning
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
892 of each line.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
893 If argument is `margin', highlights all regions with non-standard margins."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
894 (interactive
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
895 (list (intern (completing-read "Show which codes: "
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
896 '(("none") ("newline") ("indent") ("margin"))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
897 nil t))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
898 (if (null which)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
899 (setq enriched-show-codes nil)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
900 (setq enriched-show-codes which))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
901 ;; First delete current overlays
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
902 (let* ((ol (overlay-lists))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
903 (overlays (append (car ol) (cdr ol))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
904 (while overlays
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
905 (if (eq (overlay-get (car overlays) 'face) 'enriched-code-face)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
906 (delete-overlay (car overlays)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
907 (setq overlays (cdr overlays))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
908 ;; Now add new ones for each thing displayed.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
909 (if (null which)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
910 (message "Code display off."))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
911 (while which
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
912 (cond ((eq (car which) 'margin)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
913 (enriched-show-margin-codes))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
914 ((eq (car which) 'indent)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
915 (enriched-map-property-regions 'enriched-indentation
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
916 (lambda (v b e)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
917 (if v (enriched-show-region-as-code b e 'indent)))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
918 ((eq (car which) 'newline)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
919 (save-excursion
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
920 (goto-char (point-min))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
921 (while (enriched-search-forward-with-props
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
922 enriched-hard-newline nil t)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
923 (enriched-show-region-as-code (match-beginning 0) (match-end 0)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
924 'newline)))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
925 (setq which (cdr which))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
926
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
927 (defun enriched-show-margin-codes (&optional from to)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
928 "Highlight regions with nonstandard left-margins.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
929 See `enriched-show-codes'."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
930 (enriched-map-property-regions 'left-margin
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
931 (lambda (v b e)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
932 (if (and v (> v 0))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
933 (enriched-show-region-as-code b e 'margin)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
934 from to)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
935 (enriched-map-property-regions 'right-margin
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
936 (lambda (v b e)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
937 (if (and v (> v 0))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
938 (enriched-show-region-as-code b e 'margin)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
939 from to))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
940
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
941 (defun enriched-show-region-as-code (from to type)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
942 "Display region between FROM and TO as a code if TYPE is displayed.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
943 Displays it only if TYPE is an element of `enriched-show-codes' or is t."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
944 (if (or (eq t type) (memq type enriched-show-codes))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
945 (let* ((old (enriched-overlays-overlapping
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
946 from to (lambda (o)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
947 (eq 'enriched-code-face
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
948 (overlay-get o 'face)))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
949 (new (if old (move-overlay (car old) from to)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
950 (make-overlay from to))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
951 (overlay-put new 'face 'enriched-code-face)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
952 (overlay-put new 'front-nogrow t)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
953 (if (eq type 'margin)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
954 (overlay-put new 'rear-grow t))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
955 (while (setq old (cdr old))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
956 (delete-overlay (car old))))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
957
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
958 (defun enriched-nogrow-hook (beg end old-length)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
959 "Implement front-nogrow and rear-grow for overlays.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
960 Normally overlays have opposite inheritance properties than
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
961 text-properties: they will expand to include text inserted at their
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
962 beginning, but not text inserted at their end. However,
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
963 if this function is an element of `after-change-functions', then
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
964 overlays with a non-nil value of the `front-nogrow' property will not
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
965 expand to include text that is inserted just in front of them, and
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
966 overlays with a non-nil value of the `rear-grow' property will
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
967 expand to include text that is inserted just after them."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
968 (if (not (zerop old-length))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
969 nil ;; not an insertion
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
970 (let ((overlays (overlays-at end)) o)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
971 (while overlays
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
972 (setq o (car overlays)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
973 overlays (cdr overlays))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
974 (if (and (overlay-get o 'front-nogrow)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
975 (= beg (overlay-start o)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
976 (move-overlay o end (overlay-end o)))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
977 (let ((overlays (overlays-at (1- beg))) o)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
978 (while overlays
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
979 (setq o (car overlays)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
980 overlays (cdr overlays))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
981 (if (and (overlay-get o 'rear-grow)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
982 (= beg (overlay-end o)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
983 (move-overlay o (overlay-start o) end))))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
984
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
985 (defun enriched-warn (&rest args)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
986 "Display a warning message.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
987 Arguments are given to `format' and the result is displayed in a buffer."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
988 (save-excursion
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
989 (let ((buf (current-buffer))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
990 (line (1+ (count-lines 1 (point))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
991 (mark (point-marker)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
992 (pop-to-buffer (get-buffer-create "*Enriched Warnings*"))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
993 (goto-char (point-max))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
994 (insert
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
995 ; (format "%s:%d: " (if (boundp 'enriched-file) enriched-file
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
996 ; (buffer-file-name buf))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
997 ; line)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
998 (apply (function format) args)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
999 "\n")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1000 (pop-to-buffer buf))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1001
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1002 (defun enriched-looking-at-with-props (string)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1003 "True if text at point is equal to STRING, including text props.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1004 This is a literal, not a regexp match.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1005 The buffer text must include all text properties that STRING has, in
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1006 the same places, but it is allowed to have others that STRING lacks."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1007 (let ((buffer-string (buffer-substring (point) (+ (point) (length string)))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1008 (and (string-equal string buffer-string)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1009 (enriched-text-properties-include string buffer-string))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1010
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1011 (defun enriched-search-forward-with-props
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1012 (string &optional bound noerror count)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1013 "Search forward for STRING, including its text properties.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1014 Set point to end of occurrence found, and return point.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1015 The match found must include all text properties that STRING has, in
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1016 the same places, but it is allowed to have others that STRING lacks.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1017 An optional second argument bounds the search; it is a buffer position.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1018 The match found must not extend after that position. nil is equivalent
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1019 to (point-max).
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1020 Optional third argument, if t, means if fail just return nil (no error).
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1021 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
1022 Optional fourth argument is repeat count--search for successive occurrences.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1023 See also the functions `match-beginning', `match-end' and `replace-match'."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1024 (interactive "sSearch for: ")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1025 (or bound (setq bound (point-max)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1026 (or count (setq count 1))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1027 (let ((start (point))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1028 (res t))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1029 (while (and res (> count 0))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1030 (while (and (setq res (search-forward string bound t))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1031 (not (enriched-text-properties-include
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1032 string (buffer-substring (match-beginning 0)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1033 (match-end 0))))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1034 (setq count (1- count)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1035 (cond (res)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1036 ((eq noerror t) (goto-char start) nil)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1037 (noerror (goto-char bound) nil)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1038 (t (goto-char start)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1039 (error "Search failed: %s" string)))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1040
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1041 (defun enriched-search-backward-with-props
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1042 (string &optional bound noerror count)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1043 "Search backward for STRING, including its text properties.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1044 Set point to the beginning of occurrence found, and return point.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1045 The match found must include all text properties that STRING has, in
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1046 the same places, but it is allowed to have others that STRING lacks.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1047 An optional second argument bounds the search; it is a buffer position.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1048 The match found must not start before that position. nil is equivalent
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1049 to (point-min).
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1050 Optional third argument, if t, means if fail just return nil (no error).
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1051 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
1052 Optional fourth argument is repeat count--search for successive occurrences.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1053 See also the functions `match-beginning', `match-end' and `replace-match'."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1054 (interactive "sSearch for: ")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1055 (or bound (setq bound (point-min)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1056 (or count (setq count 1))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1057 (let ((start (point))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1058 (res t))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1059 (while (and res (> count 0))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1060 (while (and (setq res (search-backward string bound t))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1061 (not (enriched-text-properties-include
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1062 string (buffer-substring (match-beginning 0)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1063 (match-end 0))))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1064 (setq count (1- count)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1065 (cond (res)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1066 ((eq noerror t) (goto-char start) nil)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1067 (noerror (goto-char bound) nil)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1068 (t (goto-char start)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1069 (error "Search failed: %s" string)))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1070
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1071 (defun enriched-text-properties-include (a b)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1072 "True if all of A's text-properties are also properties of B.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1073 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
1074 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
1075 (let ((loc (length a)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1076 (catch 'fail
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1077 (while (>= loc 0)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1078 (let ((plist (text-properties-at loc a)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1079 (while plist
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1080 (if (not (equal (car (cdr plist))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1081 (get-text-property loc (car plist) b)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1082 (throw 'fail nil))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1083 (setq plist (cdr (cdr plist)))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1084 (setq loc (1- loc)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1085 t)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1086
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1087 (defun enriched-map-property-regions (prop func &optional from to)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1088 "Apply a function to regions of the buffer based on a text property.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1089 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
1090 eq, the FUNCTION will be called. Optional arguments FROM and TO specify the
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1091 region over which to scan.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1092
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1093 The specified function receives three arguments: the VALUE of the property in
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1094 the region, and the START and END of each region."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1095 (save-excursion
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1096 (save-restriction
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1097 (if to (narrow-to-region (point-min) to))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1098 (goto-char (or from (point-min)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1099 (let ((begin (point))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1100 end
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1101 (marker (make-marker))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1102 (val (get-text-property (point) prop)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1103 (while (setq end (text-property-not-all begin (point-max) prop val))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1104 (move-marker marker end)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1105 (funcall func val begin (marker-position marker))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1106 (setq begin (marker-position marker)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1107 val (get-text-property marker prop)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1108 (if (< begin (point-max))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1109 (funcall func val begin (point-max)))))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1110
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1111 (put 'enriched-map-property-regions 'lisp-indent-hook 1)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1112
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1113 (defun enriched-insert-annotations (list &optional offset)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1114 "Apply list of annotations to buffer as write-region would.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1115 Inserts each element of LIST of buffer annotations at its appropriate place.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1116 Use second arg OFFSET if the annotations' locations are not
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1117 relative to the beginning of the buffer: annotations will be inserted
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1118 at their location-OFFSET+1 \(ie, the offset is the character number of
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1119 the first character in the buffer)."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1120 (if (not offset)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1121 (setq offset 0)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1122 (setq offset (1- offset)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1123 (let ((l (reverse list)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1124 (while l
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1125 (goto-char (- (car (car l)) offset))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1126 (insert (cdr (car l)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1127 (setq l (cdr l)))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1128
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1129 ;;;
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1130 ;;; Indentation, Filling, Justification
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1131 ;;;
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1132
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1133 (defun enriched-insert-hard-newline (n)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1134 ;; internal function; use enriched-newline for most purposes.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1135 (while (> n 0)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1136 (insert-and-inherit ?\n)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1137 (add-text-properties (1- (point)) (point)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1138 (list 'hard-newline t
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1139 'rear-nonsticky '(hard-newline)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1140 'front-sticky nil))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1141 (enriched-show-region-as-code (1- (point)) (point) 'newline)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1142 (setq n (1- n))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1143
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1144 (defun enriched-left-margin ()
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1145 "Return the left margin of this line.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1146 This is defined as the value of the text-property `left-margin' in
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1147 effect at the first character of the line, or the value of the
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1148 variable `left-margin' if this is nil, or 0."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1149 (save-excursion
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1150 (beginning-of-line)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1151 (or (get-text-property (point) 'left-margin) 0)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1152
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1153 (defun enriched-fill-column (&optional pos)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1154 "Return the fill-column in effect at POS or point.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1155 This is `enriched-text-width' minus the current `right-margin'
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1156 text-property."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1157 (- (enriched-text-width)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1158 (or (get-text-property (or pos (point)) 'right-margin) 0)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1159
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1160 (defun enriched-move-to-fill-column ()
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1161 "Move point to right margin of current line.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1162 For filling, the line should be broken before this point."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1163 ;; Defn: The first point where (enriched-fill-column) <= (current-column)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1164 (interactive)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1165 (goto-char
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1166 (catch 'found
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1167 (enriched-map-property-regions 'right-margin
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1168 (lambda (v b e)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1169 (goto-char (1- e))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1170 (if (<= (enriched-fill-column) (current-column))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1171 (progn (move-to-column (enriched-fill-column))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1172 (throw 'found (point)))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1173 (progn (beginning-of-line) (point))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1174 (progn (end-of-line) (point)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1175 (end-of-line)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1176 (point))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1177
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1178 (defun enriched-line-length ()
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1179 "Length of text part of current line."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1180 (save-excursion
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1181 (- (progn (end-of-line) (current-column))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1182 (progn (enriched-beginning-of-line) (current-column)))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1183
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1184 (defun enriched-text-width ()
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1185 "The width of unindented text in this window, in characters.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1186 This is the width of the window minus `enriched-default-right-margin'."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1187 (or enriched-text-width
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1188 (let ((ww (window-width)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1189 (setq enriched-text-width
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1190 (if (> ww enriched-default-right-margin)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1191 (- ww enriched-default-right-margin)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1192 ww)))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1193
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1194 (defun enriched-tag-indentation (from to)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1195 "Define region to be indentation."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1196 (add-text-properties from to '(enriched-indentation t
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1197 rear-nonsticky (enriched-indentation))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1198
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1199 (defun enriched-indent-line (&optional column)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1200 "Line-indenting primitive for enriched-mode.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1201 By default, indents current line to `enriched-left-margin'.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1202 Optional arg COLUMN asks for indentation to that column, eg to indent a
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1203 centered or flushright line."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1204 (save-excursion
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1205 (beginning-of-line)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1206 (or column (setq column (enriched-left-margin)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1207 (let ((bol (point)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1208 (if (not (get-text-property (point) 'enriched-indentation))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1209 nil ; no current indentation
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1210 (goto-char (or (text-property-any (point) (point-max)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1211 'enriched-indentation nil)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1212 (point)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1213 (if (> (current-column) column) ; too far right
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1214 (delete-region bol (point))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1215 (indent-to column)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1216 (if (= bol (point))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1217 nil
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1218 ;; Indentation gets same properties as first real char.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1219 (set-text-properties bol (point) (text-properties-at (point)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1220 (enriched-show-region-as-code bol (point) 'indent)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1221 (enriched-tag-indentation bol (point))))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1222
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1223 (defun enriched-insert-indentation (&optional from to)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1224 "Indent and justify each line in the region."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1225 (save-excursion
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1226 (save-restriction
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1227 (if to (narrow-to-region (point-min) to))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1228 (goto-char (or from (point-min)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1229 (if (not (bolp)) (forward-line 1))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1230 (while (not (eobp))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1231 (enriched-justify-line)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1232 (forward-line 1)))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1233
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1234 (defun enriched-delete-indentation (&optional from to)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1235 "Remove indentation and justification from region.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1236 Does not alter the left-margin and right-margin text properties, so the
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1237 indentation can be reconstructed. Tries only to remove whitespace that was
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1238 added automatically, not spaces and tabs inserted by user."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1239 (save-excursion
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1240 (save-restriction
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1241 (if to (narrow-to-region (point-min) to))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1242 (if from
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1243 (progn (goto-char from)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1244 (if (not (bolp)) (forward-line 1))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1245 (setq from (point))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1246 ;; Remove everything that has the enriched-indentation text
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1247 ;; property set, unless it is not at the left margin. In that case, the
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1248 ;; property must be there by mistake and should be removed.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1249 (enriched-map-property-regions 'enriched-indentation
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1250 (lambda (v b e)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1251 (if (null v)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1252 nil
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1253 (goto-char b)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1254 (if (bolp)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1255 (delete-region b e)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1256 (remove-text-properties b e '(enriched-indentation nil
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1257 rear-nonsticky nil)))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1258 from nil)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1259 ;; Remove spaces added for FlushBoth.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1260 (enriched-map-property-regions 'justification
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1261 (lambda (v b e)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1262 (if (eq v 'both)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1263 (enriched-squeeze-spaces b e)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1264 from nil))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1265
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1266 (defun enriched-change-left-margin (from to inc)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1267 "Adjust the left-margin property between FROM and TO by INCREMENT.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1268 If the given region includes the character at the left margin, it is extended
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1269 to include the indentation too."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1270 (interactive "*r\np")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1271 (if (interactive-p) (setq inc (* inc enriched-indent-increment)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1272 (save-excursion
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1273 (let ((from (progn (goto-char from)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1274 (if (<= (current-column) (enriched-left-margin))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1275 (beginning-of-line))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1276 (point)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1277 (to (progn (goto-char to)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1278 (point-marker)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1279 (inhibit-read-only t))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1280 (enriched-delete-indentation from to)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1281 (enriched-map-property-regions 'left-margin
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1282 (lambda (v b e)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1283 (put-text-property b e 'left-margin
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1284 (max 0 (+ inc (or v 0)))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1285 from to)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1286 (enriched-fill-region from to)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1287 (enriched-show-margin-codes from to))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1288
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1289 (defun enriched-change-right-margin (from to inc)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1290 "Adjust the right-margin property between FROM and TO by INCREMENT.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1291 If the given region includes the character at the left margin, it is extended
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1292 to include the indentation too."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1293 (interactive "r\np")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1294 (if (interactive-p) (setq inc (* inc enriched-indent-increment)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1295 (save-excursion
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1296 (let ((inhibit-read-only t))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1297 (enriched-map-property-regions 'right-margin
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1298 (lambda (v b e)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1299 (put-text-property b e 'right-margin
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1300 (max 0 (+ inc (or v 0)))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1301 from to)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1302 (fill-region (progn (goto-char from)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1303 (enriched-beginning-of-paragraph))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1304 (progn (goto-char to)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1305 (enriched-end-of-paragraph)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1306 (enriched-show-margin-codes from to))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1307
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1308 (defun enriched-set-left-margin (from to lm)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1309 "Set the left margin of the region to WIDTH.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1310 If the given region includes the character at the left margin, it is extended
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1311 to include the indentation too."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1312 (interactive "r\nNSet left margin to column: ")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1313 (if (interactive-p) (setq lm (prefix-numeric-value lm)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1314 (save-excursion
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1315 (let ((from (progn (goto-char from)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1316 (if (<= (current-column) (enriched-left-margin))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1317 (beginning-of-line))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1318 (point)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1319 (to (progn (goto-char to)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1320 (point-marker)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1321 (inhibit-read-only t))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1322 (enriched-delete-indentation from to)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1323 (put-text-property from to 'left-margin lm)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1324 (enriched-fill-region from to)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1325 (enriched-show-region-as-code from to 'margin))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1326
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1327 (defun enriched-set-right-margin (from to lm)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1328 "Set the right margin of the region to WIDTH.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1329 The right margin is the space left between fill-column and
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1330 `enriched-text-width'.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1331 If the given region includes the leftmost character on a line, it is extended
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1332 to include the indentation too."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1333 (interactive "r\nNSet left margin to column: ")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1334 (if (interactive-p) (setq lm (prefix-numeric-value lm)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1335 (save-excursion
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1336 (let ((from (progn (goto-char from)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1337 (if (<= (current-column) (enriched-left-margin))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1338 (end-of-line 0))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1339 (point)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1340 (to (progn (goto-char to)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1341 (point-marker)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1342 (inhibit-read-only t))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1343 (enriched-delete-indentation from to)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1344 (put-text-property from to 'right-margin lm)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1345 (enriched-fill-region from to)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1346 (enriched-show-region-as-code from to 'margin))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1347
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1348 (defun enriched-set-justification (b e val)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1349 "Set justification of region to new value."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1350 (save-restriction
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1351 (narrow-to-region (point-min) e)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1352 (enriched-delete-indentation b (point-max))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1353 (put-text-property b (point-max) 'justification val)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1354 (enriched-fill-region b (point-max))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1355
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1356 (defun enriched-justification ()
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1357 "How should we justify at point?
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1358 This returns the value of the text-property `justification' or if that is nil,
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1359 the value of `enriched-default-justification'. However, it returns nil
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1360 rather than `none' to mean \"don't justify\"."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1361 (let ((j (or (get-text-property
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1362 (if (and (eolp) (not (bolp))) (1- (point)) (point))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1363 'justification)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1364 enriched-default-justification)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1365 (if (eq 'none j)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1366 nil
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1367 j)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1368
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1369 (defun enriched-justify-line ()
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1370 "Indent and/or justify current line.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1371 Action depends on `justification' text property."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1372 (let ((just (enriched-justification)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1373 (if (or (null just) (eq 'left just))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1374 (enriched-indent-line)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1375 (save-excursion
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1376 (let ((left-margin (enriched-left-margin))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1377 (fill-column (enriched-fill-column))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1378 (length (enriched-line-length)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1379 (cond ((eq 'both just)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1380 (enriched-indent-line left-margin)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1381 (end-of-line)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1382 (if (not (or (get-text-property (point) 'hard-newline)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1383 (= (current-column) fill-column)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1384 (justify-current-line)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1385 ((eq 'center just)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1386 (let* ((space (- fill-column left-margin)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1387 (if (and (> length space) enriched-verbose)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1388 (enriched-warn "Line too long to center"))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1389 (enriched-indent-line
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1390 (+ left-margin (/ (- space length) 2)))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1391 ((eq 'right just)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1392 (end-of-line)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1393 (let* ((lmar (- fill-column length)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1394 (if (and (< lmar 0) enriched-verbose)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1395 (enriched-warn "Line to long to justify"))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1396 (enriched-indent-line lmar)))))))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1397
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1398 (defun enriched-squeeze-spaces (from to)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1399 "Remove unnecessary spaces between words.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1400 This should only be used in FlushBoth regions; otherwise spaces are the
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1401 property of the user and should not be tampered with."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1402 (save-excursion
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1403 (goto-char from)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1404 (let ((endmark (make-marker)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1405 (set-marker endmark to)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1406 (while (re-search-forward " *" endmark t)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1407 (delete-region
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1408 (+ (match-beginning 0)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1409 (if (save-excursion
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1410 (skip-chars-backward " ]})\"'")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1411 (memq (preceding-char) '(?. ?? ?!)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1412 2 1))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1413 (match-end 0))))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1414
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1415 (defun enriched-fill-region (from to)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1416 "Fill each paragraph in region.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1417 Whether or not filling or justification is done depends on the text properties
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1418 in effect at each location."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1419 (interactive "r")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1420 (save-excursion
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1421 (goto-char to)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1422 (let ((to (point-marker)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1423 (goto-char from)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1424 (while (< (point) to)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1425 (let ((begin (point)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1426 (enriched-end-of-paragraph)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1427 (enriched-fill-region-as-paragraph begin (point)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1428 (if (not (eobp))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1429 (forward-char 1))))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1430
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1431 (defun enriched-fill-region-as-paragraph (from to)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1432 "Make sure region is filled properly between margins.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1433 Whether or not filling or justification is done depends on the text properties
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1434 in effect at each location."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1435 (save-restriction
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1436 (narrow-to-region (point-min) to)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1437 (goto-char from)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1438 (let ((just (enriched-justification)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1439 (if (not just)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1440 (while (not (eobp))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1441 (enriched-indent-line)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1442 (forward-line 1))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1443 (enriched-delete-indentation from (point-max))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1444 (enriched-indent-line)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1445 ;; Following 3 lines taken from fill.el:
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1446 (while (re-search-forward "[.?!][])}\"']*$" nil t)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1447 (insert-and-inherit ?\ ))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1448 (subst-char-in-region from (point-max) ?\n ?\ )
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1449 ;; If we are full-justifying, we can commandeer all extra spaces.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1450 ;; Remove them before filling.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1451 (if (eq 'both just)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1452 (enriched-squeeze-spaces from (point-max)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1453 ;; Now call on auto-fill for each different segment of the par.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1454 (enriched-map-property-regions 'right-margin
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1455 (lambda (v b e)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1456 (goto-char (1- e))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1457 (enriched-auto-fill-function))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1458 from (point-max))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1459 (goto-char (point-max))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1460 (enriched-justify-line)))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1461
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1462 (defun enriched-auto-fill-function ()
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1463 "If past `enriched-fill-column', break current line.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1464 Line so ended will be filled and justified, as appropriate."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1465 (if (and (not enriched-mode) enriched-old-bindings)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1466 ;; Mode was turned off improperly.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1467 (progn (enriched-mode 0)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1468 (funcall auto-fill-function))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1469 ;; Necessary for FlushRight, etc:
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1470 (enriched-indent-line) ; standardize left margin
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1471 (let* ((fill-column (enriched-fill-column))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1472 (lmar (save-excursion (enriched-beginning-of-line) (point)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1473 (rmar (save-excursion (end-of-line) (point)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1474 (justify (enriched-justification))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1475 (give-up (not justify))) ; don't even start if in a NoFill region.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1476 ;; remove inside spaces if FlushBoth
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1477 (if (eq justify 'both)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1478 (enriched-squeeze-spaces lmar rmar))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1479 (while (and (not give-up) (> (current-column) fill-column))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1480 ;; Determine where to split the line.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1481 (setq lmar (save-excursion (enriched-beginning-of-line) (point)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1482 (let ((fill-point
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1483 (let ((opoint (point))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1484 bounce
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1485 (first t))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1486 (save-excursion
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1487 (enriched-move-to-fill-column)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1488 ;; Move back to a word boundary.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1489 (while (or first
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1490 ;; If this is after period and a single space,
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1491 ;; move back once more--we don't want to break
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1492 ;; the line there and make it look like a
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1493 ;; sentence end.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1494 (and (not (bobp))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1495 (not bounce)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1496 sentence-end-double-space
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1497 (save-excursion (forward-char -1)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1498 (and (looking-at "\\. ")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1499 (not (looking-at "\\. " ))))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1500 (setq first nil)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1501 (skip-chars-backward "^ \t\n")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1502 ;; If we are not allowed to break here, move back to
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1503 ;; somewhere that may be legal. If no legal spots, this
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1504 ;; will land us at bol.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1505 ;;(if (not (enriched-canbreak))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1506 ;; (goto-char (previous-single-property-change
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1507 ;; (point) 'justification nil lmar)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1508 ;; If we find nowhere on the line to break it,
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1509 ;; break after one word. Set bounce to t
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1510 ;; so we will not keep going in this while loop.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1511 (if (<= (point) lmar)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1512 (progn
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1513 (re-search-forward "[ \t]" opoint t)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1514 ;;(while (and (re-search-forward "[ \t]" opoint t)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1515 ;; (not (enriched-canbreak))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1516 (setq bounce t)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1517 (skip-chars-backward " \t"))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1518 ;; Let fill-point be set to the place where we end up.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1519 (point)))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1520 ;; If that place is not the beginning of the line,
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1521 ;; break the line there.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1522 (if ; and (enriched-canbreak)....
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1523 (save-excursion
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1524 (goto-char fill-point)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1525 (not (bolp)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1526 (let ((prev-column (current-column)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1527 ;; If point is at the fill-point, do not `save-excursion'.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1528 ;; Otherwise, if a comment prefix or fill-prefix is inserted,
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1529 ;; point will end up before it rather than after it.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1530 (if (save-excursion
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1531 (skip-chars-backward " \t")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1532 (= (point) fill-point))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1533 (progn
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1534 (insert-and-inherit "\n")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1535 (delete-region (point)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1536 (progn (skip-chars-forward " ") (point)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1537 (enriched-indent-line))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1538 (save-excursion
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1539 (goto-char fill-point)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1540 (insert-and-inherit "\n")
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1541 (delete-region (point)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1542 (progn (skip-chars-forward " ") (point)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1543 (enriched-indent-line)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1544 ;; Now do proper sort of justification of the previous line
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1545 (save-excursion
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1546 (end-of-line 0)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1547 (enriched-justify-line))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1548 ;; If making the new line didn't reduce the hpos of
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1549 ;; the end of the line, then give up now;
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1550 ;; trying again will not help.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1551 (if (>= (current-column) prev-column)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1552 (setq give-up t)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1553 ;; No place to break => stop trying.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1554 (setq give-up t))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1555 ;; Check last line too ?
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1556 )))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1557
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1558 (defun enriched-aggressive-auto-fill-function ()
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1559 "Too slow."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1560 (save-excursion
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1561 (enriched-fill-region (progn (beginning-of-line) (point))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1562 (enriched-end-of-paragraph))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1563
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1564 ;;;
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1565 ;;; Writing Files
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1566 ;;;
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1567
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1568 (defsubst enriched-open-annotation (name)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1569 (insert-and-inherit (enriched-make-annotation name t)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1570
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1571 (defsubst enriched-close-annotation (name)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1572 (insert-and-inherit (enriched-make-annotation name nil)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1573
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1574 (defun enriched-annotate-function (start end)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1575 "For use on write-region-annotations-functions.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1576 Makes a new buffer containing the region in text/enriched format."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1577 (if enriched-mode
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1578 (let (;(enriched-file (file-name-nondirectory buffer-file-name))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1579 (copy-buf (generate-new-buffer "*Enriched Temp*")))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1580 (copy-to-buffer copy-buf start end)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1581 (set-buffer copy-buf)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1582 (enriched-insert-annotations write-region-annotations-so-far start)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1583 (setq write-region-annotations-so-far nil)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1584 (enriched-encode-region)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1585 nil)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1586
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1587 (defun enriched-encode-region (&optional from to)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1588 "Transform buffer into text/enriched format."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1589 (if enriched-verbose (message "Enriched: encoding document..."))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1590 (setq enriched-ignored-list enriched-ignored-ok)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1591 (save-excursion
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1592 (save-restriction
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1593 (if to (narrow-to-region (point-min) to))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1594 (enriched-delete-indentation from to)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1595 (let ((enriched-open-ans nil)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1596 (inhibit-read-only t))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1597 (goto-char (or from (point-min)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1598 (insert (if (stringp enriched-initial-annotation)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1599 enriched-initial-annotation
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1600 (funcall enriched-initial-annotation)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1601 (while
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1602 (let* ((ans (enriched-loc-annotations (point)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1603 (neg-ans (enriched-reorder (car ans) enriched-open-ans))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1604 (pos-ans (cdr ans)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1605 ;; First do the negative (closing) annotations
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1606 (while neg-ans
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1607 (if (not (member (car neg-ans) enriched-open-ans))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1608 (enriched-warn "BUG DETECTED: Closing %s with open list=%s"
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1609 (enriched-pop neg-ans) enriched-open-ans)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1610 (while (not (equal (car neg-ans) (car enriched-open-ans)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1611 ;; To close anno. N, need to first close ans 1 to N-1,
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1612 ;; remembering to re-open them later.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1613 (enriched-push (car enriched-open-ans) pos-ans)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1614 (enriched-close-annotation (enriched-pop enriched-open-ans)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1615 ;; Now we can safely close this anno & remove from open list
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1616 (enriched-close-annotation (enriched-pop neg-ans))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1617 (enriched-pop enriched-open-ans)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1618 ;; Now deal with positive (opening) annotations
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1619 (while pos-ans
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1620 (enriched-push (car pos-ans) enriched-open-ans)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1621 (enriched-open-annotation (enriched-pop pos-ans)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1622 (enriched-move-to-next-property-change)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1623
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1624 ;; Close up shop...
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1625 (goto-char (point-max))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1626 (while enriched-open-ans
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1627 (enriched-close-annotation (enriched-pop enriched-open-ans)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1628 (if (not (= ?\n (char-after (1- (point)))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1629 (insert ?\n)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1630 (if (and enriched-verbose (> (length enriched-ignored-list)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1631 (length enriched-ignored-ok)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1632 (let ((not-ok nil))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1633 (while (not (eq enriched-ignored-list enriched-ignored-ok))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1634 (setq not-ok (cons (car enriched-ignored-list) not-ok)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1635 enriched-ignored-list (cdr enriched-ignored-list)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1636 (enriched-warn "Not recorded: %s" not-ok)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1637 (sit-for 1))))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1638
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1639 (defun enriched-move-to-next-property-change ()
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1640 "Advance point to next prop change, dealing with special items on the way.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1641 Returns the location, or nil."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1642 (let ((prop-change (next-property-change (point))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1643 (while (and (< (point) (or prop-change (point-max)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1644 (search-forward enriched-encode-interesting-regexp
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1645 prop-change 1))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1646 (goto-char (match-beginning 0))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1647 (let ((specials enriched-encode-special-alist))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1648 (while specials
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1649 (if (enriched-looking-at-with-props (car (car specials)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1650 (progn (goto-char (match-end 0))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1651 (funcall (cdr (car specials)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1652 (setq specials nil))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1653 (enriched-pop specials)))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1654 prop-change))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1655
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1656 (defun enriched-loc-annotations (loc)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1657 "Return annotation(s) needed at LOCATION.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1658 This includes any properties that change between LOC-1 and LOC.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1659 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
1660 non-nil properties there, plus the enriched-version annotation.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1661 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
1662 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
1663 annotations to open."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1664 (let* ((prev-loc (1- loc))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1665 (begin (< prev-loc (point-min)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1666 (before-plist (if begin nil (text-properties-at prev-loc)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1667 (after-plist (text-properties-at loc))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1668 negatives positives prop props)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1669 ;; make list of all property names involved
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1670 (while before-plist
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1671 (enriched-push (car before-plist) props)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1672 (setq before-plist (cdr (cdr before-plist))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1673 (while after-plist
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1674 (enriched-push (car after-plist) props)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1675 (setq after-plist (cdr (cdr after-plist))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1676 (setq props (enriched-make-list-uniq props))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1677
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1678 (while props
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1679 (setq prop (enriched-pop props))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1680 (if (memq prop enriched-ignored-list)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1681 nil ; If its been ignored before, ignore it now.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1682 (let ((before (if begin nil (get-text-property prev-loc prop)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1683 (after (get-text-property loc prop)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1684 (if (equal before after)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1685 nil ; no change; ignore
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1686 (let ((result (enriched-annotate-change prop before after)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1687 (setq negatives (nconc negatives (car result))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1688 positives (nconc positives (cdr result))))))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1689 (cons negatives positives)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1690
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1691 (defun enriched-annotate-change (prop old new)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1692 "Return annotations for PROPERTY changing from OLD to NEW.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1693 These are searched for in `enriched-annotation-list'.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1694 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
1695 function is called.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1696 Annotations are returned as a list, as in `enriched-loc-annotations'."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1697 ;; If property is numeric, nil means 0
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1698 (if (or (consp old) (consp new))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1699 (let* ((old (if (listp old) old (list old)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1700 (new (if (listp new) new (list new)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1701 (tail (enriched-common-tail old new))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1702 close open)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1703 (while old
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1704 (setq close
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1705 (append (car (enriched-annotate-change prop (car old) nil))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1706 close)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1707 old (cdr old)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1708 (while new
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1709 (setq open
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1710 (append (cdr (enriched-annotate-change prop nil (car new)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1711 open)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1712 new (cdr new)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1713 (enriched-make-relatively-unique close open))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1714 (cond ((and (numberp old) (null new))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1715 (setq new 0))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1716 ((and (numberp new) (null old))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1717 (setq old 0)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1718 (let ((prop-alist (cdr (assoc prop enriched-annotation-alist)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1719 default)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1720 (cond ((null prop-alist) ; not found
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1721 (if (not (memq prop enriched-ignored-list))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1722 (enriched-push prop enriched-ignored-list))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1723 nil)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1724
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1725 ;; Numerical values: use the difference
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1726 ((and (numberp old) (numberp new))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1727 (let* ((entry (progn
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1728 (while (and (car (car prop-alist))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1729 (not (numberp (car (car prop-alist)))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1730 (enriched-pop prop-alist))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1731 (car prop-alist)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1732 (increment (car (car prop-alist)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1733 (n (ceiling (/ (float (- new old)) (float increment))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1734 (anno (car (cdr (car prop-alist)))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1735 (if (> n 0)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1736 (cons nil (make-list n anno))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1737 (cons (make-list (- n) anno) nil))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1738
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1739 ;; Standard annotation
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1740 (t (let ((close (and old (cdr (assoc old prop-alist))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1741 (open (and new (cdr (assoc new prop-alist)))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1742 (if (or close open)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1743 (enriched-make-relatively-unique close open)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1744 (let ((default (assoc nil prop-alist)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1745 (if default
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1746 (funcall (car (cdr default)) old new))))))))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1747
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1748 ;;;
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1749 ;;; Reading files
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1750 ;;;
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1751
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1752 (defun enriched-decode-region (&optional from to)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1753 "Decode text/enriched buffer into text with properties.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1754 This is the primary entry point for decoding."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1755 (if enriched-verbose (message "Enriched: decoding document..."))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1756 (save-excursion
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1757 (save-restriction
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1758 (if to (narrow-to-region (point-min) to))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1759 (goto-char (or from (point-min)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1760 (let ((file-width (enriched-get-file-width))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1761 (inhibit-read-only t)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1762 enriched-open-ans todo loc unknown-ans)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1763
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1764 (while (enriched-move-to-next-annotation)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1765 (let* ((loc (match-beginning 0))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1766 (anno (buffer-substring (match-beginning 0) (match-end 0)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1767 (name (enriched-annotation-name anno))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1768 (positive (enriched-annotation-positive-p anno)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1769
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1770 (if enriched-downcase-annotations
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1771 (setq name (downcase name)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1772
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1773 (delete-region (match-beginning 0) (match-end 0))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1774 (if positive
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1775 (enriched-push (list name loc) enriched-open-ans)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1776 ;; negative...
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1777 (let* ((top (car enriched-open-ans))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1778 (top-name (car top))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1779 (start (car (cdr top)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1780 (params (cdr (cdr top)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1781 (aalist enriched-annotation-alist)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1782 (matched nil))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1783 (if (not (equal name top-name))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1784 (error (format "Improper nesting in file: %s != %s"
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1785 name top)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1786 (while aalist
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1787 (let ((prop (car (car aalist)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1788 (alist (cdr (car aalist))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1789 (while alist
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1790 (let ((value (car (car alist)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1791 (ans (cdr (car alist))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1792 (if (member name ans)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1793 ;; Check if multiple annotations are satisfied
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1794 (if (member 'nil (mapcar
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1795 (lambda (r)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1796 (assoc r enriched-open-ans))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1797 ans))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1798 nil ; multiple ans not satisfied
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1799 ;; Yes, we got it:
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1800 (setq alist nil aalist nil matched t
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1801 enriched-open-ans (cdr enriched-open-ans))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1802 (cond
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1803 ((eq prop 'PARAMETER)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1804 ;; This is a parameter of the top open ann.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1805 (let ((nxt (enriched-pop enriched-open-ans)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1806 (if nxt
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1807 (enriched-push
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1808 (append
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1809 nxt
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1810 (list (buffer-substring start loc)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1811 enriched-open-ans))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1812 (delete-region start loc)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1813 ((eq prop 'FUNCTION)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1814 (let ((rtn (apply value start loc params)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1815 (if rtn (enriched-push rtn todo))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1816 (t
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1817 ;; Normal property/value pair
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1818 (enriched-push (list start loc prop value)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1819 todo))))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1820 (enriched-pop alist)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1821 (enriched-pop aalist))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1822 (if matched
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1823 nil
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1824 ;; Didn't find it
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1825 (enriched-pop enriched-open-ans)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1826 (enriched-push (list start loc 'unknown name) todo)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1827 (enriched-push name unknown-ans))))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1828
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1829 ;; Now actually add the properties
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1830
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1831 (while todo
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1832 (let* ((item (enriched-pop todo))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1833 (from (elt item 0))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1834 (to (elt item 1))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1835 (prop (elt item 2))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1836 (val (elt item 3)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1837
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1838 ; (if (and (eq prop 'IGNORE) ; 'IGNORE' pseudo-property was special
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1839 ; (eq val t))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1840 ; (delete-region from to))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1841 (put-text-property
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1842 from to prop
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1843 (cond ((numberp val)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1844 (+ val (or (get-text-property from prop) 0)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1845 ((memq prop enriched-list-valued-properties)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1846 (let ((prev (get-text-property from prop)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1847 (cons val (if (listp prev) prev (list prev)))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1848 (t val)))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1849
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1850 (if (or (and file-width ; possible reasons not to fill:
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1851 (= file-width (enriched-text-width))) ; correct wd.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1852 (null enriched-fill-after-visiting) ; never fill
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1853 (and (eq 'ask enriched-fill-after-visiting) ; asked & declined
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1854 (not (y-or-n-p "Reformat for current display width? "))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1855 ;; Minimally, we have to insert indentation and justification.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1856 (enriched-insert-indentation)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1857 (sit-for 1)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1858 (if enriched-verbose (message "Filling paragraphs..."))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1859 (enriched-fill-region (point-min) (point-max))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1860 (if enriched-verbose (message nil)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1861
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1862 (if enriched-verbose
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1863 (progn
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1864 (message nil)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1865 (if unknown-ans
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1866 (enriched-warn "Unknown annotations: %s" unknown-ans))))))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1867
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1868 (defun enriched-get-file-width ()
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1869 "Look for file width information on this line."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1870 (save-excursion
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1871 (if (search-forward "width:" (save-excursion (end-of-line) (point)) t)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1872 (read (current-buffer)))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1873
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1874 (defun enriched-move-to-next-annotation ()
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1875 "Advances point to next annotation, dealing with special items on the way.
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1876 Returns t if one was found, otherwise nil."
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1877 (while (and (re-search-forward enriched-decode-interesting-regexp nil t)
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1878 (goto-char (match-beginning 0))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1879 (not (looking-at enriched-annotation-regexp)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1880 (let ((regexps enriched-decode-special-alist))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1881 (while (and regexps
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1882 (not (looking-at (car (car regexps)))))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1883 (enriched-pop regexps))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1884 (if regexps
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1885 (funcall (cdr (car regexps)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1886 (forward-char 1)))) ; nothing found
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1887 (not (eobp)))
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1888
03324d1a8d7f Initial revision
Boris Goldowsky <boris@gnu.org>
parents:
diff changeset
1889 ;;; enriched.el ends here