Tab shuffling in emacs-w3m

Emacs-w3m comes with an excellent tab mode, which you can enable with (setq w3m-use-tab t) in your .emacs. C-cC-t creates new tabs, C-cC-w closes them and you can navigate then with C-cC-[np], or, my favourite, using a tab list via C-cC-s (if you didn’t know about this one, give it a try: it’s very useful).

But i quickly find myself with lots of open tabs that happen to be in the wrong order, and i wanted something akin to Firefox’s ability to move and reorder them around. I didn’t find a way change a tab’s position in a vanilla emacs-w3m, but it wasn’t that difficult to cook up my own solution. This function:

(defun jao-w3m-switch-buffers (dist)
    (interactive "p")
    (let* ((dist (if (zerop dist) 1 dist))
           (current (current-buffer))
           (current-no (w3m-buffer-number current))
           (next (progn (w3m-next-buffer dist)
           (next-no (w3m-buffer-number next)))
      (with-current-buffer current
        (rename-buffer "*w3m*<*>")
        (w3m-buffer-set-number next current-no)
	(w3m-buffer-set-number current next-no)
      (switch-to-buffer current)))

switches the current tab with the one to its right (cyclically), or to the n-th to its right if you provide a numerical argument (e.g. M-3). I’ve got this function bound to C-cC-f:

(define-key w3m-mode-map (kbd "C-cC-f") 'jao-w3m-switch-buffers)

Alternatively, one could define a function that moves the current tab to the right a number of times. We can take advantage of the above function for a quick hack:

(defun jao-w3m-move-buffer (dist)
  (interactive "p")
  (let ((dist (if (zerop dist) 1 dist))
    (while (> dist 0)
      (jao-w3m-switch-buffers 1)
      (setq dist (1- dist)))))

and bind that to a shortcut of your choice. There you go: easy tab shuffling.


4 Responses to “Tab shuffling in emacs-w3m”

  1. shreevatsa Says:

    Wow, great. Thanks!

    Could something similar be done for tabbar.el? (Or extend w3m’s tab mode to Emacs in general, as it looks better 😉 )

  2. Katsumi Yamaoka Says:

    Leo suggested me to incorporate this great work into emacs-w3m and I’ve installed similar functions in the CVS trunk. Now you can use these keys:

    `C-c C-,’, `C-c C-‘, C-wheel-down. or C-mouse-5

    Thank you very much for contributing this.

    Best regards,

  3. Katsumi Yamaoka Says:

    Oops. Some keys I wrote are missing in the publishing. Here they are:

    `C-c C-,’, `C-c C-‘, C-wheel-down. or C-mouse-5

  4. Katsumi Yamaoka Says:

    This is the third try. :-‘, C-wheel-down. or C-mouse-5

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: