Synch to No Gnus 200506270911.
[elisp/gnus.git-] / lisp / gnus-art.el
index f58c44e..d54d545 100644 (file)
@@ -63,6 +63,7 @@
 (autoload 'gnus-msg-mail "gnus-msg" nil t)
 (autoload 'gnus-button-mailto "gnus-msg")
 (autoload 'gnus-button-reply "gnus-msg" nil t)
+(autoload 'parse-time-string "parse-time" nil nil)
 (autoload 'ansi-color-apply-on-region "ansi-color")
 
 (defgroup gnus-article nil
@@ -277,9 +278,6 @@ This can also be a list of the above values."
       "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | ee -"))
    ((gnus-image-type-available-p 'pbm)
     'gnus-display-x-face-in-from)
-   ((and window-system
-        (module-installed-p 'x-face-mule))
-    'x-face-mule-gnus-article-display-x-face)
    (t
     "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | \
 display -"))
@@ -287,19 +285,14 @@ display -"))
 If it is a string, the command will be executed in a sub-shell
 asynchronously.         The compressed face will be piped to this command."
   :type `(choice
-         ,@(let ((x-face-mule (if (featurep 'xemacs)
-                                  nil
-                                (module-installed-p 'x-face-mule))))
-             (delq nil
-                   (list
-                    'string
-                    (if (or (gnus-image-type-available-p 'xface)
-                            (gnus-image-type-available-p 'pbm))
-                        '(function-item gnus-display-x-face-in-from))
-                    (if x-face-mule
-                        '(function-item
-                          x-face-mule-gnus-article-display-x-face))
-                    'function))))
+         :format "%{%t%}:\n%[Value Menu%] %v"
+         ,@(delq nil
+                 (list
+                  'string
+                  (if (or (gnus-image-type-available-p 'xface)
+                          (gnus-image-type-available-p 'pbm))
+                      '(function-item gnus-display-x-face-in-from))
+                  'function)))
   :version "21.1"
   :group 'gnus-picon
   :group 'gnus-article-washing)
@@ -404,7 +397,13 @@ advertisements.  For example:
                      (or (nth 4 spec) 3)
                      (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
              types))
-     '(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
+     '(;; I've never seen anyone use this strikethru convention whereas I've
+       ;; several times seen it triggered by normal text.  --Stef
+       ;; Miles suggests that this form is sometimes used but for italics,
+       ;; so maybe we should map it to `italic'.
+       ;; ("\\(\\s-\\|^\\)\\(-\\(\\(\\w\\|-[^-]\\)+\\)-\\)\\(\\s-\\|[?!.,;]\\)"
+       ;; 2 3 gnus-emphasis-strikethru)
+       ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
        2 3 gnus-emphasis-underline))))
   "*Alist that says how to fontify certain phrases.
 Each item looks like this:
@@ -516,9 +515,6 @@ be fed to `format-time-string'."
   :link '(custom-manual "(gnus)Article Date")
   :group 'gnus-article-washing)
 
-(eval-and-compile
-  (autoload 'mail-extract-address-components "mail-extr"))
-
 (defcustom gnus-save-all-headers t
   "*If non-nil, don't remove any headers before saving."
   :group 'gnus-article-saving
@@ -702,21 +698,23 @@ above them."
   :type 'face
   :group 'gnus-article-buttons)
 
-(defcustom gnus-signature-face 'gnus-signature-face
+(defcustom gnus-signature-face 'gnus-signature
   "Face used for highlighting a signature in the article buffer.
-Obsolete; use the face `gnus-signature-face' for customizations instead."
+Obsolete; use the face `gnus-signature' for customizations instead."
   :type 'face
   :group 'gnus-article-highlight
   :group 'gnus-article-signature)
 
-(defface gnus-signature-face
+(defface gnus-signature
   '((t
      (:italic t)))
   "Face used for highlighting a signature in the article buffer."
   :group 'gnus-article-highlight
   :group 'gnus-article-signature)
+;; backward-compatibility alias
+(put 'gnus-signature-face 'face-alias 'gnus-signature)
 
-(defface gnus-header-from-face
+(defface gnus-header-from
   '((((class color)
       (background dark))
      (:foreground "spring green"))
@@ -728,8 +726,10 @@ Obsolete; use the face `gnus-signature-face' for customizations instead."
   "Face used for displaying from headers."
   :group 'gnus-article-headers
   :group 'gnus-article-highlight)
+;; backward-compatibility alias
+(put 'gnus-header-from-face 'face-alias 'gnus-header-from)
 
-(defface gnus-header-subject-face
+(defface gnus-header-subject
   '((((class color)
       (background dark))
      (:foreground "SeaGreen3"))
@@ -741,8 +741,10 @@ Obsolete; use the face `gnus-signature-face' for customizations instead."
   "Face used for displaying subject headers."
   :group 'gnus-article-headers
   :group 'gnus-article-highlight)
+;; backward-compatibility alias
+(put 'gnus-header-subject-face 'face-alias 'gnus-header-subject)
 
-(defface gnus-header-newsgroups-face
+(defface gnus-header-newsgroups
   '((((class color)
       (background dark))
      (:foreground "yellow" :italic t))
@@ -756,8 +758,10 @@ In the default setup this face is only used for crossposted
 articles."
   :group 'gnus-article-headers
   :group 'gnus-article-highlight)
+;; backward-compatibility alias
+(put 'gnus-header-newsgroups-face 'face-alias 'gnus-header-newsgroups)
 
-(defface gnus-header-name-face
+(defface gnus-header-name
   '((((class color)
       (background dark))
      (:foreground "SeaGreen"))
@@ -769,8 +773,10 @@ articles."
   "Face used for displaying header names."
   :group 'gnus-article-headers
   :group 'gnus-article-highlight)
+;; backward-compatibility alias
+(put 'gnus-header-name-face 'face-alias 'gnus-header-name)
 
-(defface gnus-header-content-face
+(defface gnus-header-content
   '((((class color)
       (background dark))
      (:foreground "forest green" :italic t))
@@ -782,12 +788,14 @@ articles."
   "Face used for displaying header content."
   :group 'gnus-article-headers
   :group 'gnus-article-highlight)
+;; backward-compatibility alias
+(put 'gnus-header-content-face 'face-alias 'gnus-header-content)
 
 (defcustom gnus-header-face-alist
-  '(("From" nil gnus-header-from-face)
-    ("Subject" nil gnus-header-subject-face)
-    ("Newsgroups:.*," nil gnus-header-newsgroups-face)
-    ("" gnus-header-name-face gnus-header-content-face))
+  '(("From" nil gnus-header-from)
+    ("Subject" nil gnus-header-subject)
+    ("Newsgroups:.*," nil gnus-header-newsgroups)
+    ("" gnus-header-name gnus-header-content))
   "*Controls highlighting of article headers.
 
 An alist of the form (HEADER NAME CONTENT).
@@ -1292,9 +1300,7 @@ See Info node `(gnus)Customizing Articles' for details."
 
 (defcustom gnus-treat-display-x-face
   (and (not noninteractive)
-       (or (eq gnus-article-x-face-command
-              'x-face-mule-gnus-article-display-x-face)
-          (and (fboundp 'image-type-available-p)
+       (or (and (fboundp 'image-type-available-p)
                (image-type-available-p 'xbm)
                (string-match "^0x" (shell-command-to-string "uncompface"))
                (executable-find "icontopbm"))
@@ -2353,10 +2359,11 @@ unfolded."
                   ;; The command is a string, so we interpret the command
                   ;; as a, well, command, and fork it off.
                   (let ((process-connection-type nil))
-                    (process-kill-without-query
+                    (gnus-set-process-query-on-exit-flag
                      (start-process
                       "article-x-face" nil shell-file-name
-                      shell-command-switch gnus-article-x-face-command))
+                      shell-command-switch gnus-article-x-face-command)
+                     nil)
                     (with-temp-buffer
                       (insert face)
                       (process-send-region "article-x-face"
@@ -3006,81 +3013,74 @@ lines forward."
          (forward-line 1)
        (setq ended t)))))
 
-(defun article-date-ut (&optional type highlight header)
+(defun article-date-ut (&optional type highlight)
   "Convert DATE date to universal time in the current article.
 If TYPE is `local', convert to local time; if it is `lapsed', output
 how much time has lapsed since DATE.  For `lapsed', the value of
 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
 should replace the \"Date:\" one, or should be added below it."
   (interactive (list 'ut t))
-  (let* ((header (or header
-                    (and (eq 1 (point-min))
-                         (mail-header-date (save-excursion
-                                             (set-buffer gnus-summary-buffer)
-                                             gnus-current-headers)))
-                    (message-fetch-field "date")
-                    ""))
-        (date (if (vectorp header) (mail-header-date header)
-                header))
+  (let* ((tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
+        (date-regexp (cond ((not gnus-article-date-lapsed-new-header)
+                            tdate-regexp)
+                           ((eq type 'lapsed)
+                            "^X-Sent:[ \t]")
+                           (article-lapsed-timer
+                            "^Date:[ \t]")
+                           (t
+                            tdate-regexp)))
+        (case-fold-search t)
+        (inhibit-read-only t)
         (inhibit-point-motion-hooks t)
-        bface eface date-pos)
-    (when (and date (not (string= date "")))
-      (save-excursion
-       (save-restriction
-         (article-narrow-to-head)
-         (when (or (and (eq type 'lapsed)
-                        gnus-article-date-lapsed-new-header
-                        ;; Attempt to get the face of X-Sent first.
-                        (re-search-forward "^X-Sent:[ \t]" nil t))
-                   (re-search-forward "^Date:[ \t]" nil t)
-                   ;; If Date is missing, try again for X-Sent.
-                   (re-search-forward "^X-Sent:[ \t]" nil t))
+        pos date bface eface)
+    (save-excursion
+      (save-restriction
+       (widen)
+       (goto-char (point-min))
+       (while (or (setq date (get-text-property (setq pos (point))
+                                                'original-date))
+                  (when (setq pos (next-single-property-change
+                                   (point) 'original-date))
+                    (setq date (get-text-property pos 'original-date))
+                    t))
+         (narrow-to-region pos (or (text-property-any pos (point-max)
+                                                      'original-date nil)
+                                   (point-max)))
+         (goto-char (point-min))
+         (when (re-search-forward tdate-regexp nil t)
            (setq bface (get-text-property (point-at-bol) 'face)
-                 date (or (get-text-property (point-at-bol)
-                                             'original-date)
-                          date)
-                 eface (get-text-property (1- (point-at-eol))
-                                          'face)))
-         (let ((inhibit-read-only t))
-           ;; Delete any old X-Sent headers.
-           (when (setq date-pos
-                       (text-property-any (point-min) (point-max)
-                                          'article-date-lapsed t))
-             (goto-char (setq date-pos (set-marker (make-marker) date-pos)))
-             (delete-region (match-beginning 0)
-                            (progn (forward-line 1) (point))))
-           (goto-char (point-min))
-           ;; Delete any old Date headers.
-           (while (re-search-forward "^Date:[ \t]" nil t)
-             (unless date-pos
-               (setq date-pos (match-beginning 0)))
-             (unless (and (eq type 'lapsed)
-                          gnus-article-date-lapsed-new-header)
-               (delete-region (match-beginning 0)
-                              (progn (message-next-header) (point)))))
-           (if date-pos
-               (progn
-                 (goto-char date-pos)
-                 (unless (bolp)
-                   ;; Possibly, Date has been deleted.
-                   (insert "\n"))
-                 (when (and (eq type 'lapsed)
-                            gnus-article-date-lapsed-new-header
-                            (looking-at "Date:"))
-                   (forward-line 1)))
-             (goto-char (point-min)))
-           (insert (article-make-date-line date type))
-           (when (eq type 'lapsed)
-             (put-text-property (point-at-bol) (point)
-                                'article-date-lapsed t))
+                 eface (get-text-property (1- (point-at-eol)) 'face)))
+         (goto-char (point-min))
+         (setq pos nil)
+         ;; Delete any old Date headers.
+         (while (re-search-forward date-regexp nil t)
+           (if pos
+               (delete-region (point-at-bol) (progn
+                                               (gnus-article-forward-header)
+                                               (point)))
+             (delete-region (point-at-bol) (progn
+                                             (gnus-article-forward-header)
+                                             (forward-char -1)
+                                             (point)))
+             (setq pos (point))))
+         (when (and (not pos)
+                    (re-search-forward tdate-regexp nil t))
+           (forward-line 1))
+         (gnus-goto-char pos)
+         (insert (article-make-date-line date (or type 'ut)))
+         (unless pos
            (insert "\n")
-           (forward-line -1)
-           ;; Do highlighting.
-           (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
-             (add-text-properties (match-beginning 1) (1+ (match-end 1))
-                                  (list 'original-date date 'face bface))
-             (put-text-property (match-beginning 2) (match-end 2)
-                                'face eface))))))))
+           (forward-line -1))
+         ;; Do highlighting.
+         (beginning-of-line)
+         (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
+           (put-text-property (match-beginning 1) (1+ (match-end 1))
+                              'face bface)
+           (put-text-property (match-beginning 2) (match-end 2)
+                              'face eface))
+         (put-text-property (point-min) (1- (point-max)) 'original-date date)
+         (goto-char (point-max))
+         (widen))))))
 
 (defun article-make-date-line (date type)
   "Return a DATE line of TYPE."
@@ -3221,20 +3221,24 @@ function and want to see what the date was before converting."
 
 (defun article-update-date-lapsed ()
   "Function to be run from a timer to update the lapsed time line."
-  (let (deactivate-mark)
-    (save-excursion
-      (ignore-errors
-       (walk-windows
-        (lambda (w)
-          (set-buffer (window-buffer w))
-          (when (eq major-mode 'gnus-article-mode)
-            (let ((mark (point-marker)))
-              (goto-char (point-min))
-              (when (re-search-forward "^X-Sent:" nil t)
-                (article-date-lapsed t))
-              (goto-char (marker-position mark))
-              (move-marker mark nil))))
-        nil 'visible)))))
+  (save-match-data
+    (let (deactivate-mark)
+      (save-excursion
+       (ignore-errors
+        (walk-windows
+         (lambda (w)
+           (set-buffer (window-buffer w))
+           (when (or (and (eq major-mode 'mime-view-mode)
+                          (eq (mime-preview-original-major-mode)
+                              'gnus-original-article-mode))
+                     (eq major-mode 'gnus-article-mode))
+             (let ((mark (point-marker)))
+               (goto-char (point-min))
+               (when (re-search-forward "^X-Sent:" nil t)
+                 (article-date-lapsed t))
+               (goto-char (marker-position mark))
+               (move-marker mark nil))))
+         nil 'visible))))))
 
 (defun gnus-start-date-timer (&optional n)
   "Start a timer to update the X-Sent header in the article buffers.
@@ -3265,6 +3269,27 @@ This format is defined by the `gnus-article-time-format' variable."
   (interactive (list t))
   (article-date-ut 'iso8601 highlight))
 
+(defmacro gnus-article-save-original-date (&rest forms)
+  "Save the original date as a text property and evaluate FORMS."
+  `(let* ((case-fold-search t)
+         (start (progn
+                  (goto-char (point-min))
+                  (when (and (re-search-forward "^date:[\t\n ]+" nil t)
+                             (not (bolp)))
+                    (match-end 0))))
+         (date (when (and start
+                          (re-search-forward "[\t ]*\n\\(?:[^\t ]\\|\\'\\)"
+                                             nil t))
+                 (buffer-substring-no-properties start
+                                                 (match-beginning 0)))))
+     (goto-char (point-max))
+     (skip-chars-backward "\n")
+     (put-text-property (point-min) (point) 'original-date date)
+     ,@forms
+     (goto-char (point-max))
+     (skip-chars-backward "\n")
+     (put-text-property (point-min) (point) 'original-date date)))
+
 ;; (defun article-show-all ()
 ;;   "Show all hidden text in the article buffer."
 ;;   (interactive)
@@ -3914,6 +3939,7 @@ commands:
 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
 \\[gnus-info-find-node]\t Go to the Gnus info node"
   (interactive)
+  (kill-all-local-variables)
   (gnus-simplify-mode-line)
   (setq mode-name "Article")
   (setq major-mode 'gnus-article-mode)
@@ -3938,13 +3964,13 @@ commands:
   (make-local-variable 'gnus-article-charset)
   (make-local-variable 'gnus-article-ignored-charsets)
   ;; Prevent recent Emacsen from displaying non-break space as "\ ".
-  (set (make-local-variable 'show-nonbreak-escape) nil)
+  (set (make-local-variable 'nobreak-char-display) nil)
   (gnus-set-default-directory)
   (buffer-disable-undo)
   (setq buffer-read-only t
        show-trailing-whitespace nil)
   (set-syntax-table gnus-article-mode-syntax-table)
-  (gnus-run-hooks 'gnus-article-mode-hook))
+  (gnus-run-mode-hooks 'gnus-article-mode-hook))
 
 (defun gnus-article-setup-buffer ()
   "Initialize the article buffer."
@@ -4203,7 +4229,7 @@ If ALL-HEADERS is non-nil, no headers are hidden."
                        (if (search-forward "\n\n" nil t)
                            (point)
                          (point-max)))
-      (gnus-treat-article 'head)
+      (gnus-article-save-original-date (gnus-treat-article 'head))
       (put-text-property (point-min) (point-max) 'article-treated-header t)
       (goto-char (point-max)))
     (while (and (not (eobp)) entity)
@@ -4298,7 +4324,7 @@ If ALL-HEADERS is non-nil, no headers are hidden."
                          (if (search-forward "\n\n" nil t)
                              (point)
                            (point-max)))
-       (gnus-treat-article 'head)
+       (gnus-article-save-original-date (gnus-treat-article 'head))
        (put-text-property (point-min) (point-max) 'article-treated-header t)
        (goto-char (point-max))
        (widen)
@@ -4424,6 +4450,7 @@ This function is exclusively used by `gnus-mime-save-part-and-strip'
 and `gnus-mime-delete-part', and not provided at run-time normally."
     (gnus-article-edit-article
      `(lambda ()
+       (buffer-disable-undo)
        (erase-buffer)
        (let ((mail-parse-charset (or gnus-article-charset
                                      ',gnus-newsgroup-charset))
@@ -4735,7 +4762,7 @@ Compressed files like .gz and .bz2 are decompressed."
                 (and charset
                      (setq coding-system
                            (mm-charset-to-coding-system charset))
-                     (not (eq charset 'ascii))))
+                     (not (eq coding-system 'ascii))))
             (mm-decode-coding-string contents coding-system)
           (mm-string-to-multibyte contents)))
        (goto-char b)))))
@@ -5018,7 +5045,7 @@ N is the numerical prefix."
          (set-window-point window point)))
       (let ((handles ihandles)
            (inhibit-read-only t)
-           handle name type b e display)
+           handle)
        (cond (handles)
              ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
               (when gnus-article-emulate-mime
@@ -5057,7 +5084,8 @@ N is the numerical prefix."
            (save-restriction
              (article-goto-body)
              (narrow-to-region (point-min) (point))
-             (gnus-treat-article 'head))))))))
+             (gnus-article-save-original-date
+              (gnus-treat-article 'head)))))))))
 
 (defcustom gnus-mime-display-multipart-as-mixed nil
   "Display \"multipart\" parts as  \"multipart/mixed\".
@@ -5674,7 +5702,7 @@ not have a face in `gnus-article-boring-faces'."
              (when (eq win (selected-window))
                (setq new-sum-point (point)
                      new-sum-start (window-start win)
-                     new-sum-hscroll (window-hscroll win))
+                     new-sum-hscroll (window-hscroll win)))
              (when (eq in-buffer (current-buffer))
                (setq selected (gnus-summary-select-article))
                (set-buffer obuf)
@@ -5690,7 +5718,7 @@ not have a face in `gnus-article-boring-faces'."
                           new-sum-point)
                  (set-window-point win new-sum-point)
                  (set-window-start win new-sum-start)
-                 (set-window-hscroll win new-sum-hscroll)))))
+                 (set-window-hscroll win new-sum-hscroll))))
          (set-window-configuration owin)
          (ding))))))
 
@@ -6972,7 +7000,7 @@ do the highlighting.  See the documentation for those functions."
 (defun gnus-article-highlight-signature ()
   "Highlight the signature in an article.
 It does this by highlighting everything after
-`gnus-signature-separator' using `gnus-signature-face'."
+`gnus-signature-separator' using the face `gnus-signature'."
   (interactive)
   (when gnus-signature-face
     (gnus-with-article-buffer
@@ -7274,7 +7302,7 @@ specified by `gnus-button-alist'."
                                     (match-string 3 address)
                                   "nntp")))
        nil nil nil
-       (and (match-end 6) (list (string-to-int (match-string 6 address))))))))
+       (and (match-end 6) (list (string-to-number (match-string 6 address))))))))
 
 (defun gnus-url-parse-query-string (query &optional downcase)
   (let (retval pairs cur key val)
@@ -7557,7 +7585,7 @@ For example:
     current-prefix-arg))
   (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
     (unless func
-      (error (format "Can't find the encrypt protocol %s" protocol)))
+      (error "Can't find the encrypt protocol %s" protocol))
     (if (member gnus-newsgroup-name '("nndraft:delayed"
                                      "nndraft:drafts"
                                      "nndraft:queue"))