Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Purpose-mode breaks org-tree-to-indirect-buffer #122

Closed
dangom opened this issue Mar 18, 2018 · 4 comments
Closed

Purpose-mode breaks org-tree-to-indirect-buffer #122

dangom opened this issue Mar 18, 2018 · 4 comments
Labels

Comments

@dangom
Copy link

dangom commented Mar 18, 2018

If org-indirect-buffer-display is 'other-window, then calling org-tree-to-indirect-buffer should open an inderect buffer in the other window. If purpose-mode is enabled, then org-tree-to-indirect-buffer will open the indirect buffer in the current window. Somehow pop-to-buffer and -pop-to-buffer-same-window` do the same thing if purpose is on?

@bmag
Copy link
Owner

bmag commented Aug 7, 2018

Apparently this is a result of #98. I fixed it in the old-issues branch (b06397d), but I am worried the fix will cause Purpose to not reuse the current window enough times. If you still use Purpose, can you try out the fix and test if it interferes with your regular workflow?

Sorry for the late reply, I was busy with other matters.

For convenience, here is the diff:

--- a/window-purpose-switch.el
+++ b/window-purpose-switch.el
@@ -95,8 +95,8 @@ it yourself.")
                            purpose-display-maybe-pop-up-window
                            purpose-display-maybe-pop-up-frame))
     (force-same-window . (purpose-display-maybe-same-window))
-    (prefer-other-window . (purpose-display-reuse-window-buffer
-                            purpose-display-reuse-window-purpose
+    (prefer-other-window . (purpose-display-reuse-window-buffer-other-window
+                            purpose-display-reuse-window-purpose-other-window
                             purpose-display-maybe-other-window
                             purpose-display-maybe-pop-up-window
                             purpose-display-maybe-other-frame
@@ -326,6 +326,18 @@ that a window on another frame is chosen, avoid raising that frame."
         (purpose-change-buffer buffer window 'reuse alist))
       window)))
 
+(defun purpose-display-reuse-window-buffer-other-window (buffer alist)
+  "Return a non-selected window that is already displaying BUFFER.
+This is the same `purpose-display-reuse-window-buffer', except
+the currently selected window is not eligible for reuse."
+  (purpose-display-reuse-window-buffer buffer (cons '(inhibit-same-window . t) alist)))
+
+(defun purpose-display-reuse-window-purpose-other-window (buffer alist)
+  "Return a non-selected window that is already used for the purpose PURPOSE.
+This is the same `purpose-display-reuse-window-purpose', except
+the currently selected window is not eligible for reuse."
+  (purpose-display-reuse-window-purpose buffer (cons '(inhibit-same-window . t) alist)))
+
 (defun purpose-display-reuse-window-buffer-other-frame (buffer alist)
   "Return a window that is already displaying BUFFER.
 Return nil if no usable window is found.
@@ -492,8 +504,9 @@ used window, split the selected window."
          (new-window (or (split-window-sensibly old-window)
                          (and force-split
                               (split-window old-window)))))
-    (purpose-change-buffer buffer new-window 'window alist)
-    new-window))
+    (when new-window
+      (purpose-change-buffer buffer new-window 'window alist)
+      new-window)))
 
 (defun purpose-display-pop-up-window (buffer alist)
   "Display BUFFER in a new window.

@bmag bmag added the bug label Aug 7, 2018
bmag added a commit that referenced this issue Aug 9, 2018
@bmag bmag closed this as completed in b06397d Aug 9, 2018
bmag added a commit that referenced this issue Aug 9, 2018
@bmag
Copy link
Owner

bmag commented Aug 9, 2018

Reopening since I reverted the fix for now.

@bmag bmag reopened this Aug 9, 2018
@bmag
Copy link
Owner

bmag commented Aug 17, 2018

I decided not to fix this issue, since it I don't consider it a bug in Purpose. It might be a bug in Org 9.1.9 (built-in version in Emacs 26.1).

When org-indirect-buffer-display is set to other-window, according to its documentation org-tree-to-indirect-buffer is supposed to display the indirect buffer in another window. In the code, the display is done by calling: (ibuf is the indirect buffer created by org-tree-to-indirect-buffer)

(pop-to-buffer ibuf)

However, when called like that, pop-to-buffer is allowed to reuse the current window to display ibuf. To inhibit reuse of current window, pop-to-buffer must be called with the optional action argument, like so:

(pop-to-buffer ibuf t)

Purpose tries harder than stock Emacs to reuse windows, because it doesn't want to mess the user's window layout. That's why, when purpose-mode is enabled, org-tree-to-indirect-buffer opens the indirect buffer in the current window.

Fortunately, if you don't like reusing the current window for the indirect buffer, you can give the indirect buffers a different purpose than regular Org buffers, and that should be enough to restore org-tree-to-indirect-buffer to the behavior you are familiar with. Just add to your Emacs configuration:

(purpose-add-user-purposes :regexps '(("\\.org-" . indirect)))

@antonalekseev
Copy link

Similar issue has arisen recently with the clone-indirect-buffer-other-window. Without explicit purpose-add-user-purposes configuration it opens indirect buffer in the same window. The problem of explicit configuration like from your last post is that this way clone-indirect-buffer also opens buffer in other window.

Should't window-purpose respect pop-up-windows t in this case?

https://github.com/emacs-mirror/emacs/blob/f18af6cd5cb7dbbf7420ec2d3efed4e202c4f0dd/lisp/simple.el#L8585-L8586

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants