Skip to content

Commit

Permalink
Remember position when refreshing tabulated-list-mode buffers
Browse files Browse the repository at this point in the history
Our derived modes used to bind "g" to the listing command, shadowing
`revert-buffer'.  Now we keep the default binding and instead add the
appropriate refresh functions to `tabulated-list-revert-hook'.  This
preserves the position and avoids some other unnecessary work.  These
functions didn't previously exist.
  • Loading branch information
tarsius committed Mar 23, 2018
1 parent 59bcaff commit 2f03026
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 22 deletions.
25 changes: 14 additions & 11 deletions lisp/magit-repos.el
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,7 @@ control which repositories are displayed."
(if magit-repository-directories
(with-current-buffer (get-buffer-create "*Magit Repositories*")
(magit-repolist-mode)
(setq tabulated-list-entries
(mapcar (-lambda ((id . path))
(let ((default-directory path))
(list path
(vconcat (--map (or (funcall (nth 2 it) id) "")
magit-repolist-columns)))))
(magit-list-repos-uniquify
(--map (cons (file-name-nondirectory (directory-file-name it))
it)
(magit-list-repos)))))
(magit-repolist-refresh)
(tabulated-list-print)
(switch-to-buffer (current-buffer)))
(message "You need to customize `magit-repository-directories' %s"
Expand All @@ -141,7 +132,6 @@ control which repositories are displayed."
(defvar magit-repolist-mode-map
(let ((map (make-sparse-keymap)))
(set-keymap-parent map tabulated-list-mode-map)
(define-key map "g" 'magit-list-repositories)
(define-key map (if (featurep 'jkl) [return] (kbd "C-m"))
'magit-repolist-status)
map)
Expand All @@ -165,11 +155,24 @@ control which repositories are displayed."
(-flatten props)))
magit-repolist-columns)))
(tabulated-list-init-header)
(add-hook 'tabulated-list-revert-hook 'magit-repolist-refresh nil t)
(setq imenu-prev-index-position-function
'magit-imenu--repolist-prev-index-position-function)
(setq imenu-extract-index-name-function
'magit-imenu--repolist-extract-index-name-function))

(defun magit-repolist-refresh ()
(setq tabulated-list-entries
(mapcar (-lambda ((id . path))
(let ((default-directory path))
(list path
(vconcat (--map (or (funcall (nth 2 it) id) "")
magit-repolist-columns)))))
(magit-list-repos-uniquify
(--map (cons (file-name-nondirectory (directory-file-name it))
it)
(magit-list-repos))))))

;;;; Columns

(defun magit-repolist-column-ident (id)
Expand Down
25 changes: 14 additions & 11 deletions lisp/magit-submodule.el
Original file line number Diff line number Diff line change
Expand Up @@ -449,22 +449,12 @@ These sections can be expanded to show the respective commits."
(interactive)
(magit-display-buffer (magit-mode-get-buffer 'magit-submodule-list-mode t))
(magit-submodule-list-mode)
(setq tabulated-list-entries
(-keep (lambda (module)
(let ((default-directory
(expand-file-name (file-name-as-directory module))))
(and (file-exists-p ".git")
(list module
(vconcat
(--map (or (funcall (nth 2 it) module) "")
magit-submodule-list-columns))))))
(magit-list-module-paths)))
(magit-submodule-list-refresh)
(tabulated-list-print))

(defvar magit-submodule-list-mode-map
(let ((map (make-sparse-keymap)))
(set-keymap-parent map magit-repolist-mode-map)
(define-key map "g" 'magit-list-submodules)
map)
"Local keymap for Magit-Submodule-List mode buffers.")

Expand All @@ -480,13 +470,26 @@ These sections can be expanded to show the respective commits."
(-flatten props)))
magit-submodule-list-columns)))
(tabulated-list-init-header)
(add-hook 'tabulated-list-revert-hook 'magit-submodule-list-refresh nil t)
(setq imenu-prev-index-position-function
#'magit-imenu--submodule-prev-index-position-function)
(setq imenu-extract-index-name-function
#'magit-imenu--submodule-extract-index-name-function)
(setq-local bookmark-make-record-function
#'magit-bookmark--submodules-make-record))

(defun magit-submodule-list-refresh ()
(setq tabulated-list-entries
(-keep (lambda (module)
(let ((default-directory
(expand-file-name (file-name-as-directory module))))
(and (file-exists-p ".git")
(list module
(vconcat
(--map (or (funcall (nth 2 it) module) "")
magit-submodule-list-columns))))))
(magit-list-module-paths))))

(defun magit-modulelist-column-path (path)
"Insert the relative path of the submodule."
path)
Expand Down

0 comments on commit 2f03026

Please sign in to comment.