Commit 32c731ba authored by Jonas Bernoulli's avatar Jonas Bernoulli

Preserve visibility cache when killing buffers

The section visibility cache is stored in a buffer-local value.
For `magit-status-mode' and `magit-refs-mode' preserve that value
using a repository-local value when killing the buffer and restore
the buffer-local value when recreating the buffer.

Other modes are not supported because they contain no sections that
benefit from the visibility cache and/or because it is possible for
multiple buffers with that mode to exist per repository.
parent 57ba09e4
......@@ -265,7 +265,8 @@ Changes since v2.11.0
* The section visibility cache can now also remember that a section
should be expanded instead of being hidden when that is the default
and the section reappears, not just that it should be hidden instead
of being shown. #2780
of being shown. For `magit-status-mode' and `magit-refs-mode'
buffers the cache now persists when killing the buffer. #2780
* The new option `magit-section-cache-visibility-types' lets users
choose for which section types the visibility cache should be done.
......@@ -537,7 +537,8 @@ Magit is documented in info node `(magit)'."
(linum-mode -1))
(when (and (fboundp 'nlinum-mode)
(bound-and-true-p global-nlinum-mode))
(nlinum-mode -1)))
(nlinum-mode -1))
(add-hook 'kill-buffer-hook 'magit-preserve-section-visibility-cache))
(defvar-local magit-region-overlays nil)
......@@ -778,7 +779,8 @@ thinking a buffer belongs to a repo that it doesn't.")
(buffer (generate-new-buffer name)))
(with-current-buffer buffer
(setq magit--default-directory default-directory)
(setq magit-buffer-locked-p (and value t)))
(setq magit-buffer-locked-p (and value t))
(magit-restore-section-visibility-cache mode))
(when magit-uniquify-buffer-names
(add-to-list 'uniquify-list-buffers-directory-modes mode)
(with-current-buffer buffer
......@@ -231,7 +231,8 @@ Type \\[magit-reset] to reset `HEAD' to the commit at point.
(format "%s %s" ref (mapconcat #'identity args " ")))
(magit-insert-section (branchbuf)
(run-hooks 'magit-refs-sections-hook)))
(run-hooks 'magit-refs-sections-hook))
(add-hook 'kill-buffer-hook 'magit-preserve-section-visibility-cache))
;;; Commands
......@@ -35,6 +35,8 @@
(require 'magit-utils)
(declare-function magit-maybe-make-margin-overlay 'magit-log)
(declare-function magit-repository-local-get 'magit-mode)
(declare-function magit-repository-local-set 'magit-mode)
(defvar magit-keep-region-overlay)
;;; Options
......@@ -1022,6 +1024,17 @@ invisible."
((string-match-p "\\`\\.\\." value) "..@{push}")
(t "@{push}..")))))
(defun magit-preserve-section-visibility-cache ()
(when (derived-mode-p 'magit-status-mode 'magit-refs-mode)
(cons major-mode 'magit-section-visibility-cache)
(defun magit-restore-section-visibility-cache (mode)
(setq magit-section-visibility-cache
(cons mode 'magit-section-visibility-cache))))
;;; Utilities
(cl-defun magit-section-selected-p (section &optional (selection nil sselection))
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