31717
+ ��膩��� 1 ;;; flow-fill.el --- interprete RFC2646 "flowed" text
+ ��膩��� 2
+ ��膩��� 3 ;; Copyright (C) 2000 Free Software Foundation, Inc.
+ ��膩��� 4
+ ��膩��� 5 ;; Author: Simon Josefsson <jas@pdc.kth.se>
+ ��膩��� 6 ;; Keywords: mail
+ ��膩��� 7
+ ��膩��� 8 ;; This file is part of GNU Emacs.
+ ��膩��� 9
+ ��膩��� 10 ;; GNU Emacs is free software; you can redistribute it and/or modify
+ ��膩��� 11 ;; it under the terms of the GNU General Public License as published by
+ ��膩��� 12 ;; the Free Software Foundation; either version 2, or (at your option)
+ ��膩��� 13 ;; any later version.
+ ��膩��� 14
+ ��膩��� 15 ;; GNU Emacs is distributed in the hope that it will be useful,
+ ��膩��� 16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ��膩��� 17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ��膩��� 18 ;; GNU General Public License for more details.
+ ��膩��� 19
+ ��膩��� 20 ;; You should have received a copy of the GNU General Public License
+ ��膩��� 21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
+ ��膩��� 22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ ��膩��� 23 ;; Boston, MA 02111-1307, USA.
+ ��膩��� 24
+ ��膩��� 25 ;;; Commentary:
+ ��膩��� 26
+ ��膩��� 27 ;; This implement decoding of RFC2646 formatted text, including the
+ ��膩��� 28 ;; quoted-depth wins rules.
+ ��膩��� 29
+ ��膩��� 30 ;; Theory of operation: search for lines ending with SPC, save quote
+ ��膩��� 31 ;; length of line, remove SPC and concatenate line with the following
+ ��膩��� 32 ;; line if quote length of following line matches current line.
+ ��膩��� 33
+ ��膩��� 34 ;; When no further concatenations are possible, we've found a
+ ��膩��� 35 ;; paragraph and we let `fill-region' fill the long line into several
+ ��膩��� 36 ;; lines with the quote prefix as `fill-prefix'.
+ ��膩��� 37
32923
+ ��膩��� 38 ;; Todo: encoding, implement basic `fill-region' (Emacs and XEmacs
+ ��膩��� 39 ;; implementations differ..)
31717
+ ��膩��� 40
+ ��膩��� 41 ;; History:
+ ��膩��� 42
+ ��膩��� 43 ;; 2000-02-17 posted on ding mailing list
+ ��膩��� 44 ;; 2000-02-19 use `point-at-{b,e}ol' in XEmacs
+ ��膩��� 45 ;; 2000-03-11 no compile warnings for point-at-bol stuff
+ ��膩��� 46 ;; 2000-03-26 commited to gnus cvs
32923
+ ��膩��� 47 ;; 2000-10-23 don't flow "-- " lines, make "quote-depth wins" rule
+ ��膩��� 48 ;; work when first line is at level 0.
31717
+ ��膩��� 49
+ ��膩��� 50 ;;; Code:
+ ��膩��� 51
32923
+ ��膩��� 52 (eval-when-compile (require 'cl))
+ ��膩��� 53
31717
+ ��膩��� 54 (eval-and-compile
+ ��膩��� 55 (defalias 'fill-flowed-point-at-bol
+ ��膩��� 56 (if (fboundp 'point-at-bol)
+ ��膩��� 57 'point-at-bol
+ ��膩��� 58 'line-beginning-position))
32923
+ ��膩��� 59
+ ��膩��� 60 (defalias 'fill-flowed-point-at-eol
31717
+ ��膩��� 61 (if (fboundp 'point-at-eol)
+ ��膩��� 62 'point-at-eol
+ ��膩��� 63 'line-end-position)))
+ ��膩��� 64
+ ��膩��� 65 (defun fill-flowed (&optional buffer)
+ ��膩��� 66 (save-excursion
+ ��膩��� 67 (set-buffer (or (current-buffer) buffer))
+ ��膩��� 68 (goto-char (point-min))
+ ��膩��� 69 (while (re-search-forward " $" nil t)
+ ��膩��� 70 (when (save-excursion
+ ��膩��� 71 (beginning-of-line)
+ ��膩��� 72 (looking-at "^\\(>*\\)\\( ?\\)"))
32923
+ ��膩��� 73 (let ((quote (match-string 1)) sig)
31717
+ ��膩��� 74 (if (string= quote "")
+ ��膩��� 75 (setq quote nil))
+ ��膩��� 76 (when (and quote (string= (match-string 2) ""))
+ ��膩��� 77 (save-excursion
+ ��膩��� 78 ;; insert SP after quote for pleasant reading of quoted lines
+ ��膩��� 79 (beginning-of-line)
+ ��膩��� 80 (when (> (skip-chars-forward ">") 0)
+ ��膩��� 81 (insert " "))))
+ ��膩��� 82 (while (and (save-excursion
32923
+ ��膩��� 83 (ignore-errors (backward-char 3))
+ ��膩��� 84 (setq sig (looking-at "-- "))
31717
+ ��膩��� 85 (looking-at "[^-][^-] "))
+ ��膩��� 86 (save-excursion
+ ��膩��� 87 (unless (eobp)
+ ��膩��� 88 (forward-char 1)
32923
+ ��膩��� 89 (looking-at (format "^\\(%s\\)\\([^>]\\)" (or quote " ?"))))))
31717
+ ��膩��� 90 (save-excursion
+ ��膩��� 91 (replace-match (if (string= (match-string 2) " ")
+ ��膩��� 92 "" "\\2")))
+ ��膩��� 93 (backward-delete-char -1)
+ ��膩��� 94 (end-of-line))
32923
+ ��膩��� 95 (unless sig
+ ��膩��� 96 (let ((fill-prefix (when quote (concat quote " "))))
+ ��膩��� 97 (fill-region (fill-flowed-point-at-bol)
+ ��膩��� 98 (fill-flowed-point-at-eol)
+ ��膩��� 99 'left 'nosqueeze))))))))
31717
+ ��膩��� 100
+ ��膩��� 101 (provide 'flow-fill)
+ ��膩��� 102
+ ��膩��� 103 ;;; flow-fill.el ends here