3

*Help* windows appear to have a special behavior. For example, if I open a help window using C-h f butterfly, the window will open in a separate half-page buffer. If I use the help feature again C-h f tetris, the same help-mode buffer will be reused to display the documentation for tetris. Is there a way to replicate this behavior for other windows? For example, I would like EWW windows to have a behavior similar to *Help*.

So far, I have this:

;; Reuse old *eww* windows.
;; Otherwise, pop up a new window.
(setq-default display-buffer-alist
              (cons '("^\\*\\eww\\*$"
                      (display-buffer-reuse-window
                       display-buffer-pop-up-window))
                     display-buffer-alist))

Is this method correct? I feel uneasy about the use of the use of regex to drive the behavior. Perhaps there is some other way of achieving the same result (e.g. using advice-add)?

2
  • I'm not sure exactly what behavior you're looking for. But maybe start by looking at C-h f with-help-window. That's what's generally used to create and show a help window. – Drew Dec 31 '20 at 23:40
  • @Drew I've actually looked at with-help-window, but my Emacs Lisp isn't great. – Flux Jan 1 at 0:04
0

As @Drew says, it's not clear what you're looking for. However, since I found your answer while creating my own function to reuse an eww window, I thought you might find it helpful.

It simply looks for a buffer called "*eww*" (the default name for eww). If there's a live window, then use that. Otherwise, call eww in the current window.

I've tried to document it fully. Remember, you can use C-h f, C-h v and C-h i d m elisp to learn more.

(defun my-lookup ()
  "Lookup symbol at point in PySide online documentation."
  (interactive)
  ;; define function variables
  ;; let form defines variables, the * means you can use one definition within another
  (let* ((sym (thing-at-point 'symbol)) ; get symbol at point
         (url (concat
                      "https://doc-snapshots.qt.io/qtforpython-5.15/PySide2/QtWidgets/"
                      sym
                      ".html"
                      ))  ; define a web address using that symbol
         (buff (get-buffer-window "*eww*")))  ; check if there exists an eww buffer, get its window
    ;; begin function behavior
    (if buff
        (with-selected-window buff
          (eww url))  ; if eww buffer exists, call eww command in that window
      (eww url))))  ; otherwise call it in the current window

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.