Commit c1b0489b authored by David Byers's avatar David Byers
Browse files

Added error check in lyskom-fill-message so errors in filling don't prevent displaying the message

parent 55cb0063
2001-05-10 David Byers <davby@ida.liu.se>
* lyskom-rest.el (lyskom-fill-message): Protect the filling loop
from errors (such as regexp stack overflows).
2001-05-09 David Byers <davby@ida.liu.se> 2001-05-09 David Byers <davby@ida.liu.se>
* ChangeLog: Set language environment. * ChangeLog: Set language environment.
......
...@@ -1916,201 +1916,202 @@ in lyskom-messages." ...@@ -1916,201 +1916,202 @@ in lyskom-messages."
;; Scan each line ;; Scan each line
;; ;;
(while (not (eobp)) (condition-case nil
(setq current-line-length (lyskom-fill-message-line-length)) (while (not (eobp))
(setq current-line-length (lyskom-fill-message-line-length))
;;
;; Do some work on checking for constant differences ;;
;; ;; Do some work on checking for constant differences
;;
(cond ((null length-difference)
(when (and current-line-length last-line-length) (cond ((null length-difference)
(setq length-difference (- current-line-length (when (and current-line-length last-line-length)
last-line-length)))) (setq length-difference (- current-line-length
((eq constant-length 'maybe-not) last-line-length))))
(setq constant-length nil)) ((eq constant-length 'maybe-not)
(constant-length (setq constant-length nil))
(unless (= (- current-line-length last-line-length) (constant-length
length-difference) (unless (= (- current-line-length last-line-length)
(setq constant-length 'maybe-not)))) length-difference)
(setq constant-length 'maybe-not))))
(cond
(cond
;;
;; An empty line signifies a new paragraph. If we were scanning ;;
;; a paragraph and it was to be filled, fill it. ;; An empty line signifies a new paragraph. If we were scanning
;; ;; a paragraph and it was to be filled, fill it.
;;
((looking-at "^\\s-*$")
(when (and in-paragraph ((looking-at "^\\s-*$")
(not all-lines-colons) (when (and in-paragraph
(eq wrap-paragraph t) (not all-lines-colons)
(or (null constant-length) (eq wrap-paragraph t)
(and (eq 0 length-difference) (or (null constant-length)
(< paragraph-length lyskom-minimum-brick-size)) (and (eq 0 length-difference)
(and (not (eq 0 length-difference)) (< paragraph-length lyskom-minimum-brick-size))
(< paragraph-length lyskom-minimum-triagle-size)))) (and (not (eq 0 length-difference))
(lyskom-fill-region start (1- (match-beginning 0)) nil t) (< paragraph-length lyskom-minimum-triagle-size))))
(lyskom-signal-reformatted-text 'reformat-filled)) (lyskom-fill-region start (1- (match-beginning 0)) nil t)
(setq start (match-end 0) (lyskom-signal-reformatted-text 'reformat-filled))
in-paragraph nil (setq start (match-end 0)
all-lines-colons t in-paragraph nil
wrap-paragraph 'maybe)) all-lines-colons t
wrap-paragraph 'maybe))
;;
;; We're in a paragraph, but wait! This looks like ;;
;; a LysKOM text! ;; We're in a paragraph, but wait! This looks like
;; ;; a LysKOM text!
;;
((looking-at (concat "^" (regexp-quote (lyskom-get-string 'subject))
".*\n----")) ((looking-at (concat "^" (regexp-quote (lyskom-get-string 'subject))
(setq wrap-paragraph nil)) ".*\n----"))
(setq wrap-paragraph nil))
;;
;; We're in a paragraph, but we see indentation, a dash or ;;
;; something that looks like the end of a LysKOM text. ;; We're in a paragraph, but we see indentation, a dash or
;; This has to mean something... ;; something that looks like the end of a LysKOM text.
;; ;; This has to mean something...
;;
((and in-paragraph
(looking-at "^\\s-+\\([^\n]*\\)\\(\n\\S-\\|\\'\\)") ((and in-paragraph
(or (not (eq (point-max) (match-beginning 2))) (looking-at "^\\s-+\\([^\n]*\\)\\(\n\\S-\\|\\'\\)")
have-indented-paragraphs)) (or (not (eq (point-max) (match-beginning 2)))
(setq have-indented-paragraphs t) have-indented-paragraphs))
(when (and (eq wrap-paragraph t) (setq have-indented-paragraphs t)
(not all-lines-colons) (when (and (eq wrap-paragraph t)
(or (and (eq 0 length-difference) (not all-lines-colons)
(< paragraph-length lyskom-minimum-brick-size)) (or (and (eq 0 length-difference)
(and (not (eq 0 length-difference)) (< paragraph-length lyskom-minimum-brick-size))
(< paragraph-length lyskom-minimum-triagle-size)) (and (not (eq 0 length-difference))
(null constant-length))) (< paragraph-length lyskom-minimum-triagle-size))
(lyskom-fill-region start (match-beginning 0) nil t) (null constant-length)))
(lyskom-signal-reformatted-text 'reformat-filled)) (lyskom-fill-region start (match-beginning 0) nil t)
(setq start (match-beginning 0) (lyskom-signal-reformatted-text 'reformat-filled))
in-paragraph t (setq start (match-beginning 0)
paragraph-length 0 in-paragraph t
constant-length t paragraph-length 0
length-difference nil constant-length t
last-line-length nil length-difference nil
all-lines-colons (lyskom-fill-message-colon-line) last-line-length nil
single-line-regexp "\\(\\S-\\)" all-lines-colons (lyskom-fill-message-colon-line)
fill-prefix nil single-line-regexp "\\(\\S-\\)"
start (match-beginning 0) fill-prefix nil
wrap-paragraph (lyskom-fill-message-initial-wrap start (match-beginning 0)
current-line-length (match-beginning 1)))) wrap-paragraph (lyskom-fill-message-initial-wrap
current-line-length (match-beginning 1))))
((and in-paragraph
(looking-at "^\\s-*\\(-+\\|\\++\\)\\s-*\\S-")) ((and in-paragraph
(when (and (eq wrap-paragraph t) (looking-at "^\\s-*\\(-+\\|\\++\\)\\s-*\\S-"))
(not all-lines-colons) (when (and (eq wrap-paragraph t)
(or (and (eq 0 length-difference) (not all-lines-colons)
(< paragraph-length lyskom-minimum-brick-size)) (or (and (eq 0 length-difference)
(and (not (eq 0 length-difference)) (< paragraph-length lyskom-minimum-brick-size))
(< paragraph-length lyskom-minimum-triagle-size)) (and (not (eq 0 length-difference))
(null constant-length))) (< paragraph-length lyskom-minimum-triagle-size))
(lyskom-fill-region start (match-beginning 0) nil t) (null constant-length)))
(lyskom-signal-reformatted-text 'reformat-filled)) (lyskom-fill-region start (match-beginning 0) nil t)
(setq start (match-beginning 0) (lyskom-signal-reformatted-text 'reformat-filled))
in-paragraph t (setq start (match-beginning 0)
paragraph-length 0 in-paragraph t
constant-length t paragraph-length 0
length-difference nil constant-length t
all-lines-colons (lyskom-fill-message-colon-line) length-difference nil
last-line-length nil all-lines-colons (lyskom-fill-message-colon-line)
single-line-regexp "\\(\\S-\\)" last-line-length nil
fill-prefix nil single-line-regexp "\\(\\S-\\)"
start (match-beginning 0) fill-prefix nil
wrap-paragraph (lyskom-fill-message-initial-wrap start (match-beginning 0)
current-line-length (match-beginning 1)))) wrap-paragraph (lyskom-fill-message-initial-wrap
current-line-length (match-beginning 1))))
;;
;; Here's a tricky one... We're not in a paragraph, and we ;;
;; see what looks like an indented paragraph. Take care with ;; Here's a tricky one... We're not in a paragraph, and we
;; this one! ;; see what looks like an indented paragraph. Take care with
;; ;; this one!
;;
((and (not in-paragraph)
(looking-at "\\(\\s-+\\)\\S-") ((and (not in-paragraph)
(looking-at (concat "\\(\\s-+\\)[^\n]*\n" (looking-at "\\(\\s-+\\)\\S-")
(match-string 1) (looking-at (concat "\\(\\s-+\\)[^\n]*\n"
"\\(\\S-\\)"))) (match-string 1)
(setq in-paragraph t "\\(\\S-\\)")))
paragraph-length 0 (setq in-paragraph t
constant-length 0 paragraph-length 0
length-difference nil constant-length 0
last-line-length nil length-difference nil
all-lines-colons (lyskom-fill-message-colon-line) last-line-length nil
start (match-beginning 0) all-lines-colons (lyskom-fill-message-colon-line)
fill-prefix (match-string 1) start (match-beginning 0)
single-line-regexp (concat (match-string 1) "\\(\\S-\\)") fill-prefix (match-string 1)
wrap-paragraph (lyskom-fill-message-initial-wrap single-line-regexp (concat (match-string 1) "\\(\\S-\\)")
current-line-length (match-beginning 2)))) wrap-paragraph (lyskom-fill-message-initial-wrap
current-line-length (match-beginning 2))))
;;
;; Not in a paragraph, but here comes some text. Let's start ;;
;; a paragraph, shall we? ;; Not in a paragraph, but here comes some text. Let's start
;; ;; a paragraph, shall we?
;;
((and (not in-paragraph)
(looking-at "\\s-*\\(\\S-\\)")) ((and (not in-paragraph)
(setq in-paragraph t (looking-at "\\s-*\\(\\S-\\)"))
paragraph-length 0 (setq in-paragraph t
all-lines-colons (lyskom-fill-message-colon-line) paragraph-length 0
constant-length t all-lines-colons (lyskom-fill-message-colon-line)
length-difference nil constant-length t
last-line-length nil length-difference nil
start (match-beginning 0) last-line-length nil
fill-prefix nil start (match-beginning 0)
single-line-regexp "\\(\\S-\\)" fill-prefix nil
wrap-paragraph (lyskom-fill-message-initial-wrap single-line-regexp "\\(\\S-\\)"
current-line-length (match-beginning 1)))) wrap-paragraph (lyskom-fill-message-initial-wrap
current-line-length (match-beginning 1))))
;;
;;
;; We're in a paragraph, but the line looks kind of strange ;; We're in a paragraph, but the line looks kind of strange
;; ;;
((and in-paragraph ((and in-paragraph
(or (not (looking-at single-line-regexp)) (or (not (looking-at single-line-regexp))
(and (< (char-to-int (char-after (match-beginning 1))) (and (< (char-to-int (char-after (match-beginning 1)))
(length lyskom-line-start-chars)) (length lyskom-line-start-chars))
(not (aref lyskom-line-start-chars (not (aref lyskom-line-start-chars
(char-to-int (char-to-int
(char-after (char-after
(match-beginning 1)))))))) (match-beginning 1))))))))
(setq wrap-paragraph nil)) (setq wrap-paragraph nil))
;; ;;
;; We're in a paragraph, the line looks OK, but is long. That ;; We're in a paragraph, the line looks OK, but is long. That
;; means we should probably be filling the paragraph later ;; means we should probably be filling the paragraph later
;; ;;
((and in-paragraph ((and in-paragraph
wrap-paragraph wrap-paragraph
(> current-line-length fill-column)) (> current-line-length fill-column))
(setq wrap-paragraph t)) (setq wrap-paragraph t))
) )
;; ;;
;; Check if the line starts with Foo: ;; Check if the line starts with Foo:
;; ;;
(when (and in-paragraph (when (and in-paragraph
all-lines-colons all-lines-colons
(not (lyskom-fill-message-colon-line))) (not (lyskom-fill-message-colon-line)))
(setq all-lines-colons nil)) (setq all-lines-colons nil))
;; ;;
;; Certain things are guaranteed to disqualify the ;; Certain things are guaranteed to disqualify the
;; current paragraph from wrapping, no matter what. ;; current paragraph from wrapping, no matter what.
;; This is where we look for those. ;; This is where we look for those.
;; ;;
(when (and in-paragraph (when (and in-paragraph
wrap-paragraph) wrap-paragraph)
(setq eol-point (save-excursion (end-of-line) (point))) (setq eol-point (save-excursion (end-of-line) (point)))
(when (re-search-forward "\ (when (re-search-forward "\
\\(\\S-[ \t][ \t][ \t]+\\S-\ \\(\\S-[ \t][ \t][ \t]+\\S-\
\\|\\S-[ \t]* \t[ \t]*\\S-\ \\|\\S-[ \t]* \t[ \t]*\\S-\
\\|[ \t]*\t [ \t]*\ \\|[ \t]*\t [ \t]*\
...@@ -2120,16 +2121,19 @@ in lyskom-messages." ...@@ -2120,16 +2121,19 @@ in lyskom-messages."
\\|\\*/\ \\|\\*/\
\\|[^:]//\ \\|[^:]//\
\\)" \\)"
eol-point t) eol-point t)
(setq wrap-paragraph nil))) (setq wrap-paragraph nil)))
(setq last-line-length current-line-length)
(end-of-line)
(setq paragraph-length (1+ paragraph-length))
(unless (eobp)
(forward-line 1)
(beginning-of-line)))
(setq last-line-length current-line-length) (error (goto-char (point-max))
(end-of-line) (setq in-paragraph nil)))
(setq paragraph-length (1+ paragraph-length))
(unless (eobp)
(forward-line 1)
(beginning-of-line)))
;; ;;
;; We've seen the end of buffer. Fill any unfilled junk. ;; We've seen the end of buffer. Fill any unfilled junk.
......
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