Search code examples
htmlemacsw3m

Display contents of remote HTML in Emacs


I am aware about w3m integration with Emacs but I am exhausted to make it run on my W7/x64: there is a permanent segmentation fault of w3m binary here.

I wonder if there is an alternative way to display remote HTML in Emacs possibly preliminary filtered in the way it is done by Readability/GetPocket etc. services? I do not need a navigation there so cleared contents would be perfect.

Thanks,


Solution

  • trunk / Emacs 24.4:

    • M-x eww RET (URL) RET

    Emacs 24.1 - 24.3:

    • M-x browse-url-emacs RET (URL) RET
    • M-x load-library RET shr RET
    • M-x shr-render-buffer RET
    (defun my-render-url (url)
      "Render URL as HTML."
      (interactive "sURL: ")
      (require 'shr)
      (let ((buf (save-window-excursion (browse-url-emacs url))))
        (shr-render-buffer buf)))
    

    Edit: or this, which has absolutely no error handling, but is considerably faster (which I attribute to browse-url-emacs using url-retrieve-synchronously, where as this is asynchronous). Feel free to make improvements :)

    (defun my-render-url (url)
      "Render URL as HTML."
      (declare (obsolete eww "24.4"))
      (interactive "sURL: ")
      (require 'shr)
      (url-retrieve
       url
       (lambda (&optional status cbargs)
         (let ((markup (current-buffer)))
           (delete-region (point-min) (1+ url-http-end-of-headers))
           (shr-render-buffer markup)
           (kill-buffer markup)))))