0

So I would like to use the function below. The problem is that if I call this multiple times another window opens instead of the window that already exists. All the buffers that are created look like this "XXXXXX-1" So the second call would look like "YYYYYY-1"

Below the function is a block of my init file that deals with problematic windows, but I'm not able to find a buffer name definition that catches the scheme. I assume I need some regexp magic which I'm not able to cast. Is there some wizard who can help me out?

(defun my-org-tree-open-in-right-window ()
  (interactive)
  (org-tree-to-indirect-buffer)
  (windmove-right))

_

   (setq display-buffer-alist
        '(
          ("*Org Lint*" . ((display-buffer-use-some-window) (inhibit-same-window . t)))
          ("^\\*Woman"  . ((display-buffer-use-some-window) (inhibit-same-window . t)))
          ("^\\*Man"    . ((display-buffer-use-some-window) (inhibit-same-window . t)))
          ))
  (add-to-list 'same-window-buffer-names "*Apropos*")
  (add-to-list 'same-window-buffer-names "*Backtrace*")
  (add-to-list 'same-window-buffer-names "*Info*")
  (add-to-list 'same-window-buffer-names "*Messages*")
  (add-to-list 'same-window-buffer-names "*Shell*")
  (add-to-list 'same-window-buffer-names "*Summary*"))
  • You may be interested in the variable same-window-regexps. In addition, Emacs has a fun tool to compose regexp that can be activated with M-x re-builder, which will highlight matches in another buffer. I found that variable by reading the doc-string for same-window-buffer-names ... – lawlist Mar 24 '18 at 21:38
1

This should do what you're asking for, keep in mind there are several org-narrow-to functions so you can replace org-narrow-to-subtree with whatever fits your needs. To solve the problem I create my own buffer name, and reuse it for the indirect buffer.

(defun org-subtree-to-indirect-buffer ()
  (interactive)
  (let ((ind-buf (concat (buffer-name) "-narrowclone")))
    (if (get-buffer ind-buf)
        (kill-buffer ind-buf))
    (clone-indirect-buffer-other-window ind-buf t)
    (org-narrow-to-subtree)
    (switch-to-buffer ind-buf)))
  • Thanks alot. Did work after I added to mentioned display-buffer-alist this: ("-narrowclone" . ((display-buffer-use-some-window) (inhibit-same-window . t))) – Jens Lange Apr 4 at 21:51

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.