emacs-w3m

Description

This page is dedicated to the emacs-w3m, also known on this wiki as WThreeM, an Emacs interface to the w3m text browser. Note that it has nothing to do with the w3 or the eww web browsers written entirely in EmacsLisp. Using the Emacs interface to w3m is much faster than using w3, since the parsing and displaying is done by the external w3m process.

Though you can download emacs-w3m from its homepage at http://emacs-w3m.namazu.org, please note that the official releases are extremely old. It is best to download the CVS version from the homepage, or from an updated Git mirror such as https://github.com/ecbrown/emacs-w3m.

There is a mailing-list, that’s to a large extent in Japanese, but not completely. Its archives are available at the website. The list is also archived and gatewayed on Gmane, as gmane.emacs.w3m. Emacs-w3m comes with a manual in TexInfo format, from which a normal, comfortable section of the manual in InfoMode form will be built by the installation process.

If you are building from cvs, be aware of one gotcha: if the first emacs executable in your $PATH is a symlink, then the directory containing that symlink will be used as the base install location by make install. Fix: either change $PATH to expose the actual installed emacs binary first, at least for the duration of the configure/make/install procedure, or hand-edit the Makefile created by running ./configure.

Basic Setup

 (setq browse-url-browser-function 'w3m-browse-url)
 (autoload 'w3m-browse-url "w3m" "Ask a WWW browser to show a URL." t)
 ;; optional keyboard short-cut
 (global-set-key "\C-xm" 'browse-url-at-point)

Editing Emacs Wiki

Don’t forget to enable the use of cookies!

(setq w3m-use-cookies t)

Next, follow this link to set the cookie. This will prevent the reCAPTCHA code from being triggered.

Editing other wikis is still a problem

There is such a problem with captcha at other wikis: for example, the problem described at the Haskell Wiki. Can a solution be suggested for emacs-w3m for overcoming the captcha barrier?

Other WThreeM pages

Problems, questions and hopefully some answers too

Weird Characters

If you are seeing some Japanese characters or nothing at all where you expect Umlauts and other characters, customize the w3m group and change all the references of the ‘euc-jp’ coding system options to ‘latin-1’.

I’ve had a little better luck with making pages look right by putting the following into my ~/.emacs file:
    (setq w3m-coding-system 'utf-8
          w3m-file-coding-system 'utf-8
          w3m-file-name-coding-system 'utf-8
          w3m-input-coding-system 'utf-8
          w3m-output-coding-system 'utf-8
          w3m-terminal-coding-system 'utf-8)
Is there some reason this approach would be worse than using ‘latin-1’? – JerameyCrawford

You may want to store your w3m bookmark file coding system to ‘emacs-mule’ in order to be able to mix Japanese and Latin-1 names.

I am not sure whether you ever need to fiddle with the w3m charset coding system alist. When I last looked at it, it didn’t contain any entries for latin-1 pages.

Some pages contain the evil bullet character that displays as \225 and ought to be a little superscript plus sign. I think. In order to change that to a plus, add the following to your ~/.emacs file:

 (standard-display-ascii ?\225 [?+])

"\240" seen with emacs-w3m FreeBSD

First make sure your locale is set correctly. In my .bashrc I place this:

export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8

then you will want to make sure you are using the port www/w3m-m17n-img. That should fix the problem

Filtering To Downcast To ASCII

emacs-w3m allows users to filter content, and this feature can be used to downcast entities, unicode, and other “?”-spawning characters into something of your choice in ASCII.

First, use standard-display-ascii where you can. I put this in my .emacs:

(standard-display-ascii ?\225 [?+])
(standard-display-ascii ?\227 [?-])
(standard-display-ascii ?\222 [?'])

Now, use w3m-filter-url to do everything else. Add this code to your .emacs-w3m.el:

(setq w3m-use-filter t)
;; send all pages through one filter
(setq w3m-filter-rules `(("\\`.+" w3m-filter-all)))

(defun w3m-filter-all (url)
  (let ((list '(
                ;; add more as you see fit!
               	("»" ">>")
               	("&laquo class="comment">;" "<")
                ("&raquo class="comment">;" ">")
                ("&ouml class="comment">;" "o")
                ("…" "...")
                ("‘" "'")
                ("’" "'")
                ("&rsquo class="comment">;" "'")
                ("&lsquo class="comment">;" "'")
                ("\u2019" "\'")
                ("\u2018" "\'")
                ("\u201c" "\"")
                ("\u201d" "\"")
                ("&rdquo class="comment">;" "\"")
                ("&ldquo class="comment">;" "\"")
                ("“" "\"")
                ("”" "\"")
                ("\u2013" "-")
               	("\u2014" "-")
                ("–" "-")
                ("—" "-")
                ("&ndash class="comment">;" "-")
                ("&mdash class="comment">;" "-")
                )))
  (while list
    (let ((pat (car (car list)))
          (rep (car (cdr (car list)))))
      (goto-char (point-min))
      (while (search-forward pat nil t)
        (replace-match rep))
      (setq list (cdr list))))))

So far this has helped rid my browser of “?” substitutions. Obviously there are many more I have not felt the need to add here (yet). I will edit this list over time as my needs demand.

- BradClawsie (May 2008)

Weird Characters on MS Windows

This may be a little too specific, but I was having some difficulty getting the <HR> tag to show correctly under emacs 21.3.50. I was seeing the nice graphic tables, but the HR line was unprintable, so I was just getting a series of open boxes.

I traced the problem to the w3m-symbol package, and hacked a modification to the w3m-mule-unicode-symbol table. I found out that by setting w3m-use-symbol to nil I could display using just ASCII, but the graphic characters looked so much better.

The problem was that the character used for HR was apparently not in this (or any) font that I had installed.

I just modified the symbol table to change the hr and second-level bullet character to other values that would print.

Here’s my .emacs settings. I’m no elisp coder, but I KNOW there’s a better way to do this. I would be very happy for suggestions on a more concise way to modify the unicode table.

 ;; to see the raw SYMBOL codes generated by emacs-w3m and track down
 ;; an errant character, set the following: You can use this code to
 ;; find which position in the symbol array is being used, and replace
 ;; that as needed
 ;(setq w3m-symbol '("" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""))
 ;; to undo and revert back to normal
 ;(setq w3m-symbol 'w3m-mule-unicode-symbol)
 ;When t, uses the symbol set specified in the variable
 ;w3m-symbol. This works using unicode to paint the tables and
 ;hr with graphic lines, given the patch to the variable
 ;w3m-mule-unicode-symbol below. If the font shows garbage, set to nil
 (setq w3m-use-symbol t)
 ;; overwrite the symbol table here. This is defined originally in
 ;; w3m-symbol, but changing it here rather than in the source code
 ;; allows me to update w3m and still keep the affected change
 ;; characters changed are (0-based array):
 ;; position 26 (<HR> character):   from (32 33) to (32 32)
 ;; position 33 (2d level indent):  from (33 97) to (115 34 mule-unicode-0100-24ff)
 (setq w3m-mule-unicode-symbol
   (when (w3m-mule-unicode-p)
     (append
      (mapcar (lambda (p)
        (if p
 	   (char-to-string
 	    (make-char (or (nth 2 p) 'mule-unicode-2500-33ff)
 		       (car p) (cadr p)))
 	 ""))
      '((32 92) (32 60) (32 76)  (32 44) (32 68) (32 34)  (32 48) nil
        (32 84) (32 52) (32 32)  nil     (32 56) nil      nil     nil
        (32 92) (32 64) (32 79)  (32 47) (32 72) (32 35)  (32 51) nil
 ;       (32 87) (32 55) (32 33)  nil     (32 59) nil      nil     nil
        (32 87) (32 55) (32 32)  nil     (32 59) nil      nil     nil
 ;       (115 34 mule-unicode-0100-24ff)  (33 97) (34 102) (34 43) (33 96) (34 101)
        (115 34 mule-unicode-0100-24ff)  (115 34 mule-unicode-0100-24ff) (34 102) (34 43) (33 96) (34 101)
        (34 46) (34 47) (33 115) (34 47) (34 43) (33 97)
        (34 47)))
     (list (format "%c %c %c "
 	   (make-char 'mule-unicode-0100-24ff 121 42)
 	   (make-char 'mule-unicode-0100-24ff 118 113)
 	   (make-char 'mule-unicode-0100-24ff 118 115))))))

ChrisMcMahan

Webpages are truncated on MacOSX

If webpages get truncated, one could try evaluating

 (if (string= system-type "darwin")
     (setq process-connection-type nil))

as suggested in <m21xvxs8e5.fsf@panix.com> to solve a similar eshell issue, if upgrading is not an option.

W3M hangs on MacOSX 10.5

If W3M keeps hanging, try this:

(add-to-list ‘w3m-command-environment ‘(“GC_NPROCS” . “1”))[1]

Searching emacswiki.org does not work with emacs/w3m

however, it does work from within xterm w3m

	 Yes, it does if you put this in your .emacs file:
   (require 'w3m-search)
   (add-to-list 'w3m-search-engine-alist
		'("emacs-wiki" "http://www.emacswiki.org/cgi-bin/wiki.pl?search=%s"))
	-- kruhft

Middle click to open url in a new sesstion (tab)

I try to use:

    (define-key w3m-mode-map [mouse-2] 'w3m-mouse-view-this-url-new-session)

But it also changes the action of mouse-1. Ideas?

Not working with Emacs 23 ?

I am using GnuEmacs version 23 and emacs-w3m as of 1.4.4 refuses to load. What is the correct way to use it then ?

Try this (as suggested to me by EduardoOchs when I asked in EmacsChannel):

(require 'w3m-e21)
(provide 'w3m-e23)

Works for me. 😊

The current CVS version works out of the box with GnuEmacs 23 (as of 2007-05-09.) --ZedLopez

If you installed w3m from a package, you might need to recompile the bytecode, as bytecode compiled by GnuEmacs 22 is not compatible with GnuEmacs 23

Not working with Emacs 23 and emacs-w3m from the CVS ?

With Emacs 23 from the CVS the follow code can help you to use Emacs23 and Emacs22 without any problem

(if (= emacs-major-version 23)
	(require 'w3m-ems)
  (require 'w3m))

This will load w3m-ems which is the proper package to load with the latest version of emacs-w3m from the CVS.

Avoiding Some Problems with emacs-23 and emacs-w3m from cvs

here is the .emacs snippet i use to load w3m (note your installation path may be different):

(if (= emacs-major-version 23)
    (progn
      (add-to-list 'load-path "~/.el/emacs-w3m/share/emacs/site-lisp/w3m")
      (require 'w3m-load))
  (require 'w3m))

if you don’t know how to force your system to find emacs23 first, try:

export PATH=/path/to/emacs23:$PATH

as of june 16, 2008, this works

BradClawsie

Emacs 23 from CVS and W3M in Debian - Internationalization and code pages

RichardRiley, 20 Oct 2008.

What fixed it for me in Debian was to uninstall the w3m package and install w3mmee. All internationalization then worked. Load w3m in the normal manner.

In a shell:

sudo apt-get remove w3m
sudo apt-get install w3mmee w3mmee-img

Load w3m in the normal manner. Thanks to Andy Stewart for help via email and in the #emacs irc channel.

If you use debian sid or testing you will not have w3mmee and w3mee-img but you can install w3m-el-snapshot.

W3M, HTML articles and org-mode

RichardRiley

Below is some code from Andy Stewart (lazycat DOT manatee AT gmail.com) I requested to integrate w3m html buffers with org-mode. Bind the code to a suitable key and now you can copy the w3m html region into the clipboard in org-mode format so that pasting into org-mode buffers retains all html links.

(defun w3m-get-buffer-with-org-style ()
  "Get current buffer content with `org-mode' style.
This function will encode `link-title' and `link-location' with `org-make-link-string'.
And move buffer content to lastest of kill ring.
So you can yank in `org-mode' buffer to get `org-mode' style content."
  (interactive)
  (let (transform-start
        transform-end
        return-content
        link-location
        link-title
        temp-position
        out-bound)
    (if mark-active
        (progn
          (setq transform-start (region-beginning))
          (setq transform-end (region-end))
          (deactivate-mark))
      (setq transform-start (point-min))
      (setq transform-end (point-max)))
    (message "Start transform link to `org-mode' style, please wait...")
    (save-excursion
      (goto-char transform-start)
      (while (and (not out-bound)             ;not out of transform bound
                  (not (w3m-no-next-link-p))) ;not have next link in current buffer
        ;; store current point before jump next anchor
        (setq temp-position (point))
        ;; move to next anchor when current point is not at anchor
        (or (w3m-anchor (point)) (w3m-get-next-link-start))
        (if (<= (point) transform-end)  ;if current point is not out of transform bound
            (progn
              ;; get content between two links.
              (if (> (point) temp-position)
                  (setq return-content (concat return-content (buffer-substring temp-position (point)))))
              ;; get link location at current point.
              (setq link-location (w3m-anchor (point)))
              ;; get link title at current point.
              (setq link-title (buffer-substring (point) (w3m-get-anchor-end)))
              ;; concat `org-mode' style url to `return-content'.
              (setq return-content (concat return-content (org-make-link-string link-location link-title))))
          (goto-char temp-position)     ;reset point before jump next anchor
          (setq out-bound t)            ;for break out `while' loop
          ))
      ;; concat rest context of current buffer
      (if (< (point) transform-end)
          (setq return-content (concat return-content (buffer-substring (point) transform-end))))
      (kill-new return-content)
      (message "Transform link completed. You can get it from lastest kill ring."))))

(defun w3m-get-anchor-start ()
  "Move and return `point' for thst start of the current anchor."
  (interactive)
  (goto-char (or (previous-single-property-change (point) 'w3m-anchor-sequence) ;get start position of anchor
                 (point)))                                                      ;or current point
  (point))

(defun w3m-get-anchor-end ()
  "Move and return `point' after the end of current anchor."
  (interactive)
  (goto-char (or (next-single-property-change (point) 'w3m-anchor-sequence) ;get end position of anchor
                 (point)))                                                  ;or current point
  (point))

(defun w3m-get-next-link-start ()
  "Move and return `point' for that start of the current link."
  (interactive)
  (catch 'reach
    (while (next-single-property-change (point) 'w3m-anchor-sequence) ;jump to next anchor
      (goto-char (next-single-property-change (point) 'w3m-anchor-sequence))
      (when (w3m-anchor (point))        ;return point when current is valid link
        (throw 'reach nil))))
  (point))

(defun w3m-get-prev-link-start ()
  "Move and return `point' for that end of the current link."
  (interactive)
  (catch 'reach
    (while (previous-single-property-change (point) 'w3m-anchor-sequence) ;jump to previous anchor
      (goto-char (previous-single-property-change (point) 'w3m-anchor-sequence))
      (when (w3m-anchor (point))        ;return point when current is valid link
        (throw 'reach nil))))
  (point))


(defun w3m-no-next-link-p ()
  "Return t if no next link after cursor.
Otherwise, return nil."
  (save-excursion
    (equal (point) (w3m-get-next-link-start))))

(defun w3m-no-prev-link-p ()
  "Return t if no prevoius link after cursor.
Otherwise, return nil."
  (save-excursion
    (equal (point) (w3m-get-prev-link-start))))

My binding looks like this

(define-key w3m-minor-mode-map (kbd "M-w") 'w3m-get-buffer-with-org-style)

18 Nov 2008 : gnus in cvs (emacs 23) rgr : change - emacs 23 article mode

define-key gnus-article-mode-map (kbd "M-w") 'w3m-get-buffer-with-org-style)

org-w3m

I have create `org-w3m.el’ in org-mode, now you can use function ‘org-w3m-copy-for-org-mode’ do same thing. Or press “C-c C-x M-w” in w3m buffer. Enjoy! 😊 – AndyStewart

Bookmarking

        (defun w3m-add-delicious-bookmark (description tag)
          "Add a bookmark to delicious from w3m"
          (interactive (list (read-from-minibuffer "Description: "
                                                   nil nil nil nil
                                                   w3m-current-title)
                             (completing-read "Tag: "
                                              (anything-delicious-get-all-tags-from-cache))))
          (setq description
                (replace-regexp-in-string " " "+" description))
          (let* ((url     w3m-current-url)
                 (url-api (format anything-c-delicious-api-url-add
                                  url
                                  description
                                  tag))
                 anything-delicious-user
                 anything-delicious-password
                 auth)
            (unless (and anything-delicious-user anything-delicious-password)
              (anything-delicious-authentify))
            (setq auth (concat anything-delicious-user ":" anything-delicious-password))
            (with-temp-buffer
              (apply #'call-process "curl" nil t nil
                     `("-u"
                       ,auth
                       ,url-api))
              (buffer-string)
              (goto-char (point-min))
              (if (re-search-forward "<result code=\"done\" />" nil t)
                  (unwind-protect
                       (progn
                         (message "%s added to delicious" description)
                         (when current-prefix-arg
                           (w3m-bookmark-write-file url
                                                    (replace-regexp-in-string "\+"
                                                                              " "
                                                                              description)
                                                    tag)
                           (message "%s added to delicious and to w3m-bookmarks" description)))
                    (anything-wget-retrieve-delicious))
                  (message "Fail to add bookmark to delicious")
                  (when current-prefix-arg
                    (if (y-or-n-p "Add anyway to w3m-bookmarks?")
                        (progn
                          (w3m-bookmark-write-file url
                                                   (replace-regexp-in-string "\+" " "
                                                                             description)
                                                   tag)
                          (message "%s added to w3m-bookmarks" description))))))))

        (define-key w3m-mode-map "\C-x\C-a" 'w3m-add-delicious-bookmark)

ThierryVolpiatto

Not as simple now that OAuth is used; compare http://delicious.com/help/api and http://delicious.com/help/oauthapi --jcorneli
Don’t know what is OAuth, i will have a look. However the actual above code of Lisp:anything-delicious.el work fine. I have updated it. – ThierryVolpiatto

w3m in Emacs 23 (on Debian and Ubuntu 9.10)

The ‘w3m-el’ package is not fully compatible with Emacs 23. Installing ‘w3m-el-snapshot’ instead worked for me. No additional setup like (require 'w3m-load) was necessary.

sudo aptitude install w3m-el-snapshot

If you already have ‘w3m-el’, it will be removed.

MarcoPiedra

I confirm it. If you are on Ubuntu 9.10 and running Emacs 23, install w3m-el-snapshot. It works. Thank you, MarcoPiedra

--JeongtaeRoh

w3m in Emacs23 (Cygwin)

As with Debian and Ubuntu, above, the official w3m-el installed with Cygwin doesn’t seem to work with Emacs 23, the error message being “Cannot open load file: w3m-e22”. One solution is to get the latest emacs-w3m source code from CVS (see the instructions at http://emacs-w3m.namazu.org/) and build and install it (see the README for instructions).

– jiri

Browse url on other window

add this into the configuraion file of the emacs, it would make the emacs work as help buffer. This would help if you use w3m to check document

(setq browse-url-browser-function 'w3m-browse-url-other-window)

(defun w3m-browse-url-other-window (url &optional newwin)
  (let ((w3m-pop-up-windows t))
    (if (one-window-p) (split-window))
    (other-window 1)
    (w3m-browse-url url newwin)))

DennyZhang: Please note, emacs23 has the functions of ffap-other-window/ffap-other-frame. If you always browse url in w3m, I think these functions are good enough.

However, I usually leverage external web browser, and sometimes I may use w3m for some simple web pages.

So my variable of browse-url-browser-function is not set as w3m way. Thus, I define below standalone function, for the case that we want to browse url in a seperate window of w3m mode.

(defun ffap-w3m-other-window (url &optional new-session)
  "Browse url in w3m.
  If current frame has only one window, create a new window and browse the webpage"
  (interactive (progn
                 (require 'browse-url)
                 (browse-url-interactive-arg "Emacs-w3m URL: ")))
  (let ((w3m-pop-up-windows t))
    (if (one-window-p) (split-window))
    (other-window 1)
    (w3m-browse-url url new-session)))

Improving w3m-browse-*

Some w3m-browse-* functions (e.g. w3m-browse-generic) rely on finding urls via browse-url-url-at-point, which in turn relies on (thing-at-point ‘url). However, thing-at-point does not seem to find urls for w3m’s links. That’s because a w3m link contains the url in the w3m-href-anchor text property. I use the following piece of advice to make sure that browse-url finds w3m’s own links.

;; make browse-url-url-at-point use w3m links if they exist
(defadvice browse-url-url-at-point (after w3m-anchor-at-point activate)
	"Browse the url at point. If w3m-anchor finds a url, use it."
	(setq ad-return-value 
				(or
				 (w3m-anchor)
				 (ad-return-value))))

-ghf

Working with Gmail

To work with Gmail, w3m requires a one-line patch. After this, emacs-w3m works well with Gmail in Basic HTML mode. In particular, compared e.g. with mu4e, new mail is seen instantaneously, without needing to be fetched first by e.g. offlineimap.


CategoryExternalUtilities CategoryHypermedia ) (