Why browse the Web in Emacs?

2014-11-27: Hi, Hacker News! Remember, this post is from 2008 and predates Emacs 24.4. I hear EWW (Emacs Web Wowser?) is pretty cool and have been meaning to try it out. Anyway, on with the show!

“Are you browsing Slashdot in Emacs?”, W- asked me after he glanced at my screen.

With Emacs’ reputation for including everything _and_ the kitchen sink, you probably won’t be surprised to hear that there’s more than one way to surf the Internet using your text editor. With today’s Javascript- and image-heavy websites, it can be hard to believe that anyone would use a text-based browser with limited support for many of the things we take for granted. Still, a Web browser in your text editor can be surprisingly useful. Here are some of the reasons why you might like it:

  • Browsing is faster and less distracting. Forget flashing ads, garish colors, and large images. When you surf the Web in Emacs, you can focus on reading, and you can use all the typical Emacs shortcuts for navigating around. You can view images when you want to. If you need to see something that Emacs doesn’t support, you can easily open the current page in an external Web browser.
  • You can integrate it into your work. With a little bit of Emacs Lisp, you can quickly look up information on the Web based on what you’re currently working on. For example, PHP mode comes with a shortcut that lets you look up the current function’s documentation in the PHP manual. You can look up bug report details, dictionary definitions, and Wikipedia pages with minimal typing, too. If you use Emacspeak, you can set up the web browser to speech-synthesize more than what’s displayed on screen. The more you use Emacs, the more benefits you get from the integration.
  • You can customize everything. You can customize your Emacs experience quickly and easily, and if you spend a lot of time on the Net, you’ll appreciate having your own shortcuts and functions. For example, I’ve completely remapped my keyboard shortcuts to support tabbed browsing on a Dvorak keyboard, and I’ve defined a few functions to make frequently-used commands much easier. You can even use functions to process Web pages and either summarize the information you’re interested in or make pages more navigable. It’s all just Emacs Lisp.
  • You’re safe from browser exploits. No Javascript pop-ups, no image bugs, no browser-based malware that can take over your comuter or steal data. Just content.
  • You need less memory. Why open up a memory-intensive graphical Web-based browser when you’ve got Emacs open anyway?

There’s more than one way to browse the Web in Emacs, of course. Browse-url is a package that makes it easy to open URLs in your preferred browser or browsers. For example, you can use it to browse the Web in Mozilla Firefox, and (of course) you can use it to browse the Web within Emacs itself. For browsing within Emacs, you can use w3m.el, an interface to the external W3M browser, or w3, a Web browser written entirely in Emacs Lisp. Of the two, I prefer w3m.el, which is much faster and more featureful than w3. Both can display graphics, tables, and frames, and w3 supports stylesheets.

More about Emacs and browsing the Web soon! Planned projects for this chapter of Wicked Cool Emacs:

*** Project XXX: Browse the Web
*** Project XXX: Open the current webpage in an external browser
*** Project XXX: Different browsers for different pages
*** Project XXX: Toggle between Web and work
*** Project XXX: Quick search
*** Project XXX: Customize your keymap
*** Project XXX: Download files
*** Project XXX: Add access keys
*** Project XXX: Use social bookmarking
*** Project XXX: Typeahead
*** Project XXX: Preview HTML
*** Project XXX: Read Web pages as news
2014-11-27: You can find more comments on Hacker News.
  • Micah R Ledbetter

    This isn’t browsing IN emacs, but if you haven’t seen them already, you should definitely check out conkeror (http://conkeror.org) and stumpwm (http://www.nongnu.org/stumpwm/). Both are by the same developer(s?), are “inspired by emacs”, and aim to be both keyboard driven and hackable – conkeror, a web browser, in javascript; and stumpwm, an X11 window manager, in common lisp and on the fly.

    Both of these have made web browsing a LOT less jarring when I’m in full-on Emacs edit mode, even if it’s not an actual Emacs browser.

  • Pedro

    Nice post! So, you also use the Dvorak keyboard layout. Could you care to say a little bit about your Dvorak setup with emacs? Did you remap any functions?

  • And, you can waste time browsing the web and make it look like you’re working! :)

  • I use Dvorak too, and although I liked emacs, I found that the keybindings were very unDvorak-friendly. (Although vi is even worse)
    So I’d second the request that Pedro has posted.

  • Sam

    I am also a Dvorak user and I threw the defaults out since I don’t consider ctrl-p, ctrl-n, …, worth saving. As I am only slightly happier with my own design I’d like to see what you are using.

  • (defun sacha/w3m-setup-keymap ()
      "Use my heavily customized map."
      ;; Undefine this key and use the advice instead so that my ido doesn't get
      ;; overridden
      (define-key w3m-mode-map (kbd "C-x b") nil)
      (define-key w3m-mode-map "C" 'w3m-print-this-url)
      (define-key w3m-mode-map "a" 'sacha/delicious-url)
      (define-key w3m-mode-map "A" 'w3m-bookmark-add-current-url)
      (define-key w3m-mode-map "w" 'w3m-download-with-wget)
      (define-key w3m-mode-map "d" 'w3m-download-with-wget)
      (define-key w3m-mode-map "D" 'w3m-download-this-url)
      ;; Do not override my ever so handy ERC binding
      (define-key w3m-mode-map (kbd "C-c C-SPC") nil)
      (define-key w3m-mode-map "m" 'sacha/w3m-mirror-current-page)
      (define-key w3m-mode-map "M" 'sacha/w3m-mirror-link)
      ;; I use search much more often than the context history list, although
      ;; context is still cool. 
      (define-key w3m-mode-map "!" 'sacha/w3m-mirror-current-page)
      (define-key w3m-mode-map "s" 'w3m-search)
      (define-key w3m-mode-map "h" 'w3m-history)
      (define-key w3m-mode-map "t" 'w3m-scroll-down-or-previous-url)
      (define-key w3m-mode-map "n" 'w3m-scroll-up-or-next-url)
      ;; I don't often w3m to edit pages, so I'm borrowing o and e (right
      ;; below , / . for tab navigation) for page navigation instead.
      (define-key w3m-mode-map "o" 'w3m-view-previous-page)
      (define-key w3m-mode-map "e" 'w3m-view-next-page)
      ;; i is a more useful mnemonic for toggling images
      (define-key w3m-mode-map "i" 'w3m-toggle-inline-image)
      (define-key w3m-mode-map "I" 'w3m-toggle-inline-images)
      ;; and X for closing the buffer
      (define-key w3m-mode-map "X" 'w3m-delete-buffer)
      (define-key w3m-mode-map "x" 'w3m-delete-buffer)
      (define-key w3m-mode-map "z" 'w3m-delete-buffer)
      ;; and b for bookmarks
      (define-key w3m-mode-map "b" 'w3m-bookmark-view)
      ;; I don't use the Qwerty keymap, so hjkl is useless for me
      ;; I'll use HTNS, though
      (define-key w3m-mode-map "H" 'backward-char)
      (define-key w3m-mode-map "T" 'previous-line)
      (define-key w3m-mode-map "N" 'next-line)
      (define-key w3m-mode-map "S" 'forward-char)
      ;; Browse in new sessions by default
      (define-key w3m-mode-map (kbd "RET") 'w3m-view-this-url)
      (define-key w3m-mode-map [(shift return)] 'w3m-view-this-url-new-session)
      (define-key w3m-mode-map "g" 'w3m-goto-url)
      (define-key w3m-mode-map "G" 'w3m-goto-url-new-session)
      ;; f for forward? I want to be able to follow links without removing
      ;; most of my fingers from home row. My fingers are too short to hit
      ;; Enter.
      (define-key w3m-mode-map "f" 'w3m-view-this-url-new-session)
      (define-key w3m-mode-map "F" 'w3m-view-this-url)
      ;; Use cursor keys to scroll
      (define-key w3m-mode-map [(left)] 'backward-char)
      (define-key w3m-mode-map [(right)] 'forward-char)
      (define-key w3m-mode-map [(shift left)] 'w3m-shift-right)
      (define-key w3m-mode-map [(shift right)] 'w3m-shift-left)
      ;; Which means I can now use , and . to switch pages
      (define-key w3m-mode-map "." 'w3m-next-buffer)
      (define-key w3m-mode-map "," 'w3m-previous-buffer)
      ;; IBM stuff
      (define-key w3m-mode-map "i" nil)
      (define-key w3m-mode-map "ib" 'sacha/ibm-blog)
      (define-key w3m-mode-map "id" 'sacha/dogear-url)
      (define-key w3m-mode-map "f" 'sacha/w3m-open-in-firefox)

    Here’s my currently-unedited-and-with-a-number-of-custom-functions keymap. I really only tend to use . and , to switch buffers a lot, a to del.icio.us stuff, x, C, I, and the cursor keys…

    Someday there’s going to be a Pareto-type visualization for Emacs. I’d be interested in knowing which 20% (or more like 0.002%) of the functionality I actually use…

  • menzoic

    screenshots plz

  • z0ltan

    You look like a chipmunk, albeit a cute one.