chiark / gitweb /
emacs, dot-emacs: Overhaul of URL browsing in Emacs.
authorMark Wooding <mdw@ncipher.com>
Tue, 13 Jun 2006 10:06:46 +0000 (11:06 +0100)
committerMark Wooding <mdw@ncipher.com>
Tue, 13 Jun 2006 10:06:46 +0000 (11:06 +0100)
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
emacs

index 75e021b290e105ea085ddd249dc7b00fc806fcc8..ca053b427d3239162cad7b9fe401c46518025805 100644 (file)
@@ -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 67dc57b3a41a438cb78c31ece26c079295f4e538..d19c12aaa711a9dbba815a7580bf2b19c3fad7eb 100644 (file)
--- a/emacs
+++ b/emacs
          ("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)