www.howardism.org
Babblings of an aging geek in love with the Absurd, his family, and his own hubris.... oh, and Lisp.

Emacs-focused Web Browsing

I spend most of my computer life in Emacs, as many tasks work better. Sure apply caveats to that statement, but the mouse-less focus of Emacs is efficient. Clarification… I don’t hate the mouse, as much as changing between the mouse and the keyboard, so if I can do everything without a mouse, my efficiency improves. With that statement, let me talk about web browsing, which is traditionally mouse-oriented.

I use three different browsers:

EWW works pretty good for a lot of sites, especially if they consist of text and don’t need JavaScript. If I go to a site, I often either type R to view the contents without the poorly formatted header links of most sites, or & to load it in a graphical browser.

EWW Configuration

I’m currently using Evil mode within Spacemacs, so extract some goodies from my EWW configuration. For instance, let’s use the Duck as the default search engine and whatnot:

(setq browse-url-browser-function 'eww-browse-url
      shr-use-colors nil
      shr-bullet "• "
      shr-folding-mode t
      eww-search-prefix "https://duckduckgo.com/html?q="
      url-privacy-level '(email agent cookies lastloc))

I also bind a number of functions to the , key so that which-key can remind me, but really it works pretty well out of the box.

Going to Chrome

However, much of my day job depends on a web applications that require a graphical web browser running JavaScript, but with my notes in Org, I skip EWW depending on the type of the link, and jump right to the correct browser. For that I’m using the osx-browse package (since my work computer is a Mac). Since I am using two browsers for different purposes (and which browser I use isn’t that important as long as I use two distinct ones), I create two functions for using them:

    (defun osx-browse-url-forwork (url &optional new-window browser focus)
      "Open URL in Brave, Vivaldi, or whatever I'm running on OS X for my day job.
The parameters, URL, NEW-WINDOW, and FOCUS are as documented in
the function, `osx-browse-url'."
      (interactive (osx-browse-interactive-form))
      (callf or browser "com.google.Chrome") ;; Choices: com.apple.Safari
      (osx-browse-url url new-window browser focus))

    (defun osx-browse-url-personal (url &optional new-window browser focus)
      "Open URL in Firefox for my personal surfing.
The parameters, URL, NEW-WINDOW, and FOCUS are as documented in
the function, `osx-browse-url'."
      (interactive (osx-browse-interactive-form))
      (callf or browser "org.mozilla.Firefox")
      (osx-browse-url url new-window browser focus))

Next, I can make a list of URLs that use a particular browser by changing the browse-url-browser-function list of conses:

(setq
 ;; See: http://ergoemacs.org/emacs/emacs_set_default_browser.html
 browse-url-browser-function
 '(("docs\\.google\\.com"  . osx-browse-url-forwork)
   ("bigpanda\\.io"        . osx-browse-url-forwork)
   ("inday\\.io"           . osx-browse-url-forwork)
    ;; ...snip...
   ("dndbeyond.com"        . osx-browse-url-personal)
   ;; ...snip...
   ("."                    . eww-browse-url)))

Selecting a link in an org mode file or wherever, brings the most appropriate browser, and the default falls back to EWW.

Ace

What makes EWW especially good, is adding the ace-link feature from the Avy library. This allows me to type o and have every link on the page clickable with one or two letters. See the Github for an animation if you aren’t familiar. I like it everywhere, including binding ace-link-org.

I like it so much, I want that same feature in my graphical browsers.

Fixing Chrome and Firefox

In my mind, one failure of web browsers, is lack of a mouse-less workflow. However, people have been inventing a lot of extensions to address this. I’ve tried many, and currently using SurfingKeys as it seems pretty simple (or was at one point) and works the same for both Chrome and Firefox.

My one complaint is that the keybindings don’t match ace-link’s o, but that is pretty to address. On the Settings menu item, click the Advanced button, and enter the following URL: http://www.howardism.org/Technical/surfing-keys.js

This simply contains something like this:

unmap('ob');    // I don't need the omnibar search feature,
unmap('od');    // and I want to use the `o` key ...
unmap('og');
unmap('oh');
unmap('oi');
unmap('om');
unmap('on');
unmap('ow');
unmap('ox');
unmap('oy');

map('o', 'f');      // Typical link jumping
map('ao', 'af');    // Open link in a new, focused tab
map('go', 'gf');    // Open link in a new, non-focused tab
map('co', 'cf');    // Open multiple links... I don't use this

I will probably expand that to match more closely my Emacs keybindings.