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

Improve handling when filling very long texts.

Detailed changes:
> 	Handle breaking very long texts:
> 	* lyskom-rest.el (lyskom-fill-message): Added option of a timeout
> 	for filling, replaced whitespace deletion at the end with a method
> 	that does not rely on regexps (it seems that anchoring a regexp at
> 	the end of the buffer does not improve performance as much as I
> 	expected), and caused C-g to break out of the filling loop, but
> 	not out of the function.
>
> 	* vars.el.in (kom-autowrap-timeout): New variable.
>
parent 88aacfa7
2003-08-28 David Byers <byers@lysator.liu.se>
Handle breaking very long texts:
* lyskom-rest.el (lyskom-fill-message): Added option of a timeout
for filling, replaced whitespace deletion at the end with a method
that does not rely on regexps (it seems that anchoring a regexp at
the end of the buffer does not improve performance as much as I
expected), and caused C-g to break out of the filling loop, but
not out of the function.
* vars.el.in (kom-autowrap-timeout): New variable.
Fix bug 1117:
* commands2.el (kom-set-garb-nice): Moved kom-set-keep-commented
into this function. It makes more sense that way.
......
......@@ -2849,6 +2849,8 @@ Select whether to execute command or keyboard macro.")
(no . "No ")
(to-file . "To file:")
(max-text-length . "For texts shorter than: ")
(autowrap-timeout . "Timeout in seconds: ")
(no-timeout . "No timeout")
(friends . "Friends and other special people")
......@@ -3406,7 +3408,19 @@ up menus.")
(kom-autowrap-doc . "\
With this setting turned on, LysKOM will attempt to fill any paragraphs
containing lines that are wider than the screen. Paragraphs that appear
to have been preformatted by the author are exempted from this treatment.")
to have been preformatted by the author are exempted from this treatment.
If set to a number, only texts shorter than this number (in characters)
will be filled. This may be useful to avoid filling very long texts.")
(kom-autowrap-timeout-doc . "\
This setting controls the maximum number of seconds the client may
spend attempting to fill paragraphs of a text. This is useful to
avoid long waits while the client is breaking lines in a very long
text. The actual time spent filling paragraphs may be several
seconds longer than this value. Unfortunately there is no way to
avoid this. Furthermore, setting a limit slows down all text display
slightly. When this is off, it is still possible to cancel paragraph
filling by typing C-g.")
(kom-show-author-at-end-doc . "\
When this is turned on, the name of the author will be shown at the end
......@@ -4107,6 +4121,8 @@ up menus.")
"Dashed lines around the text body: ")
(kom-autowrap-tag .
"Fill wide paragraphs before displaying: ")
(kom-autowrap-timeout-tag .
"Maximum time spend filling paragraphs: ")
(kom-show-author-at-end-tag .
"Show the name of the author after the body: ")
......
......@@ -2443,23 +2443,26 @@ in lyskom-messages."
(insert text)
(goto-char (point-min))
(let ((start (point))
(in-paragraph nil)
(wrap-paragraph 'maybe)
(length-difference nil)
(constant-length nil)
(all-lines-colons t)
(current-line-length nil)
(last-line-length nil)
(paragraph-length 0)
(eol-point nil)
(have-indented-paragraphs nil)
(fill-column
(cond ((not (integerp fill-column)) (- (window-width) 5))
((> fill-column (- (window-width) 5)) (- (window-width) 5))
(t fill-column)))
(fill-prefix nil)
(single-line-regexp "\\(\\S-\\)"))
(let* ((start (point))
(in-paragraph nil)
(wrap-paragraph 'maybe)
(length-difference nil)
(constant-length nil)
(all-lines-colons t)
(current-line-length nil)
(last-line-length nil)
(paragraph-length 0)
(eol-point nil)
(have-indented-paragraphs nil)
(cancel (cons nil nil))
(timer (and kom-autowrap-timeout
(run-at-time kom-autowrap-timeout nil (lambda (obj) (setcdr obj t)) cancel)))
(fill-column
(cond ((not (integerp fill-column)) (- (window-width) 5))
((> fill-column (- (window-width) 5)) (- (window-width) 5))
(t fill-column)))
(fill-prefix nil)
(single-line-regexp "\\(\\S-\\)"))
;;
;; Scan each line
......@@ -2487,7 +2490,7 @@ in lyskom-messages."
(cond
;;
;; An empty line signifies a new paragraph. If we were scanning
;; An empty line signifies a new paragraph. If we were scanning
;; a paragraph and it was to be filled, fill it.
;;
......@@ -2517,7 +2520,7 @@ in lyskom-messages."
(setq wrap-paragraph nil))
;;
;; We're in a paragraph, but we see indentation, a dash or
;; We're in a paragraph, but we see indentation, a dash or
;; something that looks like the end of a LysKOM text.
;; This has to mean something...
;;
......@@ -2575,8 +2578,8 @@ in lyskom-messages."
;;
;; 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
;; see what looks like an indented paragraph. Take care with
;; this one!
;;
......@@ -2598,7 +2601,7 @@ in lyskom-messages."
current-line-length (match-beginning 2))))
;;
;; Not in a paragraph, but here comes some text. Let's start
;; Not in a paragraph, but here comes some text. Let's start
;; a paragraph, shall we?
;;
......@@ -2618,7 +2621,7 @@ in lyskom-messages."
;;
;; 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
......@@ -2632,8 +2635,8 @@ in lyskom-messages."
(setq wrap-paragraph nil))
;;
;; We're in a paragraph, the line looks OK, but is long. That
;; means we should probably be filling the paragraph later
;; We're in a paragraph, the line looks OK, but is long. That
;; means we should probably be filling the paragraph later
;;
((and in-paragraph
......@@ -2679,8 +2682,12 @@ in lyskom-messages."
(setq paragraph-length (1+ paragraph-length))
(unless (eobp)
(forward-line 1)
(beginning-of-line)))
(beginning-of-line)
(when kom-autowrap-timeout
(sit-for 0)
(and (cdr cancel) (error "Out of time")))))
(quit (goto-char (point-max))
(setq in-paragraph nil))
(error (goto-char (point-max))
(setq in-paragraph nil)))
......@@ -2703,10 +2710,12 @@ in lyskom-messages."
;; Kill off unwanted whitespace at the end of the message
;;
(let ((tmp (buffer-string)))
(if (string-match "[ \t\n]+\\'" tmp)
(substring tmp 0 (match-beginning 0))
tmp))))))
(let* ((pos (1- (point-max))))
(while (and (> pos 0)
(progn (goto-char pos)
(looking-at "[ \t\n\r]")))
(setq pos (1- pos)))
(buffer-substring (point-min) pos))))))
(defun lyskom-fill-message-line-length ()
(- (save-excursion (end-of-line)
......
......@@ -207,6 +207,7 @@
[kom-postpone-default]
"\n"
[kom-autowrap]
[kom-autowrap-timeout]
[kom-show-author-at-end]
[kom-show-creating-software]
[kom-show-imported-importer]
......@@ -613,6 +614,8 @@ All key bindings:
(kom-autowrap (choice ((const (on t))
(const (off nil))
(number nil :tag max-text-length))))
(kom-autowrap-timeout (choice ((const (no-timeout nil))
(number nil :tag autowrap-timeout))))
(kom-auto-list-faqs (toggle (on off)))
(kom-auto-review-faqs (toggle (on off)))
(kom-dashed-lines (toggle (on off)))
......
......@@ -2961,6 +2961,8 @@ att upprepas d
(no . "Nej")
(to-file . "Till fil:")
(max-text-length . "Fr inlgg kortare n: ")
(autowrap-timeout . "Antal sekunder: ")
(no-timeout . "Ingen tidsbegrnsning")
(friends . "Vnner och bekanta")
......@@ -3547,7 +3549,18 @@ ta fram menyer.")
(kom-autowrap-doc . "\
Om detta r pslaget s kommer LysKOM att frska bryta om raderna i
stycken vars rader egentligen r lngre n skrmen r bred. Stycken
som verkar vara frformatterade av frfattaren bryts dock aldrig om.")
som verkar vara frformatterade av frfattaren bryts dock aldrig om.
Det gr att ange en maximal lngd i tecken p inlgg som fr brytas
om (vilket kan vara anvndbart fr att undvika mycket lnga inlgg).")
(kom-autowrap-timeout-doc . "\
Denna instllning begrnsar hur lng tid automatisk ombrytning av
raderna i ett inlgg fr ta (i sekunder). En begrnsning r srskilt
anvndbar nr man lser mycket lnga inlgg. Notera att tiden r
hgst ungefrlig. Ombrytningen kan pg i flera sekunder lngre n
detta vrde. Begrnsningen gr ocks att all inlggsvisning gr
aningen lngsammare. Om begrnsningen r avstngd kan man nd
avbryta ombrytningen genom att trycka C-g.")
(kom-print-number-of-unread-on-entrance-doc . "\
Om detta r pslaget s visas antalet olsta i ett mte nr man gr till
......@@ -4227,6 +4240,8 @@ ta fram menyer.")
"Streckade linjer kring inlggstexten: ")
(kom-autowrap-tag .
"Automatisk radbrytning vid lsning: ")
(kom-autowrap-timeout-tag .
"Tidsbegrnsning av automatisk radbrytning: ")
(kom-show-author-at-end-tag .
"Visa frfattarens namn efter inlgget: ")
......
......@@ -2082,6 +2082,22 @@ Values other than `t', `nil' and integers are reserved for future
use."
server)
(def-kom-var kom-autowrap-timeout 5
"**Limits how much time automatic text wrapping may take.
When set to an integer, limits the number of seconds automatic line
breaking may take. Without a limitation, breaking lines of a very long
text can take a very, very long time. Note that this setting is
approximate; the actual time spent breaking lines may be several
seconds longer than this value. Furthermore, using this setting slows
down all text display slightly.
When set to `nil', do not limit the amout of time automatic line
breaking may take.
Values other than `nil' and integers are reserved for future use."
server)
(def-kom-var kom-keep-alive-interval 180
"**Polling interval for `kom-keep-alive'.
......
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