aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Magne Ingebrigtsen2014-11-23 17:22:41 +0100
committerLars Magne Ingebrigtsen2014-11-23 17:22:41 +0100
commit6fd82d61a2b82e772e8cde0e04516f5c3ca98ed3 (patch)
tree299fc939e13075631b476eaa9b2853c37e6522c1
parent7f902e70b57f3a49ccfbcb52b0e438163b3d760c (diff)
downloademacs-6fd82d61a2b82e772e8cde0e04516f5c3ca98ed3.tar.gz
emacs-6fd82d61a2b82e772e8cde0e04516f5c3ca98ed3.zip
Switch to the *eww* buffer immediately to avoid doing it asynchronously
(eww): Pop to the *eww* buffer immediately after executing the `M-x eww' command to avoid having buffers pop up later. (eww-display-html): Don't pop the *eww* buffer. (eww-display-raw): Ditto. (eww-display-image): Ditto.
-rw-r--r--lisp/ChangeLog5
-rw-r--r--lisp/net/eww.el126
2 files changed, 74 insertions, 57 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index dd8f3cee186..f743575b8ec 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,6 +1,11 @@
12014-11-23 Lars Magne Ingebrigtsen <larsi@gnus.org> 12014-11-23 Lars Magne Ingebrigtsen <larsi@gnus.org>
2 2
3 * net/eww.el (eww-display-html): Decode the document-defined charset. 3 * net/eww.el (eww-display-html): Decode the document-defined charset.
4 (eww): Pop to the *eww* buffer immediately after executing the
5 `M-x eww' command to avoid having buffers pop up later.
6 (eww-display-html): Don't pop the *eww* buffer.
7 (eww-display-raw): Ditto.
8 (eww-display-image): Ditto.
4 9
52014-11-23 Ivan Shmakov <ivan@siamics.net> 102014-11-23 Ivan Shmakov <ivan@siamics.net>
6 11
diff --git a/lisp/net/eww.el b/lisp/net/eww.el
index ba21cc857af..b4d1486340f 100644
--- a/lisp/net/eww.el
+++ b/lisp/net/eww.el
@@ -253,10 +253,13 @@ word(s) will be searched for via `eww-search-prefix'."
253 (setq url (concat url "/")))) 253 (setq url (concat url "/"))))
254 (setq url (concat eww-search-prefix 254 (setq url (concat eww-search-prefix
255 (replace-regexp-in-string " " "+" url)))))) 255 (replace-regexp-in-string " " "+" url))))))
256 (unless (eq major-mode 'eww-mode)
257 (eww-setup-buffer)
258 (eww-update-header-line-format)
259 (let ((inhibit-read-only t))
260 (insert (format "Loading %s..." url))))
256 (url-retrieve url 'eww-render 261 (url-retrieve url 'eww-render
257 (list url nil 262 (list url nil (current-buffer))))
258 (and (eq major-mode 'eww-mode)
259 (current-buffer)))))
260 263
261;;;###autoload (defalias 'browse-web 'eww) 264;;;###autoload (defalias 'browse-web 'eww)
262 265
@@ -344,8 +347,10 @@ See the `eww-search-prefix' variable for the search engine used."
344 (start end &optional base-url)) 347 (start end &optional base-url))
345 348
346(defun eww-display-html (charset url &optional document point buffer encode) 349(defun eww-display-html (charset url &optional document point buffer encode)
347 (or (fboundp 'libxml-parse-html-region) 350 (unless (fboundp 'libxml-parse-html-region)
348 (error "This function requires Emacs to be compiled with libxml2")) 351 (error "This function requires Emacs to be compiled with libxml2"))
352 (unless (buffer-live-p buffer)
353 (error "Buffer %s doesn't exist" buffer))
349 ;; There should be a better way to abort loading images 354 ;; There should be a better way to abort loading images
350 ;; asynchronously. 355 ;; asynchronously.
351 (setq url-queue nil) 356 (setq url-queue nil)
@@ -362,41 +367,42 @@ See the `eww-search-prefix' variable for the search engine used."
362 (libxml-parse-html-region (point) (point-max)))))) 367 (libxml-parse-html-region (point) (point-max))))))
363 (source (and (null document) 368 (source (and (null document)
364 (buffer-substring (point) (point-max))))) 369 (buffer-substring (point) (point-max)))))
365 (eww-setup-buffer buffer) 370 (with-current-buffer buffer
366 (plist-put eww-data :source source) 371 (plist-put eww-data :source source)
367 (plist-put eww-data :dom document) 372 (plist-put eww-data :dom document)
368 (let ((inhibit-read-only t) 373 (let ((inhibit-read-only t)
369 (after-change-functions nil) 374 (after-change-functions nil)
370 (shr-target-id (url-target (url-generic-parse-url url))) 375 (shr-target-id (url-target (url-generic-parse-url url)))
371 (shr-external-rendering-functions 376 (shr-external-rendering-functions
372 '((title . eww-tag-title) 377 '((title . eww-tag-title)
373 (form . eww-tag-form) 378 (form . eww-tag-form)
374 (input . eww-tag-input) 379 (input . eww-tag-input)
375 (textarea . eww-tag-textarea) 380 (textarea . eww-tag-textarea)
376 (body . eww-tag-body) 381 (body . eww-tag-body)
377 (select . eww-tag-select) 382 (select . eww-tag-select)
378 (link . eww-tag-link) 383 (link . eww-tag-link)
379 (a . eww-tag-a)))) 384 (a . eww-tag-a))))
380 (shr-insert-document document) 385 (erase-buffer)
381 (cond 386 (shr-insert-document document)
382 (point 387 (cond
383 (goto-char point)) 388 (point
384 (shr-target-id 389 (goto-char point))
385 (goto-char (point-min)) 390 (shr-target-id
386 (let ((point (next-single-property-change 391 (goto-char (point-min))
387 (point-min) 'shr-target-id))) 392 (let ((point (next-single-property-change
388 (when point 393 (point-min) 'shr-target-id)))
389 (goto-char point)))) 394 (when point
390 (t 395 (goto-char point))))
391 (goto-char (point-min)) 396 (t
392 ;; Don't leave point inside forms, because the normal eww 397 (goto-char (point-min))
393 ;; commands aren't available there. 398 ;; Don't leave point inside forms, because the normal eww
394 (while (and (not (eobp)) 399 ;; commands aren't available there.
395 (get-text-property (point) 'eww-form)) 400 (while (and (not (eobp))
396 (forward-line 1))))) 401 (get-text-property (point) 'eww-form))
397 (plist-put eww-data :url url) 402 (forward-line 1)))))
398 (setq eww-history-position 0) 403 (plist-put eww-data :url url)
399 (eww-update-header-line-format))) 404 (setq eww-history-position 0)
405 (eww-update-header-line-format))))
400 406
401(defun eww-handle-link (cont) 407(defun eww-handle-link (cont)
402 (let* ((rel (assq :rel cont)) 408 (let* ((rel (assq :rel cont))
@@ -440,7 +446,7 @@ See the `eww-search-prefix' variable for the search engine used."
440 ;; FIXME? Title can be blank. Default to, eg, last component 446 ;; FIXME? Title can be blank. Default to, eg, last component
441 ;; of url? 447 ;; of url?
442 (format-spec eww-header-line-format 448 (format-spec eww-header-line-format
443 `((?u . ,(plist-get eww-data :url)) 449 `((?u . ,(or (plist-get eww-data :url) ""))
444 (?t . ,(or (plist-get eww-data :title) "")))))) 450 (?t . ,(or (plist-get eww-data :title) ""))))))
445 (setq header-line-format nil))) 451 (setq header-line-format nil)))
446 452
@@ -465,24 +471,30 @@ See the `eww-search-prefix' variable for the search engine used."
465 (shr-generic cont) 471 (shr-generic cont)
466 (shr-colorize-region start (point) fgcolor bgcolor))) 472 (shr-colorize-region start (point) fgcolor bgcolor)))
467 473
468(defun eww-display-raw (&optional buffer encode) 474(defun eww-display-raw (buffer &optional encode)
469 (let ((data (buffer-substring (point) (point-max)))) 475 (let ((data (buffer-substring (point) (point-max))))
470 (eww-setup-buffer buffer) 476 (unless (buffer-live-p buffer)
471 (let ((inhibit-read-only t)) 477 (error "Buffer %s doesn't exist" buffer))
472 (insert data) 478 (with-current-buffer buffer
473 (unless (eq encode 'utf-8) 479 (let ((inhibit-read-only t))
474 (encode-coding-region (point-min) (1+ (length data)) 'utf-8) 480 (erase-buffer)
475 (condition-case nil 481 (insert data)
476 (decode-coding-region (point-min) (1+ (length data)) encode) 482 (unless (eq encode 'utf-8)
477 (coding-system-error nil)))) 483 (encode-coding-region (point-min) (1+ (length data)) 'utf-8)
478 (goto-char (point-min)))) 484 (condition-case nil
479 485 (decode-coding-region (point-min) (1+ (length data)) encode)
480(defun eww-display-image (&optional buffer) 486 (coding-system-error nil))))
487 (goto-char (point-min)))))
488
489(defun eww-display-image (buffer)
481 (let ((data (shr-parse-image-data))) 490 (let ((data (shr-parse-image-data)))
482 (eww-setup-buffer buffer) 491 (unless (buffer-live-p buffer)
483 (let ((inhibit-read-only t)) 492 (error "Buffer %s doesn't exist" buffer))
484 (shr-put-image data nil)) 493 (with-current-buffer buffer
485 (goto-char (point-min)))) 494 (let ((inhibit-read-only t))
495 (erase-buffer)
496 (shr-put-image data nil))
497 (goto-char (point-min)))))
486 498
487(defun eww-display-pdf () 499(defun eww-display-pdf ()
488 (let ((data (buffer-substring (point) (point-max)))) 500 (let ((data (buffer-substring (point) (point-max))))