*** empty log message ***
[gnus] / lisp / gnus-cite.el
index 79ff1f9..182e914 100644 (file)
@@ -17,8 +17,9 @@
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING.  If not, write to
-;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+;; along with GNU Emacs; see the file COPYING.  If not, write to the
+;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+;; Boston, MA 02111-1307, USA.
 
 ;;; Commentary:
 
 (require 'gnus)
 (require 'gnus-msg)
 (require 'gnus-ems)
+(eval-when-compile (require 'cl))
 
 (eval-and-compile
   (autoload 'gnus-article-add-button "gnus-vis"))
 
 ;;; Customization:
 
+(defvar gnus-cited-text-button-line-format "%(%{[...]%}%)\n"
+  "Format of cited text buttons.")
+
+(defvar gnus-cited-lines-visible nil
+  "The number of lines of hidden cited text to remain visible.")
+
 (defvar gnus-cite-parse-max-size 25000
   "Maximum article size (in bytes) where parsing citations is allowed.
 Set it to nil to parse all articles.")
@@ -134,6 +142,12 @@ The text matching the first grouping will be used as a button.")
 ;; PREFIX: Is the citation prefix of the attribution line(s), and
 ;; TAG: Is a SuperCite tag, if any.
 
+(defvar gnus-cited-text-button-line-format-alist 
+  `((?b beg ?d)
+    (?e end ?d)
+    (?l (- end beg) ?d)))
+(defvar gnus-cited-text-button-line-format-spec nil)
+
 ;;; Commands:
 
 (defun gnus-article-highlight-citation (&optional force)
@@ -207,17 +221,13 @@ Lines matching `gnus-cite-attribution-suffix' and perhaps
              skip (gnus-cite-find-prefix number))
        (gnus-cite-add-face number skip gnus-cite-attribution-face)))))
 
-(defun gnus-article-fill-cited-article (&optional force)
-  "Do word wrapping in the current article."
-  (interactive (list t))
+(defun gnus-dissect-cited-text ()
+  "Dissect the article buffer looking for cited text."
   (save-excursion
     (set-buffer gnus-article-buffer)
-    (gnus-cite-parse-maybe force)
-    (let ((buffer-read-only nil)
-         (alist gnus-cite-prefix-alist)
-         (inhibit-point-motion-hooks t)
-         prefix numbers number marks
-         (adaptive-fill-mode nil))
+    (gnus-cite-parse-maybe)
+    (let ((alist gnus-cite-prefix-alist)
+         prefix numbers number marks)
       ;; Loop through citation prefixes.
       (while alist
        (setq numbers (pop alist)
@@ -252,17 +262,26 @@ Lines matching `gnus-cite-attribution-suffix' and perhaps
                (setq omarks (cdr omarks)))
            (push (car omarks) marks))
          (setq omarks (cdr omarks)))
-       (push (car omarks) marks)
-       (setq marks (nreverse marks)))
+       (when (car omarks)
+         (push (car omarks) marks))
+       (nreverse marks)))))
+
+(defun gnus-article-fill-cited-article (&optional force)
+  "Do word wrapping in the current article."
+  (interactive (list t))
+  (save-excursion
+    (set-buffer gnus-article-buffer)
+    (let ((buffer-read-only nil)
+         (inhibit-point-motion-hooks t)
+         (marks (gnus-dissect-cited-text))
+         (adaptive-fill-mode nil))
       (save-restriction
        (while (cdr marks)
          (widen)
-         (narrow-to-region (car (car marks)) (car (cadr marks)))
-         (let ((adaptive-fill-regexp (concat "^" (regexp-quote
-                                                  (cdr (car marks)))
-                                             " *"))
-               (fill-prefix (cdr (car marks)))
-               )
+         (narrow-to-region (caar marks) (caadr marks))
+         (let ((adaptive-fill-regexp
+                (concat "^" (regexp-quote (cdar marks)) " *"))
+               (fill-prefix (cdar marks)))
            (fill-region (point-min) (point-max)))
          (set-marker (caar marks) nil)
          (setq marks (cdr marks)))
@@ -274,26 +293,54 @@ See the documentation for `gnus-article-highlight-citation'.
 If given a negative prefix, always show; if given a positive prefix,
 always hide."
   (interactive (list current-prefix-arg 'force))
+  (setq gnus-cited-text-button-line-format-spec 
+       (gnus-parse-format gnus-cited-text-button-line-format 
+                          gnus-cited-text-button-line-format-alist t))
   (unless (gnus-article-check-hidden-text 'cite arg)
     (save-excursion
       (set-buffer gnus-article-buffer)
-      (gnus-cite-parse-maybe force)
       (let ((buffer-read-only nil)
-           (alist gnus-cite-prefix-alist)
+           (marks (gnus-dissect-cited-text))
            (inhibit-point-motion-hooks t)
            (props (nconc (list 'gnus-type 'cite)
                          gnus-hidden-properties))
-           numbers number)
-       (while alist
-         (setq numbers (cdr (car alist))
-               alist (cdr alist))
-         (while numbers
-           (setq number (car numbers)
-                 numbers (cdr numbers))
-           (goto-line number)
-           (or (assq number gnus-cite-attribution-alist)
-               (add-text-properties 
-                (point) (progn (forward-line 1) (point)) props))))))))
+           beg end)
+       (while marks
+         (setq beg nil
+               end nil)
+         (while (and marks (string= (cdar marks) ""))
+           (setq marks (cdr marks)))
+         (when marks 
+           (setq beg (caar marks)))
+         (while (and marks (not (string= (cdar marks) "")))
+           (setq marks (cdr marks)))
+         (when marks
+           (setq end (caar marks)))
+         ;; Skip past lines we want to leave visible.
+         (when (and beg gnus-cited-lines-visible)
+           (goto-char beg)
+           (forward-line gnus-cited-lines-visible)
+           (if (> (point) end)
+               (setq beg nil)
+             (setq beg (point))))
+         (when (and beg end)
+           (add-text-properties beg end props)
+           (goto-char (1- beg))
+           (put-text-property beg end 'gnus-type 'cite)
+           (gnus-article-add-button
+            (point)
+            (progn (eval gnus-cited-text-button-line-format-spec) (point))
+            `gnus-article-toggle-cited-text (cons beg end))))))))
+
+(defun gnus-article-toggle-cited-text (region)
+  "Toggle hiding the text in REGION."
+  (let (buffer-read-only)
+    (funcall
+     (if (text-property-any
+         (car region) (1- (cdr region))
+         (car gnus-hidden-properties) (cadr gnus-hidden-properties))
+        'remove-text-properties 'add-text-properties)
+     (car region) (cdr region) gnus-hidden-properties)))
 
 (defun gnus-article-hide-citation-maybe (&optional arg force)
   "Toggle hiding of cited text that has an attribution line.
@@ -321,7 +368,7 @@ See also the documentation for `gnus-article-highlight-citation'."
        (re-search-backward gnus-signature-separator nil t)
        (setq total (count-lines start (point)))
        (while atts
-         (setq hiden (+ hiden (length (cdr (assoc (cdr (car atts))
+         (setq hiden (+ hiden (length (cdr (assoc (cdar atts)
                                                   gnus-cite-prefix-alist))))
                atts (cdr atts)))
        (if (or force
@@ -330,8 +377,7 @@ See also the documentation for `gnus-article-highlight-citation'."
            (progn
              (setq atts gnus-cite-attribution-alist)
              (while atts
-               (setq total (cdr (assoc (cdr (car atts)) 
-                                       gnus-cite-prefix-alist))
+               (setq total (cdr (assoc (cdar atts) gnus-cite-prefix-alist))
                      atts (cdr atts))
                (while total
                  (setq hiden (car total)
@@ -351,7 +397,7 @@ See also the documentation for `gnus-article-highlight-citation'."
     (let ((article (cdr gnus-article-current)))
       (unless (save-excursion
                (set-buffer gnus-summary-buffer)
-               (gnus-root-id (mail-header-id 
+               (gnus-root-id (mail-header-references
                               (gnus-summary-article-header article))))
        (gnus-article-hide-citation)))))
 
@@ -407,7 +453,7 @@ See also the documentation for `gnus-article-highlight-citation'."
        ;; Each prefix.
        (setq end (match-end 0)
              prefix (buffer-substring begin end))
-       (set-text-properties 0 (length prefix) nil prefix)
+       (gnus-set-text-properties 0 (length prefix) nil prefix)
        (setq entry (assoc prefix alist))
        (if entry 
            (setcdr entry (cons line (cdr entry)))