Commit 2a14f364 authored by David Byers's avatar David Byers
Browse files

Fixed bugs in paragraph filling.

Detailed changes:
> 2006-06-27  David Byers  <davby@ida.liu.se>
>
> 	* lyskom-rest.el (lyskom-fill-next-paragraph): Fixed off-by-one
> 	error causing the last character on the last line to (sometimes)
> 	be put on a line of its own in XEmacs.
> 	(lyskom-maybe-fill-region): Fixed off-by-one error causing lines
> 	just under fill-column long to be wrapped.
>
> 2006-05-14  David Byers  <davby@ida.liu.se>
>
> 	* utilities.el (lyskom-text-comments): Added parameter
> 	skip-footnotes.
>
> 2006-04-26  David Byers  <davby@ida.liu.se>
>
> 	* lyskom-rest.el (lyskom-fill-next-paragraph): Eliminated the
> 	inner catch, as this seemed to cost more time than adding a
> 	clause to each conditional in the loop.
> 	(lyskom-fill-message-line-length): Make this a subst.
>
parent 3043ba96
2006-06-27 David Byers <davby@ida.liu.se>
* lyskom-rest.el (lyskom-fill-next-paragraph): Fixed off-by-one
error causing the last character on the last line to (sometimes)
be put on a line of its own in XEmacs.
(lyskom-maybe-fill-region): Fixed off-by-one error causing lines
just under fill-column long to be wrapped.
2006-05-14 David Byers <davby@ida.liu.se>
* utilities.el (lyskom-text-comments): Added parameter
skip-footnotes.
2006-04-26 David Byers <davby@ida.liu.se>
* lyskom-rest.el (lyskom-fill-next-paragraph): Eliminated the
inner catch, as this seemed to cost more time than adding a
clause to each conditional in the loop.
(lyskom-fill-message-line-length): Make this a subst.
2006-05-03 Pontus Freyhult <pont@soua.net> 2006-05-03 Pontus Freyhult <pont@soua.net>
* option-edit.el, vars.el.in, swedish-strings.el,english-strings.el, * option-edit.el, vars.el.in, swedish-strings.el,english-strings.el,
......
...@@ -2448,18 +2448,23 @@ in lyskom-messages." ...@@ -2448,18 +2448,23 @@ in lyskom-messages."
(defmacro lyskom-fill-message-next-line () (defmacro lyskom-fill-message-next-line ()
`(throw 'lyskom-fill-message-next-line t)) `(setq next-line t))
(defmacro lyskom-fill-message-return () (defmacro lyskom-fill-message-return ()
`(throw 'lyskom-fill-message-return t)) `(throw 'lyskom-fill-message-return t))
(defsubst lyskom-fill-message-line-length ()
(- (save-excursion (end-of-line)
(skip-chars-backward " \t")
(current-column)) (current-column)))
(defmacro lyskom-maybe-fill-region (start end &optional justify nosqueeze to-eop) (defmacro lyskom-maybe-fill-region (start end &optional justify nosqueeze to-eop)
"Fill the region from START to END if the prerequisites for doing "Fill the region from START to END if the prerequisites for doing
so are met. This macro checks on the internal state of so are met. This macro checks on the internal state of
lyskom-fill-next-paragraph to see if the text scanned should be filled lyskom-fill-next-paragraph to see if the text scanned should be filled
or not." or not."
`(unless (or (<= ,end ,start) `(unless (or (<= ,end ,start)
(< paragraph-width fill-column) (<= paragraph-width fill-column)
quoted-paragraph quoted-paragraph
special-characters special-characters
(eq all-colon-lines t) (eq all-colon-lines t)
...@@ -2534,6 +2539,7 @@ or not." ...@@ -2534,6 +2539,7 @@ or not."
(paragraph-length 0) (paragraph-length 0)
(paragraph-width 0) (paragraph-width 0)
(eol-point 0) (eol-point 0)
(next-line nil)
;; Variables used for geometric texts ;; Variables used for geometric texts
(geometric-text t) (geometric-text t)
...@@ -2570,142 +2576,156 @@ or not." ...@@ -2570,142 +2576,156 @@ or not."
;; ;;
(while (not (eobp)) (while (not (eobp))
(setq next-line nil)
;; ;;
;; Code can throw to here to prevent further processing ;; Code can throw to here to prevent further processing
;; of a line of input. This is used when a line has been ;; of a line of input. This is used when a line has been
;; completely categorized. ;; completely categorized.
;; ;;
;; FIXME: Paragraph-width is only used when starting to fill a paragraph, so we should
;; FIXME: compute it only at that point.
;;
;; FIXME: If we can move the special patterns check, we can lose eol-point as well, and
;; FIXME: only compute it when it's needed to calculate paragraph-width.
(catch 'lyskom-fill-message-next-line (setq next-char (char-after (point)))
(setq next-char (char-after (point))) (setq eol-point (save-excursion (end-of-line) (point)))
(setq eol-point (save-excursion (end-of-line) (point))) (setq paragraph-width (max paragraph-width (- eol-point (point))))
(setq paragraph-width (max paragraph-width (- eol-point (point))))
;; ;;
;; Handle unconditional paragraph break (empty line) ;; Handle unconditional paragraph break (empty line)
;; ;;
;; An empty line signals the end of the paragraph, always. ;; An empty line signals the end of the paragraph, always.
;; ;;
(when (looking-at "^\\s-*$") (when (looking-at "^\\s-*$")
(lyskom-maybe-fill-region start (1- (point)) nil t) (lyskom-maybe-fill-region start (1- (point)) nil t)
(lyskom-fill-scan-empty-lines) (lyskom-fill-scan-empty-lines)
(lyskom-fill-message-return)) (lyskom-fill-message-return))
;; ;;
;; Detect special patterns ;; Detect special patterns
;; ;;
;; Here, we look for lines that have patterns that disqualify ;; Here, we look for lines that have patterns that disqualify
;; the entire paragraph from being filled. This should catch ;; the entire paragraph from being filled. This should catch
;; source code and many preformatted things. ;; source code and many preformatted things.
;; ;;
;; FIXME: It is probably possible to do this once when starting
(when (save-excursion ;; FIXME: to fill the text. Alternately, we could scan forward
(re-search-forward lyskom-fill-disqualifying-regexp eol-point t)) ;; FIXME: for a para break as soon as we spot this.
(setq special-characters t)) ;; FIXME:
;; FIXME: I suspect that indented paragraphs may trigger this
(when (looking-at lyskom-fill-inline-text-regexp) ;; FIXME: rule.
(setq special-characters t))
(when (save-excursion
(re-search-forward lyskom-fill-disqualifying-regexp eol-point t))
;; (setq special-characters t))
;; Handle unconditional paragraph break (bulleted text)
;; (when (looking-at lyskom-fill-inline-text-regexp)
;; Bullet items end the current paragraph unconditionally. (setq special-characters t))
;; If we have seen text before the item, bail out of here,
;; causing the same line to be revisited the next time
;; the function is called. Otherwise, keep scanning, but ;;
;; set a flag. ;; Handle unconditional paragraph break (bulleted text)
;; ;;
;; Bullet items end the current paragraph unconditionally.
(when (looking-at "^\\s-*\\([-*+#]\\|[§#]?\\s-*[0-9]+[.):]?\\)\\s-*") ;; If we have seen text before the item, bail out of here,
(when (lyskom-maybe-fill-region start (1- (point)) nil t) ;; causing the same line to be revisited the next time
(lyskom-fill-message-return)) ;; the function is called. Otherwise, keep scanning, but
(setq bulleted-paragraph (match-string 0)) ;; set a flag.
(lyskom-fill-message-next-line)) ;;
;; (when (and (not next-line)
;; Handle indented paragraph (looking-at "^\\s-*\\([-*+#]\\|[§#]?\\s-*[0-9]+[.):]?\\)\\s-*"))
;; (when (lyskom-maybe-fill-region start (1- (point)) nil t)
;; - It can be a continuation of a bullet point
;; - It can be a continuation of an indented para
;; - It can terminate a non-indented para
;; - It can continue an all-colon line
;;
(when (looking-at "^\\(\\s-+\\)\\S-")
(cond (bulleted-paragraph (lyskom-fill-message-next-line))
((equal (match-string 1) indented-paragraph)
(lyskom-fill-message-next-line))
((eq all-colon-lines t) (lyskom-fill-message-next-line))
((lyskom-maybe-fill-region start (1- (point)) nil t)
(lyskom-fill-message-return))
(t (setq indented-paragraph (match-string 1)))))
;;
;; If we have seen indentation, but don't see it now,
;; then this isn't an indented paragraph. It's just
;; a paragraph with first-line indentation.
;;
(when (and indented-paragraph (looking-at "^\\S-"))
(setq indented-paragraph nil))
;;
;; Handle unconditional paragraph break (quoted text)
;;
;; Quoted text also results in an unconditional paragraph
;; break. This must come after handling of indented lines
;; since whitespace is not considered a legal line start
;; character.
;;
(when (and (not (looking-at "^\\s-"))
(< (lyskom-char-to-int next-char)
(length lyskom-line-start-chars))
(not (aref lyskom-line-start-chars
(lyskom-char-to-int next-char))))
(lyskom-maybe-fill-region start (1- (point)) nil t)
(lyskom-fill-scan-quoted-paragraph next-char)
(lyskom-fill-message-return)) (lyskom-fill-message-return))
(setq bulleted-paragraph (match-string 0))
(lyskom-fill-message-next-line))
;; ;;
;; Handle header-like stuff ;; Handle indented paragraph
;; ;;
;; This rule detects mail-header-like stuff ;; - It can be a continuation of a bullet point
;; ;; - It can be a continuation of an indented para
;; - It can terminate a non-indented para
;; - It can continue an all-colon line
;;
(if (and all-colon-lines (looking-at "^\\S-+\\s-*:")) (when (and (not next-line) (looking-at "^\\(\\s-+\\)\\S-"))
(setq all-colon-lines t) (cond (bulleted-paragraph (lyskom-fill-message-next-line))
(setq all-colon-lines nil)) ((equal (match-string 1) indented-paragraph)
(lyskom-fill-message-next-line))
((eq all-colon-lines t) (lyskom-fill-message-next-line))
((lyskom-maybe-fill-region start (1- (point)) nil t)
(lyskom-fill-message-return))
(t (setq indented-paragraph (match-string 1)))))
;; Handle geometric paragraphs ;;
;; ;; If we have seen indentation, but don't see it now,
;; Geometric paragraphs have constant differences in line ;; then this isn't an indented paragraph. It's just
;; length. There is also a requirement of minimum size, ;; a paragraph with first-line indentation.
;; which is enforced in lyskom-maybe-fill-region ;;
;;
(when (and (not next-line) indented-paragraph (looking-at "^\\S-"))
(setq indented-paragraph nil))
;;
;; Handle unconditional paragraph break (quoted text)
;;
;; Quoted text also results in an unconditional paragraph
;; break. This must come after handling of indented lines
;; since whitespace is not considered a legal line start
;; character.
;;
(when (and (not next-line)
(not (looking-at "^\\s-"))
(< (lyskom-char-to-int next-char)
(length lyskom-line-start-chars))
(not (aref lyskom-line-start-chars
(lyskom-char-to-int next-char))))
(lyskom-maybe-fill-region start (1- (point)) nil t)
(lyskom-fill-scan-quoted-paragraph next-char)
(lyskom-fill-message-return))
;;
;; Handle header-like stuff
;;
;; This rule detects mail-header-like stuff
;;
(if (and (not next-line)
all-colon-lines
(looking-at "^\\S-+\\s-*:"))
(setq all-colon-lines t)
(setq all-colon-lines nil))
;; Handle geometric paragraphs
;;
;; Geometric paragraphs have constant differences in line
;; length. There is also a requirement of minimum size,
;; which is enforced in lyskom-maybe-fill-region
;;
(when geometric-text (when (and (not next-line) geometric-text)
(setq current-line-length (lyskom-fill-message-line-length)) (setq current-line-length (lyskom-fill-message-line-length))
(cond ((and (null length-difference) (cond ((and (null length-difference)
current-line-length current-line-length
last-line-length) last-line-length)
(setq length-difference (- current-line-length last-line-length))) (setq length-difference (- current-line-length last-line-length)))
((and current-line-length ((and current-line-length
last-line-length last-line-length
(/= (- current-line-length last-line-length) (/= (- current-line-length last-line-length)
length-difference)) length-difference))
(setq geometric-text nil)))) (setq geometric-text nil))))
) ;; catch lyskom-fill-message-next-line
(setq last-line-length current-line-length) (setq last-line-length current-line-length)
(end-of-line) (end-of-line)
...@@ -2719,7 +2739,7 @@ or not." ...@@ -2719,7 +2739,7 @@ or not."
) ;; while ) ;; while
(lyskom-maybe-fill-region start (1- (point)) nil t) (lyskom-maybe-fill-region start (point) nil t)
) ;; catch lyskom-fill-message-return ) ;; catch lyskom-fill-message-return
...@@ -2741,12 +2761,6 @@ or not." ...@@ -2741,12 +2761,6 @@ or not."
(beginning-of-line)))) (beginning-of-line))))
(defun lyskom-fill-message-line-length ()
(- (save-excursion (end-of-line)
(skip-chars-backward " \t")
(current-column)) (current-column)))
;;; ============================================================ ;;; ============================================================
;;; Beeping and feeping ;;; Beeping and feeping
;;; Faces and colors ;;; Faces and colors
......
...@@ -1309,11 +1309,13 @@ car of each element is the recipient number and the cdr is the type." ...@@ -1309,11 +1309,13 @@ car of each element is the recipient number and the cdr is the type."
result))))) result)))))
(nreverse result))) (nreverse result)))
(defun lyskom-text-comments (text-stat) (defun lyskom-text-comments (text-stat &optional skip-footnotes)
"Return the list of comments to TEXT-STAT" "Return the list of comments to TEXT-STAT.
If optional SKIP-FOOTNOTES is non-nil, do not return footnotes."
(let ((result nil)) (let ((result nil))
(lyskom-traverse misc (text-stat->misc-info-list text-stat) (lyskom-traverse misc (text-stat->misc-info-list text-stat)
(cond ((eq (misc-info->type misc) 'FOOTN-IN) (cond ((and (not skip-footnotes)
(eq (misc-info->type misc) 'FOOTN-IN))
(setq result (cons (misc-info->footn-in misc) result))) (setq result (cons (misc-info->footn-in misc) result)))
((eq (misc-info->type misc) 'COMM-IN) ((eq (misc-info->type misc) 'COMM-IN)
(setq result (cons (misc-info->comm-in misc) result))))) (setq result (cons (misc-info->comm-in misc) result)))))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment