From: Juanma Barranquero <lekktu@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 16733@debbugs.gnu.org
Subject: bug#16733: messed up unicode chars in package description
Date: Sat, 22 Mar 2014 02:11:51 +0100 [thread overview]
Message-ID: <CAAeL0STgLMxEF3gQdWYNwi6T+9ik00TDfE8nkM1-+LPLw+hYMg@mail.gmail.com> (raw)
In-Reply-To: <CAAeL0SSZgPFZcK_HaszJ28KXQpY7YDZaUf3U=YAJRcjWvcgMUQ@mail.gmail.com>
A possible fix for trunk, not the release branch.
Basically, the idea is to move most functionality from
url-insert-file-contents to a new url-insert-file-contents-internal,
which has an additional arg, a check function (possibly nil). That
function is called with the same parameters that
url-insert-file-contents plus the url buffer (with response codes,
etc.) returned by url-retrieve-synchronously. The original u-i-f-c
turns into a wrapper for u-i-f-c-internal, and
package--with-work-buffer can call u-i-f-c-internal and leverage
package-handle-response to check for errors.
(If we can assume that package-handle-response isn't used outside
package.el, a further simplification is possible.)
J
=== modified file 'lisp/emacs-lisp/package.el'
--- lisp/emacs-lisp/package.el 2014-03-21 06:06:52 +0000
+++ lisp/emacs-lisp/package.el 2014-03-22 00:48:26 +0000
@@ -770,24 +770,20 @@
and evaluates BODY while that buffer is current. This work
buffer is killed afterwards. Return the last value in BODY."
(declare (indent 2) (debug t))
- `(let* ((http (string-match "\\`https?:" ,location))
- (buffer
- (if http
- (url-retrieve-synchronously (concat ,location ,file))
- (generate-new-buffer "*package work buffer*"))))
- (prog1
- (with-current-buffer buffer
- (if http
- (progn (package-handle-response)
- (re-search-forward "^$" nil 'move)
- (forward-char)
- (delete-region (point-min) (point)))
- (unless (file-name-absolute-p ,location)
- (error "Archive location %s is not an absolute file name"
- ,location))
- (insert-file-contents (expand-file-name ,file ,location)))
- ,@body)
- (kill-buffer buffer))))
+ `(with-temp-buffer
+ (if (string-match-p "\\`https?:" ,location)
+ (progn
+ (require 'url-handlers)
+ (url-insert-file-contents-internal
+ (lambda (buffer &rest _)
+ (with-current-buffer buffer (package-handle-response)))
+ (concat ,location ,file))
+ (goto-char (point-min)))
+ (unless (file-name-absolute-p ,location)
+ (error "Archive location %s is not an absolute file name"
+ ,location))
+ (insert-file-contents (expand-file-name ,file ,location)))
+ ,@body))
(defun package-handle-response ()
"Handle the response from a `url-retrieve-synchronously' call.
@@ -1272,7 +1268,7 @@
(car archive)))))
;; Read the retrieved buffer to make sure it is valid (e.g. it
;; may fetch a URL redirect page).
- (when (listp (read buffer))
+ (when (listp (read (current-buffer)))
(make-directory dir t)
(setq buffer-file-name (expand-file-name file dir))
(let ((version-control 'never)
@@ -1531,8 +1527,7 @@
(setq readme-string (buffer-string))
t))
(error nil))
- (let ((coding (detect-coding-string readme-string t)))
- (insert (decode-coding-string readme-string coding t))))
+ (insert readme-string))
((file-readable-p readme)
(insert-file-contents readme)
(goto-char (point-max))))))))
=== modified file 'lisp/url/url-handlers.el'
--- lisp/url/url-handlers.el 2014-01-01 07:43:34 +0000
+++ lisp/url/url-handlers.el 2014-03-22 00:53:21 +0000
@@ -290,11 +290,12 @@
(insert data))
(list (length data) charset)))
-;;;###autoload
-(defun url-insert-file-contents (url &optional visit beg end replace)
+(defun url-insert-file-contents-internal (check url &optional visit
beg end replace)
(let ((buffer (url-retrieve-synchronously url)))
- (if (not buffer)
- (error "Opening input file: No such file or directory, %s" url))
+ (when check
+ (unwind-protect
+ (funcall check buffer url visit beg end replace)
+ (when buffer (kill-buffer))))
(if visit (setq buffer-file-name url))
(save-excursion
(let* ((start (point))
@@ -308,6 +309,14 @@
;; usual heuristic/rules that we apply to files.
(decode-coding-inserted-region start (point) url visit beg
end replace))
(list url (car size-and-charset))))))
+
+;;;###autoload
+(defun url-insert-file-contents (url &optional visit beg end replace)
+ (url-insert-file-contents-internal
+ (lambda (buffer url &rest _ignore)
+ (unless buffer
+ (error "Opening input file: No such file or directory, %s" url)))
+ url visit beg end replace))
(put 'insert-file-contents 'url-file-handlers 'url-insert-file-contents)
(defun url-file-name-completion (url directory &optional predicate)
next prev parent reply other threads:[~2014-03-22 1:11 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-13 1:47 bug#16733: messed up unicode chars in package description Glenn Morris
2014-03-19 1:34 ` Juanma Barranquero
2014-03-19 6:26 ` Glenn Morris
2014-03-19 10:19 ` Juanma Barranquero
2014-03-19 15:53 ` Glenn Morris
2014-03-19 16:08 ` Juanma Barranquero
2014-03-19 16:16 ` Glenn Morris
2014-03-19 16:24 ` Juanma Barranquero
2014-03-19 17:11 ` Eli Zaretskii
2014-03-19 17:43 ` Juanma Barranquero
2014-03-19 18:05 ` Glenn Morris
2014-03-19 18:33 ` Juanma Barranquero
2014-03-20 5:12 ` Juanma Barranquero
2014-03-20 16:02 ` Glenn Morris
2014-03-20 16:30 ` Juanma Barranquero
2014-03-20 16:21 ` Eli Zaretskii
2014-03-20 17:26 ` Juanma Barranquero
2014-03-22 1:11 ` Juanma Barranquero [this message]
2014-03-22 1:18 ` Juanma Barranquero
2014-03-22 1:33 ` Juanma Barranquero
2014-03-22 2:54 ` Stefan Monnier
2014-03-22 3:27 ` Juanma Barranquero
2014-03-22 14:33 ` Stefan
2014-03-22 14:43 ` Juanma Barranquero
2014-03-22 15:55 ` Stefan
2014-03-22 16:46 ` Juanma Barranquero
2014-03-22 18:53 ` Stefan
2014-03-22 19:05 ` Juanma Barranquero
2014-03-23 22:24 ` Stefan
2014-03-25 3:04 ` Juanma Barranquero
2014-03-25 3:35 ` Stefan Monnier
2014-03-25 9:54 ` Juanma Barranquero
2014-03-25 13:21 ` Stefan Monnier
2014-03-26 15:24 ` Juanma Barranquero
2014-03-22 7:25 ` Eli Zaretskii
2014-03-22 12:20 ` Juanma Barranquero
2014-03-22 14:31 ` Stefan
2014-03-22 14:39 ` Juanma Barranquero
2014-03-22 15:02 ` Eli Zaretskii
2014-03-22 15:07 ` Juanma Barranquero
2014-03-22 15:09 ` Eli Zaretskii
2014-03-22 15:11 ` Juanma Barranquero
2014-03-19 19:00 ` Stefan
2014-03-19 19:42 ` Glenn Morris
2014-03-19 20:44 ` Juanma Barranquero
2014-03-19 17:08 ` Eli Zaretskii
2014-03-19 17:09 ` Juanma Barranquero
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAAeL0STgLMxEF3gQdWYNwi6T+9ik00TDfE8nkM1-+LPLw+hYMg@mail.gmail.com \
--to=lekktu@gmail.com \
--cc=16733@debbugs.gnu.org \
--cc=eliz@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.