aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2003-04-30 21:01:05 +0000
committerStefan Monnier2003-04-30 21:01:05 +0000
commite3d2084cb13aa84751c8052fb16b30fb60b6f6e3 (patch)
tree46b966b36dddb0875edf0274d1e6ead2b164fe0d
parentdca6b77cab8309734a9539ab375f5160210882f5 (diff)
downloademacs-e3d2084cb13aa84751c8052fb16b30fb60b6f6e3.tar.gz
emacs-e3d2084cb13aa84751c8052fb16b30fb60b6f6e3.zip
(text-property-default-nonsticky): Add fill-space.
(fill-delete-newlines): Respect the new property. (fill-newline): Use the property instead of leaving "spurious" spaces.
-rw-r--r--lisp/textmodes/fill.el42
1 files changed, 24 insertions, 18 deletions
diff --git a/lisp/textmodes/fill.el b/lisp/textmodes/fill.el
index a8a98524838..348c73a0ce5 100644
--- a/lisp/textmodes/fill.el
+++ b/lisp/textmodes/fill.el
@@ -406,6 +406,12 @@ Point is moved to just past the fill prefix on the first line."
406 (goto-char (match-end 0))) 406 (goto-char (match-end 0)))
407 (setq from (point)))) 407 (setq from (point))))
408 408
409;; The `fill-space' property carries the string with which a newline
410;; should be replaced when unbreaking a line (in fill-delete-newlines).
411;; It is added to newline characters by fill-newline when the default
412;; behavior of fill-delete-newlines is not what we want.
413(add-to-list 'text-property-default-nonsticky '(fill-space . t))
414
409(defun fill-delete-newlines (from to justify nosqueeze squeeze-after) 415(defun fill-delete-newlines (from to justify nosqueeze squeeze-after)
410 (goto-char from) 416 (goto-char from)
411 ;; Make sure sentences ending at end of line get an extra space. 417 ;; Make sure sentences ending at end of line get an extra space.
@@ -434,15 +440,17 @@ Point is moved to just past the fill prefix on the first line."
434 ;; character preceding a newline has text property 440 ;; character preceding a newline has text property
435 ;; `nospace-between-words'. 441 ;; `nospace-between-words'.
436 (while (search-forward "\n" to t) 442 (while (search-forward "\n" to t)
437 (let ((prev (char-before (match-beginning 0))) 443 (if (get-text-property (match-beginning 0) 'fill-space)
438 (next (following-char))) 444 (replace-match (get-text-property (match-beginning 0) 'fill-space))
439 (if (and (or (aref (char-category-set next) ?|) 445 (let ((prev (char-before (match-beginning 0)))
440 (aref (char-category-set prev) ?|)) 446 (next (following-char)))
441 (or (get-charset-property (char-charset prev) 447 (if (and (or (aref (char-category-set next) ?|)
442 'nospace-between-words) 448 (aref (char-category-set prev) ?|))
443 (get-text-property (1- (match-beginning 0)) 449 (or (get-charset-property (char-charset prev)
444 'nospace-between-words))) 450 'nospace-between-words)
445 (delete-char -1))))) 451 (get-text-property (1- (match-beginning 0))
452 'nospace-between-words)))
453 (delete-char -1))))))
446 454
447 (goto-char from) 455 (goto-char from)
448 (skip-chars-forward " \t") 456 (skip-chars-forward " \t")
@@ -520,19 +528,17 @@ The break position will be always after LINEBEG and generally before point."
520 ;; Replace whitespace here with one newline, then 528 ;; Replace whitespace here with one newline, then
521 ;; indent to left margin. 529 ;; indent to left margin.
522 (skip-chars-backward " \t") 530 (skip-chars-backward " \t")
523 (if (and (= (following-char) ?\ )
524 (or (aref (char-category-set (preceding-char)) ?|)
525 (looking-at "[ \t]+\\c|")))
526 ;; We need one space at end of line so that
527 ;; further filling won't delete it. NOTE: We
528 ;; intentionally leave this one space to
529 ;; distinguish the case that user wants to put
530 ;; space between \c| characters.
531 (forward-char 1))
532 (insert ?\n) 531 (insert ?\n)
533 ;; Give newline the properties of the space(s) it replaces 532 ;; Give newline the properties of the space(s) it replaces
534 (set-text-properties (1- (point)) (point) 533 (set-text-properties (1- (point)) (point)
535 (text-properties-at (point))) 534 (text-properties-at (point)))
535 (and (looking-at "\\( [ \t]*\\)\\(\\c|\\)?")
536 (or (aref (char-category-set (or (char-before (1- (point))) ?\000)) ?|)
537 (match-end 2))
538 ;; When refilling later on, this newline would normally not be replaced
539 ;; by a space, so we need to mark it specially to re-install the space
540 ;; when we unfill.
541 (put-text-property (1- (point)) (point) 'fill-space (match-string 1)))
536 ;; If we don't want breaks in invisible text, don't insert 542 ;; If we don't want breaks in invisible text, don't insert
537 ;; an invisible newline. 543 ;; an invisible newline.
538 (if fill-nobreak-invisible 544 (if fill-nobreak-invisible