From: morioka Date: Mon, 24 May 1999 05:22:14 +0000 (+0000) Subject: (tm-eword::space-process): Don't concatenate `special's. X-Git-Tag: flim-1_12_7~15 X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=85976c7124f215f1ec1cfdc9a46514f22d391562;p=elisp%2Fflim.git (tm-eword::space-process): Don't concatenate `special's. (ew-encode-rword-1): Renamed from `tm-eword::encode-string-1'; add new optional argument `must-output'; return nil if it can't encode literally. (eword-encode-rword-list): Fold SPACE or TAB in the encoded string if `ew-encode-rword-1' can't encode literally and it is possible to encode the rest literally with the folding. (eword-encode-phrase-to-rword-list): Add `special' flag to brackets of comments. --- diff --git a/eword-encode.el b/eword-encode.el index 18d8dcb..c19b097 100644 --- a/eword-encode.el +++ b/eword-encode.el @@ -206,7 +206,8 @@ MODE is allows `text', `comment', `phrase' or nil. Default value is (setq seq (cdr seq)) (setq c (car seq)) (setq cc (ew-rword-charset c)) - (if (null (ew-rword-charset b)) + (if (and (null (ew-rword-charset b)) + (not (eq (ew-rword-type b) 'special))) (progn (setq a (car prev)) (setq ac (ew-rword-charset a)) @@ -267,117 +268,117 @@ MODE is allows `text', `comment', `phrase' or nil. Default value is ;;; @ encode-string ;;; -(defun tm-eword::encode-string-1 (column rwl) - (let* ((rword (car rwl)) - (ret (tm-eword::encoded-word-length rword)) - string len) - (if (null ret) - (cond ((and (setq string (car rword)) - (or (<= (setq len (+ (length string) column)) 76) - (<= column 1)) +(defun ew-encode-rword-1 (column rwl &optional must-output) + (catch 'can-not-output + (let* ((rword (car rwl)) + (ret (tm-eword::encoded-word-length rword)) + string len) + (if (null ret) + (cond ((and (setq string (car rword)) + (or (<= (setq len (+ (length string) column)) 76) + (<= column 1)) + ) + (setq rwl (cdr rwl)) + ) + ((memq (aref string 0) '(? ?\t)) + (setq string (concat "\n" string) + len (length string) + rwl (cdr rwl)) + ) + (must-output + (setq string "\n " + len 1) + ) + (t + (throw 'can-not-output nil) + )) + (cond ((and (setq len (car ret)) + (<= (+ column len) 76) ) + (setq string + (eword-encode-text + (ew-rword-charset rword) + (ew-rword-encoding rword) + (cdr ret) + (ew-rword-type rword) + )) + (setq len (+ (length string) column)) (setq rwl (cdr rwl)) ) (t - (setq string "\n ") - (setq len 1) - )) - (cond ((and (setq len (car ret)) - (<= (+ column len) 76) - ) - (setq string - (eword-encode-text - (ew-rword-charset rword) - (ew-rword-encoding rword) - (cdr ret) - (ew-rword-type rword) - )) - (setq len (+ (length string) column)) - (setq rwl (cdr rwl)) - ) - (t - (setq string (car rword)) - (let* ((p 0) np - (str "") nstr) - (while (and (< p len) - (progn - (setq np (char-next-index (sref string p) p)) - (setq nstr (substring string 0 np)) - (setq ret (tm-eword::encoded-word-length - (cons nstr (cdr rword)) - )) - (setq nstr (cdr ret)) - (setq len (+ (car ret) column)) - (<= len 76) - )) - (setq str nstr - p np)) - (if (string-equal str "") - (setq string "\n " - len 1) - (setq rwl (cons (cons (substring string p) (cdr rword)) - (cdr rwl))) - (setq string - (eword-encode-text - (ew-rword-charset rword) - (ew-rword-encoding rword) - str - (ew-rword-type rword))) - (setq len (+ (length string) column)) - ) - ))) - ) - (list string len rwl) - )) + (setq string (car rword)) + (let* ((p 0) np + (str "") nstr) + (while (and (< p len) + (progn + (setq np (char-next-index (sref string p) p)) + (setq nstr (substring string 0 np)) + (setq ret (tm-eword::encoded-word-length + (cons nstr (cdr rword)) + )) + (setq nstr (cdr ret)) + (setq len (+ (car ret) column)) + (<= len 76) + )) + (setq str nstr + p np)) + (if (string-equal str "") + (if must-output + (setq string "\n " + len 1) + (throw 'can-not-output nil)) + (setq rwl (cons (cons (substring string p) (cdr rword)) + (cdr rwl))) + (setq string + (eword-encode-text + (ew-rword-charset rword) + (ew-rword-encoding rword) + str + (ew-rword-type rword))) + (setq len (+ (length string) column)) + ) + ))) + ) + (list string len rwl) + ))) (defun eword-encode-rword-list (column rwl) - (let (ret dest ps special str ew-f pew-f bew) + (let (ret dest str ew-f pew-f folded-points) (while rwl (setq ew-f (nth 2 (car rwl))) (if (and pew-f ew-f) (setq rwl (cons '(" ") rwl) - bew t pew-f nil) - (setq pew-f ew-f - bew nil) + (setq pew-f ew-f) ) - (setq ret (tm-eword::encode-string-1 column rwl)) + (if (null (setq ret (ew-encode-rword-1 column rwl))) + (let ((i (1- (length dest))) + c s r-dest r-column) + (catch 'success + (while (catch 'found + (while (>= i 0) + (cond ((memq (setq c (aref dest i)) '(? ?\t)) + (if (memq i folded-points) + (throw 'found nil) + (setq folded-points (cons i folded-points)) + (throw 'found i)) + ) + ((eq c ?\n) + (throw 'found nil) + )) + (setq i (1- i)))) + (setq s (substring dest i) + r-column (length s) + r-dest (concat (substring dest 0 i) "\n" s)) + (when (setq ret (ew-encode-rword-1 r-column rwl)) + (setq dest r-dest + column r-column) + (throw 'success t) + )) + (setq ret (ew-encode-rword-1 column rwl 'must-output)) + ))) (setq str (car ret)) - (if (eq (elt str 0) ?\n) - (cond - ((eq special ?\() - (setq dest (concat dest "\n (")) - (setq ret (tm-eword::encode-string-1 2 rwl)) - (setq str (car ret))) - ((eq bew t) - (setq dest (concat dest "\n ")) - (setq ret (tm-eword::encode-string-1 1 (cdr rwl))) - (setq str (car ret)))) - (cond ((eq special ? ) - (if (string= str "(") - (setq ps t) - (setq dest (concat dest " ")) - (setq ps nil) - )) - ((eq special ?\() - (if ps - (progn - (setq dest (concat dest " (")) - (setq ps nil) - ) - (setq dest (concat dest "(")) - ) - ))) - (cond ((string= str " ") - (setq special ? ) - ) - ((string= str "(") - (setq special ?\() - ) - (t - (setq special nil) - (setq dest (concat dest str)) - )) + (setq dest (concat dest str)) (setq column (nth 1 ret) rwl (nth 2 ret)) ) @@ -408,13 +409,13 @@ MODE is allows `text', `comment', `phrase' or nil. Default value is ((eq type 'comment) (setq dest (append dest - '(("(" nil nil)) + '(("(" nil nil special)) (tm-eword::words-to-ruled-words (eword-encode-charset-words-to-words (eword-encode-divide-into-charset-words (cdr token))) 'comment) - '((")" nil nil)) + '((")" nil nil special)) )) ) (t