4

Suppose I open one window with a Common Lisp file in it, and a second window with SLIME REPL in it (using M-x slime or whatever). Now, doing C-c C-d h with point on a Common Lisp keyword brings up a window with the CLHS entry for that keyword (using w3m, and assuming everything has been configured correctly, but lets assume that is the case).

Now, I want the CLHS window to be set up, so that wherever I call C-c C-d h, either in the Lisp file window, or in the SLIME REPL window, the CLHS page comes up in the same window. This currently does not happen. I am using some code which I found on the Emacs wiki, W3m: Browse url on other window, which helps but does not completely work. I think it works if only one window (besides the CLHS window) is open.

(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)))

NOTE: This is probably a specific example of a more general question.

4

I think the following should mostly do what you want

(defvar w3m-dedicated-window nil)

(defun w3m-browse-url-dedicated-window (url &optional new-session)
  (let ((w3m-pop-up-windows t))
    (if (and w3m-dedicated-window
             (window-live-p w3m-dedicated-window))
        (with-selected-window w3m-dedicated-window
          (w3m-browse-url url new-session))
      (split-window) ;; ugly as hell, but w3m-pop-up-windows is ignored...
      (other-window 1)
      (w3m-browse-url url new-session)
      (setq w3m-dedicated-window (selected-window))
      (set-window-dedicated-p w3m-dedicated-window t))))

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

Using the dedicated window flag, it tries harder to keep the browser visible. And that dedicated window is reused as much as possible, whenever a new URL is browsed.

  • This doesn't appear to work. To start with, I just opened a Lisp file, and ran C-c C-d h. Emacs didn't open a new window; it just replaced the Lisp file with a CLHS entry. Then I tried opening a Lisp file, then run M-x slime which opened a second window. Then I ran C-c C-d h with point in the Lisp file window, and it replaced the Lisp file with a CLHS entry again. Also, when attempted to click on a link in the CLHS wndow, I get "Symbol's value as variable is void: "w3m-pop-up-windows". Am I doing something wrong? – Faheem Mitha Sep 24 '14 at 9:38
  • Ok, I partially take that back. Once a window containing a CLHS entry is open, the CLHS pages do seem to come up in the same window. But having the first CLHS entry come up in a window that is being used by something else is not ideal. Can this be fixed? Also, of course, one wants links to work... – Faheem Mitha Sep 24 '14 at 9:46
  • No idea why w3m-pop-up-windows is undefined for you. It's a variable defined in w3m.el (and it works for me :)). You're right about the window being recycled. Unfortunately it looks like w3m-pop-up-windows, which should provide just that feature, is ignored when w3m is called non-interactively, as is the case here. I guess using (split-window) as in your initial code could work. It's a bit ugly though – Sigma Sep 24 '14 at 13:58
  • Ok, just fyi, I don't get notified if you don't add a @ in front. Can you suggest a possible reworking of the code using (split-window)? – Faheem Mitha Sep 24 '14 at 17:58
  • @FaheemMitha yep, edited my code to reflect that. There ought to be a better solution though :( – Sigma Sep 26 '14 at 0:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.