diff options
| author | Richard M. Stallman | 1996-09-01 03:28:43 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1996-09-01 03:28:43 +0000 |
| commit | 8b91400357b1a66f9ea71e4389d9fde0679b951c (patch) | |
| tree | db624704cb613de0b49c37a8eb12c407ec36cff3 | |
| parent | d1abb42fc8051d53da10f2decfe436ddf599b378 (diff) | |
| download | emacs-8b91400357b1a66f9ea71e4389d9fde0679b951c.tar.gz emacs-8b91400357b1a66f9ea71e4389d9fde0679b951c.zip | |
Don't fill based on window width.
Don't require facemenu; it's preloaded if applicable.
(enriched-default-right-margin, enriched-fill-after-visiting)
(enriched-text-width): Variables deleted.
(enriched-text-width): Function deleted.
(enriched-initial-annotation): Use `fill-column' rather than
enriched-text-width.
(enriched-mode): Use `add-to-list'. Turn use-hard-newlines on by
calling function, not setting variable.
(enriched-encode): New argument ORIG-BUF; evaluate
enriched-initial-annotation in that buffer.
(enriched-decode): Turn on use-hard-newlines with function. Use new
`set-hard-newline-properties' function. Set fill-column from
File-Width header; re-fill paragraphs only if there is no File-Width
header.
| -rw-r--r-- | lisp/enriched.el | 82 |
1 files changed, 27 insertions, 55 deletions
diff --git a/lisp/enriched.el b/lisp/enriched.el index c8336de99db..f80a75e2513 100644 --- a/lisp/enriched.el +++ b/lisp/enriched.el | |||
| @@ -41,7 +41,6 @@ | |||
| 41 | ;;; Code: | 41 | ;;; Code: |
| 42 | 42 | ||
| 43 | (provide 'enriched) | 43 | (provide 'enriched) |
| 44 | (if window-system (require 'facemenu)) | ||
| 45 | 44 | ||
| 46 | ;;; | 45 | ;;; |
| 47 | ;;; Variables controlling the display | 46 | ;;; Variables controlling the display |
| @@ -50,19 +49,6 @@ | |||
| 50 | (defvar enriched-verbose t | 49 | (defvar enriched-verbose t |
| 51 | "*If non-nil, give status messages when reading and writing files.") | 50 | "*If non-nil, give status messages when reading and writing files.") |
| 52 | 51 | ||
| 53 | (defvar enriched-default-right-margin 10 | ||
| 54 | "*Default amount of space to leave on the right edge of the screen. | ||
| 55 | This can be increased inside text by changing the 'right-margin text property. | ||
| 56 | Measured in character widths. If the screen is narrower than this, it is | ||
| 57 | assumed to be 0.") | ||
| 58 | |||
| 59 | (defvar enriched-fill-after-visiting t | ||
| 60 | "If t, fills paragraphs when reading in enriched documents. | ||
| 61 | If nil, only fills when you explicitly request it. If the value is 'ask, then | ||
| 62 | it will query you whether to fill. | ||
| 63 | Filling is never done if the current text-width is the same as the value | ||
| 64 | stored in the file.") | ||
| 65 | |||
| 66 | ;;; | 52 | ;;; |
| 67 | ;;; Set up faces & display table | 53 | ;;; Set up faces & display table |
| 68 | ;;; | 54 | ;;; |
| @@ -100,7 +86,7 @@ These are set front-sticky everywhere except at hard newlines.") | |||
| 100 | (defconst enriched-initial-annotation | 86 | (defconst enriched-initial-annotation |
| 101 | (lambda () | 87 | (lambda () |
| 102 | (format "Content-Type: text/enriched\nText-Width: %d\n\n" | 88 | (format "Content-Type: text/enriched\nText-Width: %d\n\n" |
| 103 | (enriched-text-width))) | 89 | fill-column)) |
| 104 | "What to insert at the start of a text/enriched file. | 90 | "What to insert at the start of a text/enriched file. |
| 105 | If this is a string, it is inserted. If it is a list, it should be a lambda | 91 | If this is a string, it is inserted. If it is a list, it should be a lambda |
| 106 | expression, which is evaluated to get the string to insert.") | 92 | expression, which is evaluated to get the string to insert.") |
| @@ -168,9 +154,6 @@ them and their old values to `enriched-old-bindings'.") | |||
| 168 | The value is a list of \(VAR VALUE VAR VALUE...).") | 154 | The value is a list of \(VAR VALUE VAR VALUE...).") |
| 169 | (make-variable-buffer-local 'enriched-old-bindings) | 155 | (make-variable-buffer-local 'enriched-old-bindings) |
| 170 | 156 | ||
| 171 | (defvar enriched-text-width nil) | ||
| 172 | (make-variable-buffer-local 'enriched-text-width) | ||
| 173 | |||
| 174 | ;;; | 157 | ;;; |
| 175 | ;;; Define the mode | 158 | ;;; Define the mode |
| 176 | ;;; | 159 | ;;; |
| @@ -204,27 +187,22 @@ Commands: | |||
| 204 | (enriched-mode nil) ; Mode already on; do nothing. | 187 | (enriched-mode nil) ; Mode already on; do nothing. |
| 205 | 188 | ||
| 206 | (t (setq enriched-mode t) ; Turn mode on | 189 | (t (setq enriched-mode t) ; Turn mode on |
| 207 | (if (not (memq 'text/enriched buffer-file-format)) | 190 | (add-to-list 'buffer-file-format 'text/enriched) |
| 208 | (setq buffer-file-format | ||
| 209 | (cons 'text/enriched buffer-file-format))) | ||
| 210 | ;; Save old variable values before we change them. | 191 | ;; Save old variable values before we change them. |
| 211 | ;; These will be restored if we exit Enriched mode. | 192 | ;; These will be restored if we exit Enriched mode. |
| 212 | (setq enriched-old-bindings | 193 | (setq enriched-old-bindings |
| 213 | (list 'buffer-display-table buffer-display-table | 194 | (list 'buffer-display-table buffer-display-table |
| 214 | 'indent-line-function indent-line-function | 195 | 'indent-line-function indent-line-function |
| 215 | 'use-hard-newlines use-hard-newlines | ||
| 216 | 'default-text-properties default-text-properties)) | 196 | 'default-text-properties default-text-properties)) |
| 217 | (make-local-variable 'indent-line-function) | 197 | (make-local-variable 'indent-line-function) |
| 218 | (make-local-variable 'use-hard-newlines) | ||
| 219 | (make-local-variable 'default-text-properties) | 198 | (make-local-variable 'default-text-properties) |
| 220 | (setq indent-line-function 'indent-to-left-margin | 199 | (setq indent-line-function 'indent-to-left-margin |
| 221 | buffer-display-table enriched-display-table | 200 | buffer-display-table enriched-display-table) |
| 222 | use-hard-newlines t) | 201 | (use-hard-newlines 1 nil) |
| 223 | (let ((sticky (plist-get default-text-properties 'front-sticky)) | 202 | (let ((sticky (plist-get default-text-properties 'front-sticky)) |
| 224 | (p enriched-par-props)) | 203 | (p enriched-par-props)) |
| 225 | (while p | 204 | (while p |
| 226 | (if (not (memq (car p) sticky)) | 205 | (add-to-list 'sticky (car p)) |
| 227 | (setq sticky (cons (car p) sticky))) | ||
| 228 | (setq p (cdr p))) | 206 | (setq p (cdr p))) |
| 229 | (if sticky | 207 | (if sticky |
| 230 | (setq default-text-properties | 208 | (setq default-text-properties |
| @@ -302,22 +280,12 @@ the region, and the START and END of each region." | |||
| 302 | (justify-current-line t nil t)) | 280 | (justify-current-line t nil t)) |
| 303 | (forward-line 1))))) | 281 | (forward-line 1))))) |
| 304 | 282 | ||
| 305 | (defun enriched-text-width () | ||
| 306 | "The width of unindented text in this window, in characters. | ||
| 307 | This is the width of the window minus `enriched-default-right-margin'." | ||
| 308 | (or enriched-text-width | ||
| 309 | (let ((ww (window-width))) | ||
| 310 | (setq enriched-text-width | ||
| 311 | (if (> ww enriched-default-right-margin) | ||
| 312 | (- ww enriched-default-right-margin) | ||
| 313 | ww))))) | ||
| 314 | |||
| 315 | ;;; | 283 | ;;; |
| 316 | ;;; Encoding Files | 284 | ;;; Encoding Files |
| 317 | ;;; | 285 | ;;; |
| 318 | 286 | ||
| 319 | ;;;###autoload | 287 | ;;;###autoload |
| 320 | (defun enriched-encode (from to) | 288 | (defun enriched-encode (from to orig-buf) |
| 321 | (if enriched-verbose (message "Enriched: encoding document...")) | 289 | (if enriched-verbose (message "Enriched: encoding document...")) |
| 322 | (save-restriction | 290 | (save-restriction |
| 323 | (narrow-to-region from to) | 291 | (narrow-to-region from to) |
| @@ -331,7 +299,13 @@ This is the width of the window minus `enriched-default-right-margin'." | |||
| 331 | (goto-char from) | 299 | (goto-char from) |
| 332 | (insert (if (stringp enriched-initial-annotation) | 300 | (insert (if (stringp enriched-initial-annotation) |
| 333 | enriched-initial-annotation | 301 | enriched-initial-annotation |
| 334 | (funcall enriched-initial-annotation))) | 302 | (save-excursion |
| 303 | ;; Eval this in the buffer we are annotating. This | ||
| 304 | ;; fixes a bug which was saving incorrect File-Width | ||
| 305 | ;; information, since we were looking at local | ||
| 306 | ;; variables in the wrong buffer. | ||
| 307 | (if orig-buf (set-buffer orig-buf)) | ||
| 308 | (funcall enriched-initial-annotation)))) | ||
| 335 | (enriched-map-property-regions 'hard | 309 | (enriched-map-property-regions 'hard |
| 336 | (lambda (v b e) | 310 | (lambda (v b e) |
| 337 | (if (and v (= ?\n (char-after b))) | 311 | (if (and v (= ?\n (char-after b))) |
| @@ -384,37 +358,35 @@ One annotation each for foreground color, background color, italic, etc." | |||
| 384 | ;;;###autoload | 358 | ;;;###autoload |
| 385 | (defun enriched-decode (from to) | 359 | (defun enriched-decode (from to) |
| 386 | (if enriched-verbose (message "Enriched: decoding document...")) | 360 | (if enriched-verbose (message "Enriched: decoding document...")) |
| 361 | (use-hard-newlines 1 'never) | ||
| 387 | (save-excursion | 362 | (save-excursion |
| 388 | (save-restriction | 363 | (save-restriction |
| 389 | (narrow-to-region from to) | 364 | (narrow-to-region from to) |
| 390 | (goto-char from) | 365 | (goto-char from) |
| 391 | (let ((file-width (enriched-get-file-width)) | 366 | |
| 392 | (use-hard-newlines t)) | 367 | ;; Deal with header |
| 368 | (let ((file-width (enriched-get-file-width))) | ||
| 393 | (enriched-remove-header) | 369 | (enriched-remove-header) |
| 394 | 370 | ||
| 395 | ;; Deal with newlines | 371 | ;; Deal with newlines |
| 396 | (goto-char from) | ||
| 397 | (while (search-forward-regexp "\n\n+" nil t) | 372 | (while (search-forward-regexp "\n\n+" nil t) |
| 398 | (if (current-justification) | 373 | (if (current-justification) |
| 399 | (delete-char -1)) | 374 | (delete-char -1)) |
| 400 | (put-text-property (match-beginning 0) (point) 'hard t) | 375 | (set-hard-newline-properties (match-beginning 0) (point))) |
| 401 | (put-text-property (match-beginning 0) (point) 'front-sticky nil)) | ||
| 402 | 376 | ||
| 403 | ;; Translate annotations | 377 | ;; Translate annotations |
| 404 | (format-deannotate-region from (point-max) enriched-translations | 378 | (format-deannotate-region from (point-max) enriched-translations |
| 405 | 'enriched-next-annotation) | 379 | 'enriched-next-annotation) |
| 406 | 380 | ||
| 407 | ;; Fill paragraphs | 381 | ;; Indent or fill the buffer |
| 408 | (if (or (and file-width ; possible reasons not to fill: | 382 | (cond (file-width ; File was filled to this width |
| 409 | (= file-width (enriched-text-width))) ; correct wd. | 383 | (setq fill-column file-width) |
| 410 | (null enriched-fill-after-visiting) ; never fill | 384 | (if enriched-verbose (message "Indenting...")) |
| 411 | (and (eq 'ask enriched-fill-after-visiting) ; asked & declined | 385 | (enriched-insert-indentation)) |
| 412 | (not (y-or-n-p "Re-fill for current display width? ")))) | 386 | (t ; File was not filled. |
| 413 | ;; Minimally, we have to insert indentation and justification. | 387 | (if enriched-verbose (message "Filling paragraphs...")) |
| 414 | (enriched-insert-indentation) | 388 | (fill-region (point-min) (point-max)))) |
| 415 | (if enriched-verbose (message "Filling paragraphs...")) | 389 | (if enriched-verbose (message nil))) |
| 416 | (fill-region (point-min) (point-max)))) | ||
| 417 | (if enriched-verbose (message nil)) | ||
| 418 | (point-max)))) | 390 | (point-max)))) |
| 419 | 391 | ||
| 420 | (defun enriched-next-annotation () | 392 | (defun enriched-next-annotation () |