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

Option to make magit-status always open in current window #2541

Closed
jimeh opened this issue Feb 5, 2016 · 10 comments
Closed

Option to make magit-status always open in current window #2541

jimeh opened this issue Feb 5, 2016 · 10 comments
Labels
. maintainer's bookmark support User needs some help

Comments

@jimeh
Copy link

jimeh commented Feb 5, 2016

Since I updated magit, it always opens in a "other" window now. I recall earlier last year there were a few options around this behavior, and they changed names a few times, the most recent one I set in my config was magit-status-buffer-switch-function to 'switch-to-buffer which made it open in the current buffer as I like.

But now there doesn't seem to be any options for it. And sadly my lisp skills aren't good enough to dig through the code and the find the solution in 5 minutes. Hence any possible of adding back such an option, or pointing me in the right direction to make magit behave that way?

Thanks :)

@kyleam
Copy link
Member

kyleam commented Feb 5, 2016

This is controlled by magit-display-buffer-function, which by
default is

(defun magit-display-buffer-traditional (buffer)
  "Display BUFFER the way this has traditionally been done."
  (display-buffer
   buffer (if (and (derived-mode-p 'magit-mode)
                   (not (memq (with-current-buffer buffer major-mode)
                              '(magit-process-mode
                                magit-revision-mode
                                magit-diff-mode
                                magit-stash-mode
                                magit-status-mode))))
              '(display-buffer-same-window)
            nil))) ; display in another window

If you wanted Magit to open up every buffer in the current window, you
could set it to

(setq magit-display-buffer-function
      (lambda (buffer)
        (display-buffer buffer '(display-buffer-same-window))))

However, that's not very convenient for things like showing revisions
from log buffers. To behave like magit-display-buffer-traditional,
but open up the status in the current window, you could use something like

(setq magit-display-buffer-function
      (lambda (buffer)
        (display-buffer
         buffer (if (and (derived-mode-p 'magit-mode)
                         (memq (with-current-buffer buffer major-mode)
                               '(magit-process-mode
                                 magit-revision-mode
                                 magit-diff-mode
                                 magit-stash-mode
                                 magit-status-mode)))
                    nil
                  '(display-buffer-same-window)))))

@tarsius tarsius added the support User needs some help label Feb 6, 2016
@tarsius tarsius closed this as completed Feb 6, 2016
@jimeh
Copy link
Author

jimeh commented Feb 10, 2016

@kyleam Thanks, your last code snippet seems to do the job.

Would it not make sense to have a more user friendly option for this stuff though? Cause I found it annoying that magit would pop up somewhere semi-random when I was jumping in and out of magit-status a lot.

@fxleblanc
Copy link

@kyleam Thanks for the snippet. This is exactly what I was looking for. Only one thing(at least on my part), when I activate the commit behavior in my magit status window, I get only the diff window and not a split between the commit message and the diff. I therefore have to switch manually to the COMMIT_MSG buffer to type in my commit.

@kyleam
Copy link
Member

kyleam commented Mar 11, 2016

when I activate the commit behavior in my magit status window, I get
only the diff window and not a split between the commit message and
the diff

That makes sense because, with the snippert above, a diff is shown in
another window given you're currently in a Magit buffer, which is not
true when the diff is displayed from COMMIT_EDITMSG. Without thinking
about it very deeply or trying it out, you could separate out the
check so that non-status Magit buffers are displayed in the other
window regardless of the current buffer's mode:

(setq magit-display-buffer-function
      (lambda (buffer)
        (display-buffer
         buffer
         (cond ((and (derived-mode-p 'magit-mode)
                     (eq (with-current-buffer buffer major-mode)
                         'magit-status-mode))
                nil)
               ((memq (with-current-buffer buffer major-mode)
                      '(magit-process-mode
                        magit-revision-mode
                        magit-diff-mode
                        magit-stash-mode))
                nil)
               (t
                '(display-buffer-same-window))))))

@fxleblanc
Copy link

Cool! It works. Thanks a lot for the explanation. I have a lot of learning to do in elisp and emacs ;)

@tarsius
Copy link
Member

tarsius commented Mar 11, 2016

Would it not make sense to have a more user friendly option for this stuff though?

Sure, but there are many possible magit-display-buffer-functions. I've just started working on some more. Whatever functions I may end up adding I am going to version them, to avoid breaking what worked for some users, when I decided that an existing implementation should be further improved. Unfortunately that means that users who might want to use improved version will have to occasionally have to check if there is a new version available.

Anyway, this is what I have come up so far (completely untested and one function does not even have an implementation yet):

(defun magit-display-buffer-other-window-except-diff-v1 (buffer)
  "Display BUFFER in the selected window except for some modes.

Display buffers whose `major-mode' derive from `magit-diff-mode'
or `magit-process-mode' in another window, and display all other
buffers in the selected window."
  (display-buffer
   buffer (if (or (derived-mode-p 'magit-diff-mode)
                  (derived-mode-p 'magit-process-mode))
              nil ; display in another window
            '(display-buffer-same-window))))

(defun magit-display-buffer-fullcolumn-with-log-exception-v1 (buffer)
  "Display BUFFER using the full column except in some cases.

Display most buffers whose `magit-mode' derive from `magit-mode'
in the selected window and grow that window to the full height
of the frame, deleting other window in that column as necessary.

But buffers whose modes derive from `magit-process-mode' are
always displayed in another window and buffers whose modes
derive from `magit-diff-mode' are also displayed in another
window, provided that the mode of the current buffer derives
from `magit-log-mode' or `magit-cherry-mode'."
  )

And here's a snippet that might also help:

The hierarchy of `magit-mode' derived modes is as follows.

  `magit-mode'
    `magit-status-mode'
    `magit-refs-mode'
    `magit-diff-mode'
      `magit-revision-mode'
      `magit-stash-mode'
      `magit-merge-preview-mode'
    `magit-log-mode'
      `magit-log-select-mode'
      `magit-reflog-mode'
        `magit-stashes-mode'
    `magit-cherry-mode'
    `magit-process-mode'

The major-modes `magit-popup-mode', `git-commit-mode', and
`git-rebase-mode' do not derived from `magit-mode', and you
should not try to handle them here.

@tarsius tarsius added the . maintainer's bookmark label Apr 28, 2016
kyleam added a commit that referenced this issue May 21, 2016
As mentioned in #2541, there are a lot of possible behaviors for
display-buffer functions.  Provide a few more options that users can try
before resorting to writing their own functions.

magit-display-buffer-same-window-except-diff-v1 and
wmagit-display-buffer-fullcolumn-most-v1 are modified from variants
proposed in #2541.  magit-display-buffer-fullframe-status-v1 provides
the full-frame status behavior that seems to be popular (#1953).

The names of these functions are versioned, as suggested in #2541.

The helper function magit--display-buffer-fullframe is modified from a
function that Sebastian Wiesner shared in #1953.
kyleam added a commit that referenced this issue May 22, 2016
As mentioned in #2541, there are a lot of possible behaviors for
display-buffer functions.  Provide a few more options that users can try
before resorting to writing their own functions.

magit-display-buffer-same-window-except-diff-v1 and
magit-display-buffer-fullcolumn-most-v1 are modified from variants
proposed in #2541.  magit-display-buffer-fullframe-status-v1 provides
the full-frame status behavior that seems to be popular (#1953).

The names of these functions are versioned, as suggested in #2541.

The helper function magit--display-buffer-fullframe is modified from a
function that Sebastian Wiesner shared in #1953.
kyleam added a commit that referenced this issue May 24, 2016
As mentioned in #2541, there are a lot of possible behaviors for
display-buffer functions.  Provide a few more options that users can try
before resorting to writing their own functions.

magit-display-buffer-same-window-except-diff-v1 and
magit-display-buffer-fullcolumn-most-v1 are modified from variants
proposed in #2541.  magit-display-buffer-fullframe-status-v1 provides
the full-frame status behavior that seems to be popular (#1953).

The names of these functions are versioned, as suggested in #2541.

The helper function magit--display-buffer-fullframe is modified from a
function that Sebastian Wiesner shared in #1953.
simon-katz added a commit to simon-katz/nomis-public-dev-setup that referenced this issue Sep 10, 2017
Fixed by getting rid of `nomis/magit-display-buffer-function`,
which was a fix for the following problem that seems to have gone away:
    > Have Magit status buffer open in same window
    > See magit/magit#2541
@snan

This comment has been minimized.

@tarsius

This comment has been minimized.

@snan

This comment has been minimized.

@tarsius
Copy link
Member

tarsius commented Feb 22, 2021

That too is not controlled by magit-display-buffer. 😁

Unless you are using a very old magit version it also isn't controlled by magit-popup-display-buffer-action, because magit doesn't use magit-popup anymore. It now uses transient.

I don't understand your problem description. Also we no longer use the issue tracker for support requests and repurposing old issues for new support requests was never a good idea in the first place. Please open a new "discussion" instead, possibly with screenshots.

8dcc added a commit to 8dcc/emacs-dotfiles that referenced this issue Nov 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
. maintainer's bookmark support User needs some help
Development

No branches or pull requests

5 participants