| @@ -2120,35 +2120,40 @@ initializing." | |||||
| (bname (format "*GitWorktree<%s>*" name))) | (bname (format "*GitWorktree<%s>*" name))) | ||||
| (with-current-buffer (get-buffer-create bname) | (with-current-buffer (get-buffer-create bname) | ||||
| (cd root) | (cd root) | ||||
| (let ((trees (git-worktree-get-current-trees))) | |||||
| (setq tabulated-list-entries | |||||
| (mapcar (lambda (e) | |||||
| (list e | |||||
| (vector | |||||
| (concat (file-relative-name (plist-get e :worktree)) | |||||
| "/") | |||||
| (or (plist-get e :branch) "") | |||||
| (plist-get e :head) | |||||
| ))) | |||||
| trees)) | |||||
| (let ((branch-max-size | |||||
| (apply 'max | |||||
| (cl-loop for e in tabulated-list-entries | |||||
| collect (length (elt (cadr e) 1))))) | |||||
| (worktree-max-size | |||||
| (apply 'max | |||||
| (length "Worktree") | |||||
| (cl-loop for e in tabulated-list-entries | |||||
| collect (length (elt (cadr e) 0)))))) | |||||
| (setq tabulated-list-format | |||||
| `[ | |||||
| ("Worktree" ,worktree-max-size t) | |||||
| ("Branch" ,branch-max-size t) | |||||
| ("Head" -1 t) | |||||
| ]))) | |||||
| (git-worktree--set-tabulated-list-mmode-variables) | |||||
| (git-worktree-mode) | (git-worktree-mode) | ||||
| (current-buffer)))) | (current-buffer)))) | ||||
| ;; ((:worktree "/Users/10sr/.dotfiles" :head "5e7457a8d49ef6a517cdf39d038ba5fdf98dc68e" :branch "refs/heads/master") (:worktree "/Users/10sr/.dotfiles/b1" :head "fa7d868076d807692e35f82ae23596c903fd1117" :branch "refs/heads/b1")) | ;; ((:worktree "/Users/10sr/.dotfiles" :head "5e7457a8d49ef6a517cdf39d038ba5fdf98dc68e" :branch "refs/heads/master") (:worktree "/Users/10sr/.dotfiles/b1" :head "fa7d868076d807692e35f82ae23596c903fd1117" :branch "refs/heads/b1")) | ||||
| (defun git-worktree--set-tabulated-list-mmode-variables () | |||||
| "Set variables for `tabulated-list-mode'." | |||||
| (let ((trees (git-worktree-get-current-trees))) | |||||
| (setq tabulated-list-entries | |||||
| (mapcar (lambda (e) | |||||
| (list e | |||||
| (vector | |||||
| (concat (file-relative-name (plist-get e :worktree)) | |||||
| "/") | |||||
| (or (plist-get e :branch) "") | |||||
| (plist-get e :head) | |||||
| ))) | |||||
| trees)) | |||||
| (let ((branch-max-size | |||||
| (apply 'max | |||||
| (cl-loop for e in tabulated-list-entries | |||||
| collect (length (elt (cadr e) 1))))) | |||||
| (worktree-max-size | |||||
| (apply 'max | |||||
| (length "Worktree") | |||||
| (cl-loop for e in tabulated-list-entries | |||||
| collect (length (elt (cadr e) 0)))))) | |||||
| (setq tabulated-list-format | |||||
| `[ | |||||
| ("Worktree" ,worktree-max-size t) | |||||
| ("Branch" ,branch-max-size t) | |||||
| ("Head" -1 t) | |||||
| ])))) | |||||
| (defun git-worktree-open (&optional directory) | (defun git-worktree-open (&optional directory) | ||||
| "Open git worktree list buffer. | "Open git worktree list buffer. | ||||
| @@ -2198,8 +2203,10 @@ initializing." | |||||
| (define-derived-mode git-worktree-mode tabulated-list-mode "Git-Worktrees" | (define-derived-mode git-worktree-mode tabulated-list-mode "Git-Worktrees" | ||||
| "Major mode for browsing recently opened files and directories." | "Major mode for browsing recently opened files and directories." | ||||
| (setq tabulated-list-padding 2) | (setq tabulated-list-padding 2) | ||||
| ;; TODO: Implement revert | |||||
| ;; (add-hook 'tabulated-list-revert-hook 'git-worktree-mode-reload nil t) | |||||
| (add-hook 'tabulated-list-revert-hook | |||||
| 'git-worktree--set-tabulated-list-mmode-variables | |||||
| nil | |||||
| t) | |||||
| (tabulated-list-init-header) | (tabulated-list-init-header) | ||||
| (tabulated-list-print nil nil)) | (tabulated-list-print nil nil)) | ||||