Use image-url instead of gnus-image-url to unify the image url text properties.
[gnus] / lisp / shr.el
index bbb7ff1..876d7b1 100644 (file)
@@ -154,7 +154,7 @@ redirects somewhere else."
 (defun shr-browse-image ()
   "Browse the image under point."
   (interactive)
-  (let ((url (get-text-property (point) 'shr-image)))
+  (let ((url (get-text-property (point) 'image-url)))
     (if (not url)
        (message "No image under point")
       (message "Browsing %s..." url)
@@ -163,7 +163,7 @@ redirects somewhere else."
 (defun shr-insert-image ()
   "Insert the image under point into the buffer."
   (interactive)
-  (let ((url (get-text-property (point) 'shr-image)))
+  (let ((url (get-text-property (point) 'image-url)))
     (if (not url)
        (message "No image under point")
       (message "Inserting %s..." url)
@@ -181,7 +181,7 @@ redirects somewhere else."
            result))
     (dolist (sub dom)
       (if (stringp sub)
-         (push (cons :text sub) result)
+         (push (cons 'text sub) result)
        (push (shr-transform-dom sub) result)))
     (nreverse result)))
 
@@ -194,7 +194,7 @@ redirects somewhere else."
 (defun shr-generic (cont)
   (dolist (sub cont)
     (cond
-     ((eq (car sub) :text)
+     ((eq (car sub) 'text)
       (shr-insert (cdr sub)))
      ((listp (cdr sub))
       (shr-descend sub)))))
@@ -235,20 +235,23 @@ redirects somewhere else."
                                  (aref elem 0)))))
          (delete-char -1)))
       (insert elem)
-      (while (> (current-column) shr-width)
-       (unless (prog1
-                   (shr-find-fill-point)
-                 (when (eq (preceding-char) ? )
-                   (delete-char -1))
-                 (insert "\n"))
-         (put-text-property (1- (point)) (point) 'shr-break t)
-         ;; No space is needed at the beginning of a line.
-         (when (eq (following-char) ? )
-           (delete-char 1)))
-       (when (> shr-indentation 0)
-         (shr-indent))
-       (end-of-line))
-      (insert " "))
+      (let (found)
+       (while (and (> (current-column) shr-width)
+                   (progn
+                     (setq found (shr-find-fill-point))
+                     (not (eolp))))
+         (when (eq (preceding-char) ? )
+           (delete-char -1))
+         (insert "\n")
+         (unless found
+           (put-text-property (1- (point)) (point) 'shr-break t)
+           ;; No space is needed at the beginning of a line.
+           (when (eq (following-char) ? )
+             (delete-char 1)))
+         (when (> shr-indentation 0)
+           (shr-indent))
+         (end-of-line))
+       (insert " ")))
     (unless (string-match "[ \t\n]\\'" text)
       (delete-char -1)))))
 
@@ -286,7 +289,9 @@ redirects somewhere else."
                            (aref (char-category-set (following-char)) ?>)))
                  (backward-char 1))
              (while (and (>= (setq count (1- count)) 0)
-                         (aref (char-category-set (following-char)) ?>))
+                         (aref (char-category-set (following-char)) ?>)
+                         (aref fill-find-break-point-function-table
+                               (following-char)))
                (forward-char 1)))
            (when (eq (following-char) ? )
              (forward-char 1))
@@ -338,9 +343,13 @@ redirects somewhere else."
   "Browse the URL under point."
   (interactive)
   (let ((url (get-text-property (point) 'shr-url)))
-    (if (not url)
-       (message "No link under point")
-      (browse-url url))))
+    (cond
+     ((not url)
+      (message "No link under point"))
+     ((string-match "^mailto:" url)
+      (browse-url-mailto url))
+     (t
+      (browse-url url)))))
 
 (defun shr-save-contents (directory)
   "Save the contents from URL in a file."
@@ -409,6 +418,11 @@ redirects somewhere else."
                     image)))
       image)))
 
+;; url-cache-extract autoloads url-cache.
+(declare-function url-cache-create-filename "url-cache" (url))
+(autoload 'mm-disable-multibyte "mm-util")
+(autoload 'browse-url-mailto "browse-url")
+
 (defun shr-get-image-data (url)
   "Get image data for URL.
 Return a string with image data."
@@ -426,6 +440,8 @@ Return a string with image data."
   (apply #'shr-fontize-cont cont types)
   (shr-ensure-paragraph))
 
+(autoload 'widget-convert-button "wid-edit")
+
 (defun shr-urlify (start url)
   (widget-convert-button
    'url-link start (point)
@@ -524,7 +540,7 @@ Return a string with image data."
          (url (or url (cdr (assq :src cont)))))
       (let ((start (point-marker)))
        (when (zerop (length alt))
-         (setq alt "[img]"))
+         (setq alt "*"))
        (cond
         ((or (member (cdr (assq :height cont)) '("0" "1"))
              (member (cdr (assq :width cont)) '("0" "1")))
@@ -543,8 +559,8 @@ Return a string with image data."
                   (string-match shr-blocked-images url)))
          (setq shr-start (point))
          (let ((shr-state 'space))
-           (if (> (length alt) 8)
-               (shr-insert (substring alt 0 8))
+           (if (> (string-width alt) 8)
+               (shr-insert (truncate-string-to-width alt 8))
              (shr-insert alt))))
         ((url-is-cached (shr-encode-url url))
          (shr-put-image (shr-get-image-data url) alt))
@@ -556,7 +572,7 @@ Return a string with image data."
                          t))))
        (put-text-property start (point) 'keymap shr-map)
        (put-text-property start (point) 'shr-alt alt)
-       (put-text-property start (point) 'shr-image url)
+       (put-text-property start (point) 'image-url url)
        (put-text-property start (point) 'help-echo alt)
        (setq shr-state 'image)))))