| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
(provide 'enriched) |
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
(defgroup enriched nil |
|---|
| 51 |
"Read and save files in text/enriched format." |
|---|
| 52 |
:group 'wp) |
|---|
| 53 |
|
|---|
| 54 |
(defcustom enriched-verbose t |
|---|
| 55 |
"*If non-nil, give status messages when reading and writing files." |
|---|
| 56 |
:type 'boolean |
|---|
| 57 |
:group 'enriched) |
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
(defface fixed |
|---|
| 67 |
'((t (:weight bold))) |
|---|
| 68 |
"Face used for text that must be shown in fixed width. |
|---|
| 69 |
Currently, Emacs can only display fixed-width fonts, but this may change. |
|---|
| 70 |
This face is used for text specifically marked as fixed-width, for example |
|---|
| 71 |
in text/enriched files." |
|---|
| 72 |
:group 'enriched) |
|---|
| 73 |
|
|---|
| 74 |
(defface excerpt |
|---|
| 75 |
'((t (:slant italic))) |
|---|
| 76 |
"Face used for text that is an excerpt from another document. |
|---|
| 77 |
This is used in Enriched mode for text explicitly marked as an excerpt." |
|---|
| 78 |
:group 'enriched) |
|---|
| 79 |
|
|---|
| 80 |
(defconst enriched-display-table (or (copy-sequence standard-display-table) |
|---|
| 81 |
(make-display-table))) |
|---|
| 82 |
(aset enriched-display-table ?\f (make-vector (1- (frame-width)) ?-)) |
|---|
| 83 |
|
|---|
| 84 |
(defconst enriched-par-props '(left-margin right-margin justification) |
|---|
| 85 |
"Text-properties that usually apply to whole paragraphs. |
|---|
| 86 |
These are set front-sticky everywhere except at hard newlines.") |
|---|
| 87 |
|
|---|
| 88 |
|
|---|
| 89 |
|
|---|
| 90 |
|
|---|
| 91 |
|
|---|
| 92 |
(defconst enriched-initial-annotation |
|---|
| 93 |
(lambda () |
|---|
| 94 |
(format "Content-Type: text/enriched\nText-Width: %d\n\n" |
|---|
| 95 |
fill-column)) |
|---|
| 96 |
"What to insert at the start of a text/enriched file. |
|---|
| 97 |
If this is a string, it is inserted. If it is a list, it should be a lambda |
|---|
| 98 |
expression, which is evaluated to get the string to insert.") |
|---|
| 99 |
|
|---|
| 100 |
(defconst enriched-annotation-format "<%s%s>" |
|---|
| 101 |
"General format of enriched-text annotations.") |
|---|
| 102 |
|
|---|
| 103 |
(defconst enriched-annotation-regexp "<\\(/\\)?\\([-A-Za-z0-9]+\\)>" |
|---|
| 104 |
"Regular expression matching enriched-text annotations.") |
|---|
| 105 |
|
|---|
| 106 |
(defvar enriched-translations |
|---|
| 107 |
'((face (bold-italic "bold" "italic") |
|---|
| 108 |
(bold "bold") |
|---|
| 109 |
(italic "italic") |
|---|
| 110 |
(underline "underline") |
|---|
| 111 |
(fixed "fixed") |
|---|
| 112 |
(excerpt "excerpt") |
|---|
| 113 |
(default ) |
|---|
| 114 |
(nil enriched-encode-other-face)) |
|---|
| 115 |
(left-margin (4 "indent")) |
|---|
| 116 |
(right-margin (4 "indentright")) |
|---|
| 117 |
(justification (none "nofill") |
|---|
| 118 |
(right "flushright") |
|---|
| 119 |
(left "flushleft") |
|---|
| 120 |
(full "flushboth") |
|---|
| 121 |
(center "center")) |
|---|
| 122 |
(PARAMETER (t "param")) |
|---|
| 123 |
|
|---|
| 124 |
(FUNCTION (enriched-decode-foreground "x-color") |
|---|
| 125 |
(enriched-decode-background "x-bg-color") |
|---|
| 126 |
(enriched-decode-display-prop "x-display")) |
|---|
| 127 |
(read-only (t "x-read-only")) |
|---|
| 128 |
(display (nil enriched-handle-display-prop)) |
|---|
| 129 |
(unknown (nil format-annotate-value)) |
|---|
| 130 |
|
|---|
| 131 |
|
|---|
| 132 |
) |
|---|
| 133 |
"List of definitions of text/enriched annotations. |
|---|
| 134 |
See `format-annotate-region' and `format-deannotate-region' for the definition |
|---|
| 135 |
of this structure.") |
|---|
| 136 |
|
|---|
| 137 |
(defconst enriched-ignore |
|---|
| 138 |
'(front-sticky rear-nonsticky hard) |
|---|
| 139 |
"Properties that are OK to ignore when saving text/enriched files. |
|---|
| 140 |
Any property that is neither on this list nor dealt with by |
|---|
| 141 |
`enriched-translations' will generate a warning.") |
|---|
| 142 |
|
|---|
| 143 |
|
|---|
| 144 |
|
|---|
| 145 |
(defcustom enriched-mode-hook nil |
|---|
| 146 |
"Hook run after entering/leaving Enriched mode. |
|---|
| 147 |
If you set variables in this hook, you should arrange for them to be restored |
|---|
| 148 |
to their old values if you leave Enriched mode. One way to do this is to add |
|---|
| 149 |
them and their old values to `enriched-old-bindings'." |
|---|
| 150 |
:type 'hook |
|---|
| 151 |
:group 'enriched) |
|---|
| 152 |
|
|---|
| 153 |
(defvar enriched-old-bindings nil |
|---|
| 154 |
"Store old variable values that we change when entering mode. |
|---|
| 155 |
The value is a list of \(VAR VALUE VAR VALUE...).") |
|---|
| 156 |
(make-variable-buffer-local 'enriched-old-bindings) |
|---|
| 157 |
|
|---|
| 158 |
|
|---|
| 159 |
|
|---|
| 160 |
|
|---|
| 161 |
|
|---|
| 162 |
(defvar enriched-default-text-properties-local-flag t) |
|---|
| 163 |
|
|---|
| 164 |
|
|---|
| 165 |
|
|---|
| 166 |
|
|---|
| 167 |
(defvar enriched-rerun-flag nil) |
|---|
| 168 |
|
|---|
| 169 |
|
|---|
| 170 |
|
|---|
| 171 |
|
|---|
| 172 |
|
|---|
| 173 |
(put 'enriched-mode 'permanent-local t) |
|---|
| 174 |
|
|---|
| 175 |
(define-minor-mode enriched-mode |
|---|
| 176 |
"Minor mode for editing text/enriched files. |
|---|
| 177 |
These are files with embedded formatting information in the MIME standard |
|---|
| 178 |
text/enriched format. |
|---|
| 179 |
Turning the mode on or off runs `enriched-mode-hook'. |
|---|
| 180 |
|
|---|
| 181 |
More information about Enriched mode is available in the file |
|---|
| 182 |
etc/enriched.doc in the Emacs distribution directory. |
|---|
| 183 |
|
|---|
| 184 |
Commands: |
|---|
| 185 |
|
|---|
| 186 |
\\{enriched-mode-map}" |
|---|
| 187 |
:group 'enriched :lighter " Enriched" |
|---|
| 188 |
(cond ((null enriched-mode) |
|---|
| 189 |
|
|---|
| 190 |
(setq buffer-file-format (delq 'text/enriched buffer-file-format)) |
|---|
| 191 |
|
|---|
| 192 |
(while enriched-old-bindings |
|---|
| 193 |
(set (pop enriched-old-bindings) (pop enriched-old-bindings))) |
|---|
| 194 |
(unless enriched-default-text-properties-local-flag |
|---|
| 195 |
(kill-local-variable 'default-text-properties)) |
|---|
| 196 |
(kill-local-variable 'enriched-default-text-properties-local-flag) |
|---|
| 197 |
(unless use-hard-newlines (use-hard-newlines 0))) |
|---|
| 198 |
|
|---|
| 199 |
((and (memq 'text/enriched buffer-file-format) |
|---|
| 200 |
(not enriched-rerun-flag)) |
|---|
| 201 |
|
|---|
| 202 |
nil) |
|---|
| 203 |
|
|---|
| 204 |
(t |
|---|
| 205 |
(add-to-list 'buffer-file-format 'text/enriched) |
|---|
| 206 |
|
|---|
| 207 |
|
|---|
| 208 |
(setq enriched-old-bindings |
|---|
| 209 |
(list 'buffer-display-table buffer-display-table |
|---|
| 210 |
'default-text-properties default-text-properties |
|---|
| 211 |
'use-hard-newlines use-hard-newlines)) |
|---|
| 212 |
(make-local-variable 'enriched-default-text-properties-local-flag) |
|---|
| 213 |
(setq enriched-default-text-properties-local-flag |
|---|
| 214 |
(local-variable-p 'default-text-properties)) |
|---|
| 215 |
(make-local-variable 'default-text-properties) |
|---|
| 216 |
(setq buffer-display-table enriched-display-table) |
|---|
| 217 |
(use-hard-newlines 1 (if enriched-rerun-flag 'never nil)) |
|---|
| 218 |
(let ((sticky (plist-get default-text-properties 'front-sticky)) |
|---|
| 219 |
(p enriched-par-props)) |
|---|
| 220 |
(dolist (x p) |
|---|
| 221 |
(add-to-list 'sticky x)) |
|---|
| 222 |
(if sticky |
|---|
| 223 |
(setq default-text-properties |
|---|
| 224 |
(plist-put default-text-properties |
|---|
| 225 |
'front-sticky sticky))))))) |
|---|
| 226 |
|
|---|
| 227 |
(defun enriched-before-change-major-mode () |
|---|
| 228 |
(when enriched-mode |
|---|
| 229 |
(while enriched-old-bindings |
|---|
| 230 |
(set (pop enriched-old-bindings) (pop enriched-old-bindings))))) |
|---|
| 231 |
|
|---|
| 232 |
(add-hook 'change-major-mode-hook 'enriched-before-change-major-mode) |
|---|
| 233 |
|
|---|
| 234 |
(defun enriched-after-change-major-mode () |
|---|
| 235 |
(when enriched-mode |
|---|
| 236 |
(let ((enriched-rerun-flag t)) |
|---|
| 237 |
(enriched-mode 1)))) |
|---|
| 238 |
|
|---|
| 239 |
(add-hook 'after-change-major-mode-hook 'enriched-after-change-major-mode) |
|---|
| 240 |
|
|---|
| 241 |
|
|---|
| 242 |
|
|---|
| 243 |
|
|---|
| 244 |
|
|---|
| 245 |
(defvar enriched-mode-map nil |
|---|
| 246 |
"Keymap for Enriched mode.") |
|---|
| 247 |
|
|---|
| 248 |
(if (null enriched-mode-map) |
|---|
| 249 |
(fset 'enriched-mode-map (setq enriched-mode-map (make-sparse-keymap)))) |
|---|
| 250 |
|
|---|
| 251 |
(if (not (assq 'enriched-mode minor-mode-map-alist)) |
|---|
| 252 |
(setq minor-mode-map-alist |
|---|
| 253 |
(cons (cons 'enriched-mode enriched-mode-map) |
|---|
| 254 |
minor-mode-map-alist))) |
|---|
| 255 |
|
|---|
| 256 |
(define-key enriched-mode-map "\C-a" 'beginning-of-line-text) |
|---|
| 257 |
(define-key enriched-mode-map "\C-m" 'reindent-then-newline-and-indent) |
|---|
| 258 |
(define-key enriched-mode-map "\C-j" 'reindent-then-newline-and-indent) |
|---|
| 259 |
(define-key enriched-mode-map "\M-j" 'facemenu-justification-menu) |
|---|
| 260 |
(define-key enriched-mode-map "\M-S" 'set-justification-center) |
|---|
| 261 |
(define-key enriched-mode-map "\C-x\t" 'increase-left-margin) |
|---|
| 262 |
(define-key enriched-mode-map "\C-c[" 'set-left-margin) |
|---|
| 263 |
(define-key enriched-mode-map "\C-c]" 'set-right-margin) |
|---|
| 264 |
|
|---|
| 265 |
|
|---|
| 266 |
|
|---|
| 267 |
|
|---|
| 268 |
|
|---|
| 269 |
(defun enriched-map-property-regions (prop func &optional from to) |
|---|
| 270 |
"Apply a function to regions of the buffer based on a text property. |
|---|
| 271 |
For each contiguous region of the buffer for which the value of PROPERTY is |
|---|
| 272 |
eq, the FUNCTION will be called. Optional arguments FROM and TO specify the |
|---|
| 273 |
region over which to scan. |
|---|
| 274 |
|
|---|
| 275 |
The specified function receives three arguments: the VALUE of the property in |
|---|
| 276 |
the region, and the START and END of each region." |
|---|
| 277 |
(save-excursion |
|---|
| 278 |
(save-restriction |
|---|
| 279 |
(if to (narrow-to-region (point-min) to)) |
|---|
| 280 |
(goto-char (or from (point-min))) |
|---|
| 281 |
(let ((begin (point)) |
|---|
| 282 |
end |
|---|
| 283 |
(marker (make-marker)) |
|---|
| 284 |
(val (get-text-property (point) prop))) |
|---|
| 285 |
(while (setq end (text-property-not-all begin (point-max) prop val)) |
|---|
| 286 |
(move-marker marker end) |
|---|
| 287 |
(funcall func val begin (marker-position marker)) |
|---|
| 288 |
(setq begin (marker-position marker) |
|---|
| 289 |
val (get-text-property marker prop))) |
|---|
| 290 |
(if (< begin (point-max)) |
|---|
| 291 |
(funcall func val begin (point-max))))))) |
|---|
| 292 |
|
|---|
| 293 |
(put 'enriched-map-property-regions 'lisp-indent-hook 1) |
|---|
| 294 |
|
|---|
| 295 |
(defun enriched-insert-indentation (&optional from to) |
|---|
| 296 |
"Indent and justify each line in the region." |
|---|
| 297 |
(save-excursion |
|---|
| 298 |
(save-restriction |
|---|
| 299 |
(if to (narrow-to-region (point-min) to)) |
|---|
| 300 |
(goto-char (or from (point-min))) |
|---|
| 301 |
(if (not (bolp)) (forward-line 1)) |
|---|
| 302 |
(while (not (eobp)) |
|---|
| 303 |
(if (eolp) |
|---|
| 304 |
nil |
|---|
| 305 |
(indent-to (current-left-margin)) |
|---|
| 306 |
(justify-current-line t nil t)) |
|---|
| 307 |
(forward-line 1))))) |
|---|
| 308 |
|
|---|
| 309 |
|
|---|
| 310 |
|
|---|
| 311 |
|
|---|
| 312 |
|
|---|
| 313 |
|
|---|
| 314 |
(defun enriched-encode (from to orig-buf) |
|---|
| 315 |
(if enriched-verbose (message "Enriched: encoding document...")) |
|---|
| 316 |
(let ((inhibit-read-only t)) |
|---|
| 317 |
(save-restriction |
|---|
| 318 |
(narrow-to-region from to) |
|---|
| 319 |
(delete-to-left-margin) |
|---|
| 320 |
(unjustify-region) |
|---|
| 321 |
(goto-char from) |
|---|
| 322 |
(format-replace-strings '(("<" . "<<"))) |
|---|
| 323 |
(format-insert-annotations |
|---|
| 324 |
(format-annotate-region from (point-max) enriched-translations |
|---|
| 325 |
'enriched-make-annotation enriched-ignore)) |
|---|
| 326 |
(goto-char from) |
|---|
| 327 |
(insert (if (stringp enriched-initial-annotation) |
|---|
| 328 |
enriched-initial-annotation |
|---|
| 329 |
(save-excursion |
|---|
| 330 |
|
|---|
| 331 |
|
|---|
| 332 |
|
|---|
| 333 |
|
|---|
| 334 |
(if orig-buf (set-buffer orig-buf)) |
|---|
| 335 |
(funcall enriched-initial-annotation)))) |
|---|
| 336 |
(enriched-map-property-regions 'hard |
|---|
| 337 |
(lambda (v b e) |
|---|
| 338 |
(if (and v (= ?\n (char-after b))) |
|---|
| 339 |
(progn (goto-char b) (insert "\n")))) |
|---|
| 340 |
(point) nil) |
|---|
| 341 |
(if enriched-verbose (message nil)) |
|---|
| 342 |
|
|---|
| 343 |
(point-max)))) |
|---|
| 344 |
|
|---|
| 345 |
(defun enriched-make-annotation (internal-ann positive) |
|---|
| 346 |
"Format an annotation INTERNAL-ANN. |
|---|
| 347 |
INTERNAL-ANN may be a string, for a flag, or a list of the form (PARAM VALUE). |
|---|
| 348 |
If POSITIVE is non-nil, this is the opening annotation; |
|---|
| 349 |
if nil, the matching close." |
|---|
| 350 |
(cond ((stringp internal-ann) |
|---|
| 351 |
(format enriched-annotation-format (if positive "" "/") internal-ann)) |
|---|
| 352 |
|
|---|
| 353 |
(positive |
|---|
| 354 |
(let ((item (car internal-ann)) |
|---|
| 355 |
(params (cdr internal-ann))) |
|---|
| 356 |
(concat (format enriched-annotation-format "" item) |
|---|
| 357 |
(mapconcat (lambda (i) (concat "<param>" i "</param>")) |
|---|
| 358 |
params "")))) |
|---|
| 359 |
(t (format enriched-annotation-format "/" (car internal-ann))))) |
|---|
| 360 |
|
|---|
| 361 |
(defun enriched-encode-other-face (old new) |
|---|
| 362 |
"Generate annotations for random face change. |
|---|
| 363 |
One annotation each for foreground color, background color, italic, etc." |
|---|
| 364 |
(cons (and old (enriched-face-ans old)) |
|---|
| 365 |
(and new (enriched-face-ans new)))) |
|---|
| 366 |
|
|---|
| 367 |
(defun enriched-face-ans (face) |
|---|
| 368 |
"Return annotations specifying FACE. |
|---|
| 369 |
FACE may be a list of faces instead of a single face; |
|---|
| 370 |
it can also be anything allowed as an element of a list |
|---|
| 371 |
which can be the value of the `face' text property." |
|---|
| 372 |
(cond ((and (consp face) (eq (car face) 'foreground-color)) |
|---|
| 373 |
(list (list "x-color" (cdr face)))) |
|---|
| 374 |
((and (consp face) (eq (car face) 'background-color)) |
|---|
| 375 |
(list (list "x-bg-color" (cdr face)))) |
|---|
| 376 |
((and (listp face) (eq (car face) :foreground)) |
|---|
| 377 |
(list (list "x-color" (cadr face)))) |
|---|
| 378 |
((and (listp face) (eq (car face) :background)) |
|---|
| 379 |
(list (list "x-bg-color" (cadr face)))) |
|---|
| 380 |
((listp face) |
|---|
| 381 |
(apply 'append (mapcar 'enriched-face-ans face))) |
|---|
| 382 |
((let* ((fg (face-attribute face :foreground)) |
|---|
| 383 |
(bg (face-attribute face :background)) |
|---|
| 384 |
(props (face-font face t)) |
|---|
| 385 |
(ans (cdr (format-annotate-single-property-change |
|---|
| 386 |
'face nil props enriched-translations)))) |
|---|
| 387 |
(unless (eq fg 'unspecified) |
|---|
| 388 |
(setq ans (cons (list "x-color" fg) ans))) |
|---|
| 389 |
(unless (eq bg 'unspecified) |
|---|
| 390 |
(setq ans (cons (list "x-bg-color" bg) ans))) |
|---|
| 391 |
ans)))) |
|---|
| 392 |
|
|---|
| 393 |
|
|---|
| 394 |
|
|---|
| 395 |
|
|---|
| 396 |
|
|---|
| 397 |
|
|---|
| 398 |
(defun enriched-decode (from to) |
|---|
| 399 |
(if enriched-verbose (message "Enriched: decoding document...")) |
|---|
| 400 |
(use-hard-newlines 1 'never) |
|---|
| 401 |
(save-excursion |
|---|
| 402 |
(save-restriction |
|---|
| 403 |
(narrow-to-region from to) |
|---|
| 404 |
(goto-char from) |
|---|
| 405 |
|
|---|
| 406 |
|
|---|
| 407 |
(let ((file-width (enriched-get-file-width))) |
|---|
| 408 |
(enriched-remove-header) |
|---|
| 409 |
|
|---|
| 410 |
|
|---|
| 411 |
(while (search-forward-regexp "\n\n+" nil t) |
|---|
| 412 |
(if (current-justification) |
|---|
| 413 |
(delete-char -1)) |
|---|
| 414 |
(set-hard-newline-properties (match-beginning 0) (point))) |
|---|
| 415 |
|
|---|
| 416 |
|
|---|
| 417 |
(format-deannotate-region from (point-max) enriched-translations |
|---|
| 418 |
'enriched-next-annotation) |
|---|
| 419 |
|
|---|
| 420 |
|
|---|
| 421 |
(cond (file-width |
|---|
| 422 |
(setq fill-column file-width) |
|---|
| 423 |
(if enriched-verbose (message "Indenting...")) |
|---|
| 424 |
(enriched-insert-indentation)) |
|---|
| 425 |
(t |
|---|
| 426 |
(if enriched-verbose (message "Filling paragraphs...")) |
|---|
| 427 |
(fill-region (point-min) (point-max)))) |
|---|
| 428 |
(if enriched-verbose (message nil))) |
|---|
| 429 |
(point-max)))) |
|---|
| 430 |
|
|---|
| 431 |
(defun enriched-next-annotation () |
|---|
| 432 |
"Find and return next text/enriched annotation. |
|---|
| 433 |
Any \"<<\" strings encountered are converted to \"<\". |
|---|
| 434 |
Return value is \(begin end name positive-p), or nil if none was found." |
|---|
| 435 |
(while (and (search-forward "<" nil 1) |
|---|
| 436 |
(progn (goto-char (match-beginning 0)) |
|---|
| 437 |
(not (looking-at enriched-annotation-regexp)))) |
|---|
| 438 |
(forward-char 1) |
|---|
| 439 |
(if (= ?< (char-after (point))) |
|---|
| 440 |
(delete-char 1) |
|---|
| 441 |
|
|---|
| 442 |
|
|---|
| 443 |
(message "Warning: malformed annotation in file at %s" |
|---|
| 444 |
(1- (point))))) |
|---|
| 445 |
(if (not (eobp)) |
|---|
| 446 |
(let* ((beg (match-beginning 0)) |
|---|
| 447 |
(end (match-end 0)) |
|---|
| 448 |
(name (downcase (buffer-substring |
|---|
| 449 |
(match-beginning 2) (match-end 2)))) |
|---|
| 450 |
(pos (not (match-beginning 1)))) |
|---|
| 451 |
(list beg end name pos)))) |
|---|
| 452 |
|
|---|
| 453 |
(defun enriched-get-file-width () |
|---|
| 454 |
"Look for file width information on this line." |
|---|
| 455 |
(save-excursion |
|---|
| 456 |
(if (search-forward "Text-Width: " (+ (point) 1000) t) |
|---|
| 457 |
(read (current-buffer))))) |
|---|
| 458 |
|
|---|
| 459 |
(defun enriched-remove-header () |
|---|
| 460 |
"Remove file-format header at point." |
|---|
| 461 |
(while (looking-at "^[-A-Za-z]+: .*\n") |
|---|
| 462 |
(delete-region (point) (match-end 0))) |
|---|
| 463 |
(if (looking-at "^\n") |
|---|
| 464 |
(delete-char 1))) |
|---|
| 465 |
|
|---|
| 466 |
(defun enriched-decode-foreground (from to &optional color) |
|---|
| 467 |
(if color |
|---|
| 468 |
(list from to 'face (list ':foreground color)) |
|---|
| 469 |
(message "Warning: no color specified for <x-color>") |
|---|
| 470 |
nil)) |
|---|
| 471 |
|
|---|
| 472 |
(defun enriched-decode-background (from to &optional color) |
|---|
| 473 |
(if color |
|---|
| 474 |
(list from to 'face (list ':background color)) |
|---|
| 475 |
(message "Warning: no color specified for <x-bg-color>") |
|---|
| 476 |
nil)) |
|---|
| 477 |
|
|---|
| 478 |
|
|---|
| 479 |
|
|---|
| 480 |
|
|---|
| 481 |
(defun enriched-handle-display-prop (old new) |
|---|
| 482 |
"Return a list of annotations for a change in the `display' property. |
|---|
| 483 |
OLD is the old value of the property, NEW is the new value. Value |
|---|
| 484 |
is a list `(CLOSE OPEN)', where CLOSE is a list of annotations to |
|---|
| 485 |
close and OPEN a list of annotations to open. Each of these lists |
|---|
| 486 |
has the form `(ANNOTATION PARAM ...)'." |
|---|
| 487 |
(let ((annotation "x-display") |
|---|
| 488 |
(param (prin1-to-string (or old new)))) |
|---|
| 489 |
(if (null old) |
|---|
| 490 |
(cons nil (list (list annotation param))) |
|---|
| 491 |
(cons (list (list annotation param)) nil)))) |
|---|
| 492 |
|
|---|
| 493 |
(defun enriched-decode-display-prop (start end &optional param) |
|---|
| 494 |
"Decode a `display' property for text between START and END. |
|---|
| 495 |
PARAM is a `<param>' found for the property. |
|---|
| 496 |
Value is a list `(START END SYMBOL VALUE)' with START and END denoting |
|---|
| 497 |
the range of text to assign text property SYMBOL with value VALUE." |
|---|
| 498 |
(let ((prop (when (stringp param) |
|---|
| 499 |
(condition-case () |
|---|
| 500 |
(car (read-from-string param)) |
|---|
| 501 |
(error nil))))) |
|---|
| 502 |
(unless prop |
|---|
| 503 |
(message "Warning: invalid <x-display> parameter %s" param)) |
|---|
| 504 |
(list start end 'display prop))) |
|---|
| 505 |
|
|---|
| 506 |
|
|---|
| 507 |
|
|---|
| 508 |
|
|---|