emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r101792: shr.el (shr-encode-url-chars


From: Katsumi Yamaoka
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r101792: shr.el (shr-encode-url-chars): New function.
Date: Tue, 05 Oct 2010 00:44:05 +0000
User-agent: Bazaar (2.0.3)

------------------------------------------------------------
revno: 101792
committer: Katsumi Yamaoka <address@hidden>
branch nick: trunk
timestamp: Tue 2010-10-05 00:44:05 +0000
message:
  shr.el (shr-encode-url-chars): New function.
modified:
  lisp/gnus/ChangeLog
  lisp/gnus/shr.el
=== modified file 'lisp/gnus/ChangeLog'
--- a/lisp/gnus/ChangeLog       2010-10-04 22:26:51 +0000
+++ b/lisp/gnus/ChangeLog       2010-10-05 00:44:05 +0000
@@ -1,3 +1,9 @@
+2010-10-05  Katsumi Yamaoka  <address@hidden>
+
+       * shr.el (shr-encode-url-chars): New function, that's an alias to
+       browse-url-url-encode-chars or a copy of it.
+       (shr-tag-img): Use it.
+
 2010-10-04  Lars Magne Ingebrigtsen  <address@hidden>
 
        * shr.el (shr-tag-blockquote): Ensure paragraph after quote, too.

=== modified file 'lisp/gnus/shr.el'
--- a/lisp/gnus/shr.el  2010-10-04 22:26:51 +0000
+++ b/lisp/gnus/shr.el  2010-10-05 00:44:05 +0000
@@ -191,6 +191,25 @@
        (copy-region-as-kill (point-min) (point-max))
        (message "Copied %s" url))))))
 
+(eval-and-compile
+  (defalias 'shr-encode-url-chars
+    ;; Neither Emacs 22 nor XEmacs provides this function.
+    (if (fboundp 'browse-url-url-encode-chars)
+       'browse-url-url-encode-chars
+      (lambda (text chars)
+       "URL-encode the chars in TEXT that match CHARS.
+CHARS is a regexp-like character alternative (e.g., \"[)$]\")."
+       (let ((encoded-text (copy-sequence text))
+             (s 0))
+         (while (setq s (string-match chars encoded-text s))
+           (setq encoded-text
+                 (replace-match (format "%%%x"
+                                        (string-to-char
+                                         (match-string 0 encoded-text)))
+                                t t encoded-text)
+                 s (1+ s)))
+         encoded-text)))))
+
 (defun shr-tag-img (cont)
   (when (and (> (current-column) 0)
             (not (eq shr-state 'image)))
@@ -204,7 +223,7 @@
        ((and shr-blocked-images
             (string-match shr-blocked-images url))
        (insert alt))
-       ((url-is-cached (browse-url-url-encode-chars url "[&)$ ]"))
+       ((url-is-cached (shr-encode-url-chars url "[&)$ ]"))
        (shr-put-image (shr-get-image-data url) (point) alt))
        (t
        (insert alt)


reply via email to

[Prev in Thread] Current Thread [Next in Thread]