Next: , Previous: , Up: Top   [Index]

15 Browsing Haddocks using w3m

An experimental feature is use of the w3m browser to browse Haddock docs inside Emacs.

15.1 Get w3m

Most Linux distributions will have a package for the binary:

$ sudo apt-get install w3m

Now grab w3m.el from:

Confirm installation by trying M-x w3m-browse-url RET RET.

If this works, you’re good to go.

15.2 Configure w3m

Now that you have w3m, you probably want to configure it to be more of a passive viewer than a full-fledged browser. For example:

(setq w3m-mode-map (make-sparse-keymap))

(define-key w3m-mode-map (kbd "RET") 'w3m-view-this-url)
(define-key w3m-mode-map (kbd "q") 'bury-buffer)
(define-key w3m-mode-map (kbd "<mouse-1>") 'w3m-maybe-url)
(define-key w3m-mode-map [f5] 'w3m-reload-this-page)
(define-key w3m-mode-map (kbd "C-c C-d") 'haskell-w3m-open-haddock)
(define-key w3m-mode-map (kbd "M-<left>") 'w3m-view-previous-page)
(define-key w3m-mode-map (kbd "M-<right>") 'w3m-view-next-page)
(define-key w3m-mode-map (kbd "M-.") 'w3m-haddock-find-tag)

(defun w3m-maybe-url ()
  (if (or (equal '(w3m-anchor) (get-text-property (point) 'face))
          (equal '(w3m-arrived-anchor) (get-text-property (point) 'face)))

15.3 Import w3m-haddock

It’s not enabled by default in haskell-mode at present, so you need to import it manually:

(require 'w3m-haddock)

15.4 Add a hook for w3m

In order to make haddock pages a little more palatable (and add syntax highlighting to source view), you can add this hook:

(add-hook 'w3m-display-hook 'w3m-haddock-display)

It’s a little rough around the edges, but it’s a start.

15.5 Configure your package locations

By default, the package locations is set to:

(defcustom haskell-w3m-haddock-dirs

If you are using an hsenv or a custom package directory, you should configure this variable with M-x customize-variable or by writing the custom-set-variables code for it.

15.6 Finally

You did all that! Now you’re ready to bind a useful key:

(define-key haskell-mode-map (kbd "C-c C-d") 'haskell-w3m-open-haddock)

Now when you press C-c C-d it will prompt for a package to browse to.

This feature will be improved gradually as time goes on.

Next: , Previous: , Up: Top   [Index]