- (cond
- ((not state)
- (setq state 'word)
- (if (not (eq (setq cs (mm-charset-after)) 'ascii))
- (setq current cs))
- (setq b (point)))
- ((eq state 'blank)
- (cond
- ((memq (char-after) special-list)
- (setq state nil))
- ((memq (char-after) blank-list))
- (t
- (setq state 'word)
- (unless b
- (setq b (point)))
- (if (not (eq (setq cs (mm-charset-after)) 'ascii))
- (setq current cs)))))
- ((eq state 'word)
- (cond
- ((memq (char-after) special-list)
- (setq state nil)
- (push (list b (point) current) words)
- (setq current nil))
- ((memq (char-after) blank-list)
- (setq state 'blank)
- (if (not current)
- (setq b nil)
- (push (list b (point) current) words)
- (setq b (point))
- (setq current nil)))
- ((or (eq (setq cs (mm-charset-after)) 'ascii)
- (if current
- (eq current cs)
- (setq current cs))))
- (t
- (push (list b (point) current) words)
- (setq current cs)
- (setq b (point))))))
- (if state
- (forward-char)
- (skip-chars-forward all-specials)))
- (if (eq state 'word)
- (push (list b (point) current) words)))
- words))
+ (setq point (point))
+ (skip-chars-backward word-chars b)
+ (unless (eq b (point))
+ (push (cons (buffer-substring b (point)) nil) words))
+ (setq b (point))
+ (goto-char point)
+ (setq current (mm-charset-after))
+ (forward-char 1)
+ (skip-chars-forward word-chars)
+ (while (and (not (eobp))
+ (eq (mm-charset-after) current))
+ (forward-char 1)
+ (skip-chars-forward word-chars))
+ (unless (eq b (point))
+ (push (cons (buffer-substring b (point)) current) words))
+ (setq b (point))
+ (skip-chars-forward "\000-\177"))
+ (unless (eq b (point))
+ (push (cons (buffer-substring b (point)) nil) words)))
+ ;; merge adjacent words
+ (setq word (pop words))
+ (while word
+ (if (and (cdr word)
+ (caar words)
+ (not (cdar words))
+ (string-match "^[ \t]+$" (caar words)))
+ (if (eq (cdr (nth 1 words)) (cdr word))
+ (progn
+ (setq word (cons (concat
+ (car (nth 1 words)) (caar words)
+ (car word))
+ (cdr word)))
+ (pop words)
+ (pop words))
+ (push (cons (concat (caar words) (car word)) (cdr word))
+ result)
+ (pop words)
+ (setq word (pop words)))
+ (push word result)
+ (setq word (pop words))))
+ result))