conkeror: web browsing the emacs way





Web browsing is one of the few computer-based activities for which I usually
do not use emacs. Of course, there are of emacs-based browsers like w3m,
which is pretty good. But for the 21st-century web, a text-mode browser is a
bit limited. There are some efforts underway to integrate a graphical web
browser experience in emacs (e.g., using Xembed), but it will take a while
before that is ready.


The next best thing to web browsing with emacs, is a browser that is
inspired by emacs. Such a browser exists: it's called conkeror (not to be
confused with KDE's Konqueror). conkeror is a Mozilla-based browser that
brings an emacs-like experience to web browsing. I've been using it for more
than a year now as my primary browser, and I am quite happy with it.


Conkeror is a user-interface for the normal Mozilla/Firefox engine
(xulrunner); this means that all those websites that work with Firefox, work
just as well in conkeror, including things like ad-blockers, Java, Flash
etc. and many plug-ins. This is a very important point for me.


If you like emacs, you'll probably also like conkeror. For starters, it uses
many of the same key bindings – C-x C-f will open a url in a new buffer
(tab), C-x 5 2 will open a new window (frame), I can inspect a key-binding
with C-h k… and so on. Some of the single-key shortcuts are the same as
those in w3m, like g to go to a webpage, or B to go back. Conkeror
is fully keyboard-driven; it allows you do almost anything on the web without
using the mouse – it can overlay numbers on items in a webpage so you can
interact with them by their number. Of course, you can still use a mouse if
you want, too.


The conkeror wiki gives many more examples. It also discusses installation in
quite some detail, which makes life a bit easier for me :) Instead, I will
just list a couple of the customizations I have made and encourage you to try
for yourself.




configuration



Like emacs, conkeror is very configurable. The big difference is that
conkeror uses Javascript instead of Elisp for the configuration; however,
the concepts and naming should be familiar for emacs-users. Conkeror's
equivalent of ~/.emacs is ~/.conkerorrc. Below are some snippets from my
setup, that can hopefully help you to create your Perfect Browser ™; all
examples below are based on the latest development version of Conkeror, as
per end of November 2010.


First, some basics:


//allow for 'contrib' stuff
load_paths.unshift("chrome://conkeror-contrib/content/");

// teach me something whenever I start my browser
homepage = "http://en.wikipedia.org/wiki/Special:Random";

// give me new tabs; open buffers (tabs) in the background
require("new-tabs.js");
require("clicks-in-new-buffer.js");
clicks_in_new_buffer_target = OPEN_NEW_BUFFER_BACKGROUND;
clicks_in_new_buffer_button = 1; // midclick links in new buffers with

// auto completion in the minibuffer
minibuffer_auto_complete_default = true;
url_completion_use_history = true; // should work since bf05c87405
url_completion_use_bookmarks = true;





modeline customization



As in emacs, you can customize the modeline. Also in good emacs tradition,
this is far from intuitive…


require("mode-line.js");
// funky icons in the modeline
require("mode-line-buttons.js");
mode_line_add_buttons(standard_mode_line_buttons, true);

// we'd like to see the # of buffers being loaded
add_hook("mode_line_hook", mode_line_adder(loading_count_widget), true);
// we don't need a clock
remove_hook("mode_line_hook", mode_line_adder(clock_widget));






bookmarks



Plain-old bookmarks are easy to add with define_webjump – and you can just
bind them to a short string. You can then 'jump' to the corresponding website by
pressing g and then this short string. For example, to go to Emacs-Fu, you
could type g efu RET. No mousing around needed.


// some bookmarks
define_webjump("conk", "http://conkeror.org");
define_webjump("efu", "http://emacs-fu.blogspot.com");
define_webjump("lkml", "http://lkml.org");
define_webjump("ew", "http://emacswiki.org");
// ...






smart links



Smartlinks are just like normal bookmarks, which the one difference that
they contain an %s-parameter which will be replaced by whatever you type
after the name of the bookmark. Thus, g imdb grande bouffe RET would
take you to the IMDB-page about the movie La Grande Bouffe.


Some examples:


define_webjump("so",    "http://stackoverflow.com/search?q=%s");
define_webjump("yts", "http://www.youtube.com/results?search_query=%s&aq=f");
define_webjump("imbd", "http://www.imdb.com/find?s=all&q=%s");
// ...






integration with emacs



Another useful feature in conkeror is the ability to interact with Emacs
(or any other text editor), so you can use emacs for writing text in web
pages; for example, when you're using emacs-daemon (you should), you could
can add the below, and C-i will then take you to emacs whenever you are in
a text field in a web page.


editor_shell_command = "emacsclient -c";






adding your own functions



It's fairly easy to add your own functions; admittedly, I'm still at the
beginning stages with that, but it's not too hard to combine the internal
function, and assign them to key bindings. Some examples:


// copy url with C-c u
interactive("copy-url",
"Copy the current buffer's URL to the clipboard",
function(I) {
var text = I.window.buffers.current.document.location.href;
writeToClipboard(text);
I.window.minibuffer.message("copied: " + text);
}
);
define_key(default_global_keymap, "C-c u", "copy-url");


// reload conkerorrc with C-c r
interactive("reload-config", "reload conkerorrc",
function(I) {
load_rc();
I.window.minibuffer.message("config reloaded");
}
);
define_key(default_global_keymap, "C-c r", "reload-config");

It's not necessarily so easy to find the exact functions / objects you need
to accomplish what you want. There's a certain learning curve – just like
when using emacs.





integration with org-mode



The integration with emacs can go further than merely editing text fields
though; it's possible to integrate conkeror with org-mode in emacs; I
have the following in my .conkerorrc (this requires emacs-daemon), based
on the code in WOrg:


// org-protocol stuff
function org_capture (url, title, selection, window) {
var cmd_str =
'emacsclient \"org-protocol:/capture:/w/'+url+'/'+title+'/'+selection+'\"';
if (window != null) {
window.minibuffer.message('Issuing ' + cmd_str);
}
shell_command_blind(cmd_str);
}

interactive("org-capture", "Clip url, title, and selection to capture via org-protocol",
function (I) {
org_capture(encodeURIComponent(I.buffer.display_uri_string),
encodeURIComponent(I.buffer.document.title),
encodeURIComponent(I.buffer.top_frame.getSelection()),
I.window);
});
// capture with C-c c
define_key(content_buffer_normal_keymap, "C-c c", "org-capture");

Then, on the emacs-side (in your .emacs), you should have a capture
template for this; for example:


;; ;; the 'w' corresponds with the 'w' used before as in:
;; emacsclient \"org-protocol:/capture:/w/ [...]
(setq org-capture-templates
'(
("w" "" entry ;; 'w' for 'org-protocol'
(file+headline "www.org" "Notes")
"* %^{Title}\n\n Source: %u, %c\n\n %i")
;; other templates
))

Now, when in conkeror, you can select some text, push C-c c ('capture');
emacs will offer you to save this text, including a link to the source, the
date and so on, and saves it for later retrieval. I really love this
feature!






so…



These were just a couple of the many things you can do with conkeror;
there's so much potential here. I haven't discussed many of the other
powerful features, such as the page-specific modes, that give special
features to specific websites, be it GMail or Wikipedia.


I've been using this fine browser for a year or so now, and I really like
it. There are a few rough edges here and there, but it's quite amazing what
the small development team has accomplished. I heartily recommend it – for
web-browsing the emacs-way, there's simple no better alternative.


Finally, if you're using conkeror already, and have some clever tricks
you'd like to share, feel free to do so in the comments.


No comments:

Post a Comment

Followers

Popular Posts