Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

fetch async

  • Loading branch information...
commit 05f4800c4e311ed2fcfc1511415fd81de3145290 1 parent 321f7db
Rüdiger Sonderfeld authored November 30, 2009

Showing 1 changed file with 33 additions and 24 deletions. Show diff stats Hide diff stats

  1. 57  codepad.el
57  codepad.el
@@ -232,32 +232,41 @@ optional argument is the BUFFER-NAME where to write."
232 232
          (buffer-name (or buffer-name (format "*codepad %s*" just-id)))
233 233
          (url (concat +codepad-url+ "/" just-id "/raw"))
234 234
          (buffer (get-buffer buffer-name)))
235  
-    (unless (bufferp buffer)
236  
-      (message "Fetching %s from Codepad" just-id)
237  
-      (setq buffer (url-retrieve-synchronously url))
238  
-      (with-current-buffer buffer
239  
-        (rename-buffer buffer-name t)
  235
+    (if (bufferp buffer)
  236
+        (pop-to-buffer buffer)
240 237
 
241  
-        ;; set codepad-id to the id
242  
-        (make-local-variable 'codepad-id)
243  
-        (setq codepad-id just-id)
  238
+        (message "Fetching %s from Codepad" just-id)
  239
+        (url-retrieve url
  240
+         (lambda (status buffer-name just-id)
  241
+           (let ((err (plist-get status :error)))
  242
+             (when err
  243
+               (signal (car err) (cdr err))))
  244
+           (rename-buffer buffer-name t)
  245
+           
  246
+           ;; set codepad-id to the id
  247
+           (make-local-variable 'codepad-id)
  248
+           (setq codepad-id just-id)
244 249
 
245  
-        (goto-char (point-min))
246  
-        (re-search-forward "\n\n") ; Find end of Headers
247  
-        (let ((header-end (point)))
248  
-          (goto-char (point-min))
249  
-          ;; Determine and set mode
250  
-          (when (and codepad-autoset-mode
251  
-                     url-http-content-type
252  
-                     (string-match "text/x-\\([^;[:space:]]*\\)" url-http-content-type))
253  
-            (let ((mode (cdr (assoc (match-string 1 url-http-content-type)
254  
-                                    +codepad-mime-to-mode+))))
255  
-              (when mode
256  
-                (funcall mode))))
257  
-          ;; Delete Headers
258  
-          (delete-region (point-min) header-end)
259  
-          (set-buffer-modified-p nil))))
260  
-    (pop-to-buffer buffer)))
  250
+           (goto-char (point-min))
  251
+           (re-search-forward "\n\n") ; Find end of Headers
  252
+           (let ((header-end (point)))
  253
+             (goto-char (point-min))
  254
+             ;; Determine and set mode
  255
+             (when (and codepad-autoset-mode
  256
+                        url-http-content-type
  257
+                        (string-match "text/x-\\([^;[:space:]]*\\)"
  258
+                                      url-http-content-type))
  259
+               (let ((mode
  260
+                      (cdr (assoc
  261
+                            (match-string 1 url-http-content-type)
  262
+                            +codepad-mime-to-mode+))))
  263
+                 (when mode
  264
+                   (funcall mode))))
  265
+             ;; Delete Headers
  266
+             (delete-region (point-min) header-end)
  267
+             (set-buffer-modified-p nil)
  268
+             (pop-to-buffer (current-buffer))))
  269
+         (list buffer-name just-id)))))
261 270
 
262 271
 (provide 'codepad)
263 272
 ;;; codepad.el ends here

0 notes on commit 05f4800

Please sign in to comment.
Something went wrong with that request. Please try again.