From a203fba87fe2b0d9be2c1da7b55a6eb6ca46766b Mon Sep 17 00:00:00 2001 Message-Id: From: Mark Wooding Date: Tue, 13 Jun 2006 11:06:46 +0100 Subject: [PATCH] emacs, dot-emacs: Overhaul of URL browsing in Emacs. Organization: Straylight/Edgeware From: Mark Wooding Insert a wossname in front of w3m's main function so that it doesn't take over my current window. It now tries to reuse the existing w3m window if there is one, or picks some other convenient window, creating a new one if necessary. This makes Hyperspec lookups rather more convenient, since I can carry on working in the REPL or a Lisp buffer with the Hyperspec stuff in a fixed place and not worry about w3m screwing my display over. --- dot-emacs.el | 36 ++++++++++++++++++++++++++++++++++++ emacs | 11 ++--------- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/dot-emacs.el b/dot-emacs.el index 75e021b..ca053b4 100644 --- a/dot-emacs.el +++ b/dot-emacs.el @@ -292,6 +292,42 @@ (defun mdwmail-mangle-signature () (perform-replace "\n-- \n" "\n-- " nil nil nil))) (add-hook 'mail-setup-hook 'mdwmail-mangle-signature) +;;;----- URL viewing -------------------------------------------------------- + +(defun mdw-w3m-browse-url (url &optional new-session-p) + "Invoke w3m on the URL in its current window, or at least a different one. +If NEW-SESSION-P, start a new session." + (interactive "sURL: \nP") + (save-excursion + (select-window (or (and (not new-session-p) + (get-buffer-window "*w3m*")) + (progn + (if (one-window-p t) (split-window)) + (get-lru-window)))) + (w3m-browse-url url new-session-p))) + +(defvar mdw-good-url-browsers + '((w3m . mdw-w3m-browse-url) + browse-url-w3 + browse-url-mozilla) + "List of good browsers for mdw-good-url-browsers; each item is a browser +function name, or a cons (CHECK . FUNC). A symbol FOO stands for (FOO +. FOO).") + +(defun mdw-good-url-browser () + "Return a good URL browser. Trundle the list of such things, finding the +first item for which CHECK is fboundp, and returning the correponding FUNC." + (let ((bs mdw-good-url-browsers) b check func answer) + (while (and bs (not answer)) + (setq b (car bs) + bs (cdr bs)) + (if (consp b) + (setq check (car b) func (cdr b)) + (setq check b func b)) + (if (fboundp check) + (setq answer func))) + answer)) + ;;;----- Paragraph filling -------------------------------------------------- ;; --- Useful variables --- diff --git a/emacs b/emacs index 67dc57b..d19c12a 100644 --- a/emacs +++ b/emacs @@ -168,16 +168,9 @@ ("ftp" . ,proxy) ("gopher" . ,proxy)))) (setq url-cookie-untrusted-urls '(".")) - -(let ((browsers '(w3m browse-url-w3 browse-url-mozilla)) browser) - (while browsers - (setq browser (car browsers) - browsers (cdr browsers)) - (if (fboundp browser) - (setq browse-url-browser-function browser - browsers nil)))) -(setq browse-url-mozilla-program "firefox") +(setq browse-url-browser-function (mdw-good-url-browser) + browse-url-mozilla-program "firefox") (setq w3m-default-display-inline-images t) -- [mdw]