shr.el (shr-find-fill-point): Work better for kinsoku chars and apostrophes.
[gnus] / lisp / gnus-art.el
index 235aa87..8d8aaa0 100644 (file)
@@ -1590,7 +1590,7 @@ predicate.  See Info node `(gnus)Customizing Articles'."
   :link '(custom-manual "(gnus)Customizing Articles")
   :type gnus-article-treat-custom)
 
-(defcustom gnus-treat-fill-long-lines nil
+(defcustom gnus-treat-fill-long-lines '(typep "text/plain")
   "Fill long lines.
 Valid values are nil, t, `head', `first', `last', an integer or a
 predicate.  See Info node `(gnus)Customizing Articles'."
@@ -1636,6 +1636,12 @@ This requires GNU Libidn, and by default only enabled if it is found."
   :group 'gnus-article
   :type 'boolean)
 
+(defcustom gnus-inhibit-images nil
+  "Non-nil means inhibit displaying of images inline in the article body."
+  :version "24.1"
+  :group 'gnus-article
+  :type 'boolean)
+
 (defcustom gnus-blocked-images 'gnus-block-private-groups
   "Images that have URLs matching this regexp will be blocked.
 This can also be a function to be evaluated.  If so, it will be
@@ -1664,7 +1670,7 @@ regexp."
     (gnus-treat-highlight-signature gnus-article-highlight-signature)
     (gnus-treat-buttonize gnus-article-add-buttons)
     (gnus-treat-fill-article gnus-article-fill-cited-article)
-    (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
+    (gnus-treat-fill-long-lines gnus-article-fill-cited-long-lines)
     (gnus-treat-strip-cr gnus-article-remove-cr)
     (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
     (gnus-treat-date-ut gnus-article-date-ut)
@@ -2114,6 +2120,35 @@ try this wash."
   (interactive)
   (article-translate-strings gnus-article-dumbquotes-map))
 
+(defvar org-entities)
+
+(defun article-treat-non-ascii ()
+  "Translate many Unicode characters into their ASCII equivalents."
+  (interactive)
+  (require 'org-entities)
+  (let ((table (make-char-table (if (featurep 'xemacs) 'generic))))
+    (dolist (elem org-entities)
+      (when (and (listp elem)
+                (= (length (nth 6 elem)) 1))
+       (if (featurep 'xemacs)
+           (put-char-table (aref (nth 6 elem) 0) (nth 4 elem) table)
+         (set-char-table-range table (aref (nth 6 elem) 0) (nth 4 elem)))))
+    (save-excursion
+      (when (article-goto-body)
+       (let ((inhibit-read-only t)
+             replace props)
+         (while (not (eobp))
+           (if (not (setq replace (if (featurep 'xemacs)
+                                      (get-char-table (following-char) table)
+                                    (aref table (following-char)))))
+               (forward-char 1)
+             (if (prog1
+                     (setq props (text-properties-at (point)))
+                   (delete-char 1))
+                 (add-text-properties (point) (progn (insert replace) (point))
+                                      props)
+               (insert replace)))))))))
+
 (defun article-translate-characters (from to)
   "Translate all characters in the body of the article according to FROM and TO.
 FROM is a string of characters to translate from; to is a string of
@@ -2242,6 +2277,17 @@ unfolded."
     (dolist (elem gnus-article-image-alist)
       (gnus-delete-images (car elem)))))
 
+(defun gnus-article-show-images ()
+  "Show any images that are in the HTML-rendered article buffer.
+This only works if the article in question is HTML."
+  (interactive)
+  (gnus-with-article-buffer
+    (dolist (region (gnus-find-text-property-region (point-min) (point-max)
+                                                   'image-displayer))
+      (destructuring-bind (start end function) region
+       (funcall function (get-text-property start 'image-url)
+                start end)))))
+
 (defun gnus-article-treat-fold-newsgroups ()
   "Unfold folded message headers.
 Only the headers that fit into the current window width will be
@@ -4248,6 +4294,7 @@ If variable `gnus-use-long-file-name' is non-nil, it is
      article-date-lapsed
      article-emphasize
      article-treat-dumbquotes
+     article-treat-non-ascii
      article-normalize-headers
      ;;(article-show-all . gnus-article-show-all-headers)
      )))
@@ -5563,36 +5610,39 @@ all parts."
   "Go to MIME part N."
   (when gnus-break-pages
     (widen))
-  (let ((start (text-property-any (point-min) (point-max) 'gnus-part n))
-       part handle end next handles)
-    (when start
-      (goto-char start)
-      (unless (setq handle (get-text-property start 'gnus-data))
-       ;; Go to the displayed subpart, assuming this is multipart/alternative.
-       (setq part start
-             end (point-at-eol))
-       (while (and (not handle)
-                   part
-                   (< part end)
-                   (setq next (text-property-not-all part end
-                                                     'gnus-data nil)))
-         (setq part next
-               handle (get-text-property part 'gnus-data))
-         (push (cons handle part) handles)
-         (unless (mm-handle-displayed-p handle)
-           (setq handle nil
-                 part (text-property-any part end 'gnus-data nil))))
-       (unless handle
-         ;; No subpart is displayed, so we find preferred one.
-         (setq part
-               (cdr (assq (mm-preferred-alternative
-                           (nreverse (mapcar 'car handles)))
-                          handles)))))
-      (when gnus-break-pages
-       (gnus-narrow-to-page))
-      (if part
-         (goto-char (1+ part))
-       start))))
+  (prog1
+      (let ((start (text-property-any (point-min) (point-max) 'gnus-part n))
+           part handle end next handles)
+       (when start
+         (goto-char start)
+         (if (setq handle (get-text-property start 'gnus-data))
+             start
+           ;; Go to the displayed subpart, assuming this is
+           ;; multipart/alternative.
+           (setq part start
+                 end (point-at-eol))
+           (while (and (not handle)
+                       part
+                       (< part end)
+                       (setq next (text-property-not-all part end
+                                                         'gnus-data nil)))
+             (setq part next
+                   handle (get-text-property part 'gnus-data))
+             (push (cons handle part) handles)
+             (unless (mm-handle-displayed-p handle)
+               (setq handle nil
+                     part (text-property-any part end 'gnus-data nil))))
+           (unless handle
+             ;; No subpart is displayed, so we find preferred one.
+             (setq part
+                   (cdr (assq (mm-preferred-alternative
+                               (nreverse (mapcar 'car handles)))
+                              handles))))
+           (if part
+               (goto-char (1+ part))
+             start))))
+    (when gnus-break-pages
+      (gnus-narrow-to-page))))
 
 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
   (let ((gnus-tmp-name
@@ -5701,7 +5751,7 @@ all parts."
          (save-restriction
            (article-goto-body)
            (narrow-to-region (point) (point-max))
-           (gnus-treat-article nil 1 1)
+           (gnus-treat-article nil 1 1 "text/plain")
            (widen)))
        (unless ihandles
          ;; Highlight the headers.
@@ -5801,7 +5851,12 @@ If displaying \"text/html\" is discouraged \(see
        (while ignored
          (when (string-match (pop ignored) type)
            (throw 'ignored nil)))
-       (if (and (setq not-attachment
+       (if (and (not (and (if (gnus-buffer-live-p gnus-summary-buffer)
+                              (with-current-buffer gnus-summary-buffer
+                                gnus-inhibit-images)
+                            gnus-inhibit-images)
+                          (string-match "\\`image/" type)))
+                (setq not-attachment
                       (and (not (mm-inline-override-p handle))
                            (or (not (mm-handle-disposition handle))
                                (equal (car (mm-handle-disposition handle))
@@ -5989,7 +6044,7 @@ If displaying \"text/html\" is discouraged \(see
                  (gnus-treat-article
                   nil (length gnus-article-mime-handle-alist)
                   (gnus-article-mime-total-parts)
-                  (mm-handle-media-type handle))))))
+                  (mm-handle-media-type preferred))))))
          (goto-char (point-max))
          (setcdr begend (point-marker)))))
     (when ibegend
@@ -8091,6 +8146,7 @@ url is put as the `gnus-button-url' overlay property on the button."
 
 (defun gnus-url-mailto (url)
   ;; Send mail to someone
+  (setq url (replace-regexp-in-string "\n" " " url))
   (when (string-match "mailto:/*\\(.*\\)" url)
     (setq url (substring url (match-beginning 1) nil)))
   (let (to args subject func)
@@ -8100,8 +8156,7 @@ url is put as the `gnus-button-url' overlay property on the button."
                  (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
                      (concat "to=" (match-string 1 url) "&"
                              (match-string 2 url))
-                   (concat "to=" url)))
-               t)
+                   (concat "to=" url))))
          subject (cdr-safe (assoc "subject" args)))
     (gnus-msg-mail)
     (while args
@@ -8252,16 +8307,19 @@ For example:
 ;;; Treatment top-level handling.
 ;;;
 
-(defun gnus-treat-article (condition &optional part-number total-parts type)
-  (let ((length (- (point-max) (point-min)))
+(defvar gnus-inhibit-article-treatments nil)
+
+(defun gnus-treat-article (gnus-treat-condition
+                          &optional part-number total-parts gnus-treat-type)
+  (let ((gnus-treat-length (- (point-max) (point-min)))
        (alist gnus-treatment-function-alist)
        (article-goto-body-goes-to-point-min-p t)
        (treated-type
-        (or (not type)
+        (or (not gnus-treat-type)
             (catch 'found
               (let ((list gnus-article-treat-types))
                 (while list
-                  (when (string-match (pop list) type)
+                  (when (string-match (pop list) gnus-treat-type)
                     (throw 'found t)))))))
        (highlightp (gnus-visual-p 'article-highlight 'highlight))
        val elem)
@@ -8274,6 +8332,8 @@ For example:
              (symbol-value (car elem))))
       (when (and (or (consp val)
                     treated-type)
+                (or (not gnus-inhibit-article-treatments)
+                    (eq gnus-treat-condition 'head))
                 (gnus-treat-predicate val)
                 (or (not (get (car elem) 'highlight))
                     highlightp))
@@ -8283,16 +8343,16 @@ For example:
 ;; Dynamic variables.
 (defvar part-number)
 (defvar total-parts)
-(defvar type)
-(defvar condition)
-(defvar length)
+(defvar gnus-treat-type)
+(defvar gnus-treat-condition)
+(defvar gnus-treat-length)
 
 (defun gnus-treat-predicate (val)
   (cond
    ((null val)
     nil)
-   (condition
-    (eq condition val))
+   (gnus-treat-condition
+    (eq gnus-treat-condition val))
    ((and (listp val)
         (stringp (car val)))
     (apply 'gnus-or (mapcar `(lambda (s)
@@ -8308,7 +8368,7 @@ For example:
        ((eq pred 'not)
        (not (gnus-treat-predicate (car val))))
        ((eq pred 'typep)
-       (equal (car val) type))
+       (equal (car val) gnus-treat-type))
        (t
        (error "%S is not a valid predicate" pred)))))
    ((eq val t)
@@ -8320,7 +8380,7 @@ For example:
    ((eq val 'last)
     (eq part-number total-parts))
    ((numberp val)
-    (< length val))
+    (< gnus-treat-length val))
    (t
     (error "%S is not a valid value" val))))