About a week ago, I was using emacs on a remote computer with only a terminal. I was doing some java coding, and attempted to use java-describe to pull up some javadoc. Of course, since I usually use Firefox for url-browsing, this failed. This prompted me to re-install emacs-w3m, to be used in situations where Firefox was unavailable. I tried emacs-w3m for generalized browsing a while ago, but found it insufficient; it’s a bit slow(although faster than w3), doesn’t support javascript, and is a log uglier. However, it’s better than nothing. You do need w3m to use emacs-w3m; it’s faster than w3 mainly because it is the w3m process that does most of the work.
Installing emacs-w3m is pretty easy: I followed the instructions here to check out the sources from CVS and added them to my load-path. This, as well as the customizations in this blog, were enough to get it set up. As a note: all of the customizations here came from this emacs-wiki page or a page it links to; you may want to see if there is anything else that you’d like on those pages. If you don’t already have the w3m browser, you’ll need to install it. On Ubuntu, you can just do ’sudo apt-get install w3m’.
(setq w3m-session-file "~/.emacs.d/.w3m-session") (setq w3m-session-autosave t) (setq w3m-session-load-last-sessions t) (setq w3m-use-cookies t) (setq browse-url-browser-function 'w3m-browse-url) (setq browse-url-new-window-flag t)nn
These are all the variables used for customizing w3m that I used. The first three auto-save my w3m sessions; if I close emacs while having w3m buffers opened, the next time I open emacs on that computer the buffers should re-open, much like how save-visisted-files opens all the files that were opened previously. I also allow w3m to use cookies so I can log into sites like gmail and facebook if I end up wanting to do that.
(require 'w3m) (require 'w3m-session) (require 'w3m-cookie)
These are the three w3m libraries that I require. w3m is just for standard browing functionality, w3m-session is for the session-saving mentioned above, and w3m-cookie allows cookies to be used when browsing. There are a lot more w3m libraries you can check out, but for the minimal usage I am planning on using it for this is quite enough.
(defun my-w3m-rename-buffer (url) "Renames the current buffer to be the current URL" (rename-buffer url t)) (add-hook 'w3m-display-hook 'my-w3m-rename-buffer) (add-hook 'w3m-display-hook (lambda (url) (let ((buffer-read-only nil)) (delete-trailing-whitespace))))
my-w3m-rename-buffer will rename the current buffer to that of it’s url. Since w3m by default uses names like ‘*w3m*’, ‘*w3m<2>*, and so on for buffer names, this is incredibly useful. Adding the function to w3m-display-hook forces all w3m buffers to have their URLs as their name. The second hook deletes trailing whitespace from w3m buffers. In a lot of cases, trailing whitespace is added, which makes it harder to navigate to where you expect when using C-e; this removes all of that.
(defun w3m-browse-current-buffer () "Look at the current buffer as rendered by w3m." (interactive) (let ((filename (concat (make-temp-file "w3m-") ".html"))) (unwind-protect (progn (write-region (point-min) (point-max) filename) (w3m-find-file filename)) (delete-file filename))))
In case I have a HTML file open in a buffer I’m editing that I want to view in w3m, I have this function. It will open up a new w3m buffer viewing the current buffer. I haven’t had occasion to use it yet, but I saw it on emacs-wiki and it seemed like something that would eventually be useful.
(unless window-system (setq browse-url-browser-function 'w3m-browse-url) (setq browse-url-new-window-flag t))
This is what sets Emacs to use w3m instead of Firefox. I only evaluate it when window-system is nil; if it is ‘x’, or anything else, I know I have a graphical display and can thus use Firefox. I change the function to use when browsing urls to w3m-browse-url, which will open the url up in w3m. The other option forces w3m to create a new buffer whenever a URL is browsed, instead of using old buffers.
Of course, if you’re using Ubuntu, you could just install w3m-el and take care of 95% of what you’ve done.
Just saying….
And wrong. Installing that does not configure your emacs to use it by default.