Commit 78cbe4f5 authored by Jonas Bernoulli's avatar Jonas Bernoulli

magit-generate-buffer-name-function: new option

Add new option `magit-generate-buffer-name-function' and new function
`magit-generate-buffer-name-default-function' as its default value.

Also add new function `magit-generate-new-buffer' as a wrapper around
the calls to `magit-generate-buffer-name-function' and
`generate-new-buffer'.
parent e3ffa7be
......@@ -504,6 +504,16 @@ the user invokes Git commands, or creates or visits other buffers.
*** Naming Buffers
- User Option: magit-generate-buffer-name-function
The function used to generate the names of Magit buffers.
- Function: magit-generate-buffer-name-default-function mode
This function returns a buffer name suitable for a buffer whose
major-mode is MODE and which shows information about the repository
in which ~default-directory~ is located.
While it often is enough to have one buffer of a certain Magit mode
per repository, this is not always the case. You might, for example,
want to view the diffs for two commits at the same time. To do so,
......
......@@ -769,6 +769,18 @@ buffer is buried.
@node Naming Buffers
@subsection Naming Buffers
@defopt magit-generate-buffer-name-function
The function used to generate the names of Magit buffers.
@end defopt
@defun magit-generate-buffer-name-default-function mode
This function returns a buffer name suitable for a buffer whose
major-mode is MODE and which shows information about the repository
in which @code{default-directory} is located.
@end defun
While it often is enough to have one buffer of a certain Magit mode
per repository, this is not always the case. You might, for example,
want to view the diffs for two commits at the same time. To do so,
......
......@@ -87,6 +87,14 @@ which in turn used the function specified here."
:type 'hook
:options '(magit-maybe-set-dedicated))
(defcustom magit-generate-buffer-name-function
'magit-generate-buffer-name-default-function
"The function used to generate the name for a Magit buffer."
:package-version '(magit . "2.3.0")
:group 'magit-modes
:type '(radio (function-item magit-generate-buffer-name-default-function)
(function :tag "Function")))
(defcustom magit-region-highlight-hook
'(magit-section-update-region magit-diff-update-hunk-region)
"Functions used to highlight the region.
......@@ -526,7 +534,8 @@ Magit buffer is buried."
(defun magit-mode-get-buffer (mode &optional create frame)
(-if-let (topdir (magit-toplevel magit-mode-get-buffer--topdir))
(let ((name (format "*%s: %s*" (substring (symbol-name mode) 0 -5) topdir)))
(let ((name (let ((default-directory topdir))
(funcall magit-generate-buffer-name-function mode))))
(or (--first (with-current-buffer it
(and (equal (buffer-name) name)
(equal (expand-file-name default-directory) topdir)))
......@@ -539,6 +548,16 @@ Magit buffer is buried."
(generate-new-buffer name)))))
(user-error "Not inside a Git repository")))
(defun magit-generate-new-buffer (mode)
(generate-new-buffer (funcall magit-generate-buffer-name-function mode)))
(defun magit-generate-buffer-name-default-function (mode)
(format "*%s: %s*"
(if (eq mode 'magit-status-mode)
"magit"
(substring (symbol-name mode) 0 -5))
default-directory))
(defun magit-mode-bury-buffer (&optional kill-buffer)
"Bury the current buffer.
With a prefix argument, kill the buffer instead.
......
......@@ -154,8 +154,7 @@ optional NODISPLAY is non-nil also display it."
(equal default-directory topdir)))
(buffer-list))
(let ((default-directory topdir))
(generate-new-buffer
(format "*magit-process: %s" topdir))))))
(magit-generate-new-buffer 'magit-process-mode)))))
(with-current-buffer buffer
(if magit-root-section
(when magit-process-log-max
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment