enhanced magit navigation, added magit-todos

This commit is contained in:
2023-05-08 18:11:44 +02:00
parent 523e0675fb
commit 7dd3454ab2
3 changed files with 88 additions and 73 deletions

View File

@@ -1,87 +1,102 @@
;; *** Magit ;; *** Magit
;; TODO: add blamer.el (https://github.com/Artawower/blamer.el), currently fails to install (2023/05/08)
;; Not much to say about Magit ;; Not much to say about Magit
(use-package magit (use-package magit
:ensure t :ensure t
:config
(defun tvd-magit-status () :init
"Always call `magit-status' with prefix arg." (use-package magit-todos)
(interactive)
(let ((current-prefix-arg t))
(call-interactively 'magit-status)))
;; (with-eval-after-load 'info :config
;; (info-initialize) (magit-todos-mode)
;; (add-to-list 'Info-directory-list
;; (expand-file-name (concat "~/.emacs.d/lisp/magit-"
;; tvd-magit-revision
;; "/Documentation/"))))
(setq magit-view-git-manual-method 'woman)
(defalias 'git 'magit-status) (defun tvd-magit-status ()
(defalias 'gitlog 'magit-log-buffer-file) "Always call `magit-status' with prefix arg."
(interactive)
(let ((current-prefix-arg t))
(call-interactively 'magit-status)))
;; configure magit (setq magit-view-git-manual-method 'woman)
(with-eval-after-load 'magit
(dolist (dir (list (expand-file-name "~/dev/D/github")
(expand-file-name "~/fits/git")
(expand-file-name "~/dev")))
(when (file-exists-p dir)
(add-to-list 'magit-repository-directories (cons dir 1))))
(setq magit-completing-read-function 'magit-ido-completing-read)
;; use timestamps in log buffers (defalias 'git 'magit-status)
(setq magit-log-margin '(t "%Y-%m-%d " magit-log-margin-width t 18)) (defalias 'gitlog 'magit-log-buffer-file)
;; navigate magit buffers as I do everywhere else, I do not automatically (defun tvd-magit-cycle-down()
;; cycle/decycle though, the magit defaults are absolutely sufficient. "hide current section, jump down to the next and show it"
(define-key magit-mode-map (kbd "<C-down>") 'magit-section-forward-sibling) (interactive)
(define-key magit-mode-map (kbd "<C-up>") 'magit-section-backward-sibling) (magit-section-hide (magit-current-section))
(define-key magit-mode-map (kbd "<delete>") 'magit-delete-thing)) (magit-section-forward-sibling)
(magit-section-show (magit-current-section)))
;; one thing though: on startup it bitches about git version, but it (defun tvd-magit-cycle-up()
;; works nevertheless. So I disable this specific warning. "hide current section, jump up to the next and show it"
(interactive)
(magit-section-hide (magit-current-section))
(magit-section-backward-sibling)
(magit-section-show (magit-current-section)))
(defun tvd-ignore-magit-warnings-if-any () ;; configure magit
(interactive) (with-eval-after-load 'magit
(when (get-buffer "*Warnings*") (dolist (dir (list (expand-file-name "~/dev/D/github")
(with-current-buffer "*Warnings*" (expand-file-name "~/fits/git")
(goto-char (point-min)) (expand-file-name "~/dev")))
(when (re-search-forward "Magit requires Git >=") (when (file-exists-p dir)
(kill-buffer-and-window))))) (add-to-list 'magit-repository-directories (cons dir 1))))
(setq magit-completing-read-function 'magit-ido-completing-read)
(add-hook 'after-init-hook 'tvd-ignore-magit-warnings-if-any t) ;; use timestamps in log buffers
(setq magit-log-margin '(t "%Y-%m-%d " magit-log-margin-width t 18))
;; now, THIS is the pure genius me: hit "ls in magit-status buffer ;; navigate magit buffers as I do in org-mode, that is going down
;; and end up in a dired buffer of current repository. The default ;; hides the current sibling, and vice versa
;; binding for this is C-M-i, which is not memorizable, while "ls" (define-key magit-mode-map (kbd "<C-down>") 'tvd-magit-cycle-down)
;; is. That is, 'l' is a prefix command leading to magit-log-popup (define-key magit-mode-map (kbd "<C-up>") 'tvd-magit-cycle-up)
;; and 's' is undefined, which I define here, which then jumps to (define-key magit-mode-map (kbd "<delete>") 'magit-delete-thing))
;; dired.
;; see: https://github.com/magit/magit/wiki/Converting-popup-modifications-to-transient-modifications#adding-an-action
(transient-append-suffix 'magit-log "l"
'("s" "dired" magit-dired-jump))
;; after an exhausting discussion on magit#3139 I use this function ;; one thing though: on startup it bitches about git version, but it
;; to (kind of) switch to another repository from inside magit-status. ;; works nevertheless. So I disable this specific warning.
(defun tvd-switch-magit-repo ()
(interactive)
(let ((dir (magit-read-repository)))
(magit-mode-bury-buffer)
(magit-status dir)))
(define-key magit-mode-map (kbd "C") 'tvd-switch-magit-repo)
;; via (defun tvd-ignore-magit-warnings-if-any ()
;; http://manuel-uberti.github.io/emacs/2018/02/17/magit-bury-buffer/: (interactive)
;; a great enhancement, when closing the magit status buffer, ALL (when (get-buffer "*Warnings*")
;; other possibly still remaining magit buffers will be killed as (with-current-buffer "*Warnings*"
;; well AND the window setup will be restored. (goto-char (point-min))
(defun tvd-kill-magit-buffers() (when (re-search-forward "Magit requires Git >=")
"Restore window setup from before magit and kill all magit buffers." (kill-buffer-and-window)))))
(interactive)
(let ((buffers (magit-mode-get-buffers)))
(magit-restore-window-configuration)
(mapc #'kill-buffer buffers)))
(define-key magit-status-mode-map (kbd "q") #'tvd-kill-magit-buffers)) (add-hook 'after-init-hook 'tvd-ignore-magit-warnings-if-any t)
;; now, THIS is the pure genius me: hit "ls in magit-status buffer
;; and end up in a dired buffer of current repository. The default
;; binding for this is C-M-i, which is not memorizable, while "ls"
;; is. That is, 'l' is a prefix command leading to magit-log-popup
;; and 's' is undefined, which I define here, which then jumps to
;; dired.
;; see: https://github.com/magit/magit/wiki/Converting-popup-modifications-to-transient-modifications#adding-an-action
(transient-append-suffix 'magit-log "l"
'("s" "dired" magit-dired-jump))
;; after an exhausting discussion on magit#3139 I use this function
;; to (kind of) switch to another repository from inside magit-status.
(defun tvd-switch-magit-repo ()
(interactive)
(let ((dir (magit-read-repository)))
(magit-mode-bury-buffer)
(magit-status dir)))
(define-key magit-mode-map (kbd "C") 'tvd-switch-magit-repo)
;; via
;; http://manuel-uberti.github.io/emacs/2018/02/17/magit-bury-buffer/:
;; a great enhancement, when closing the magit status buffer, ALL
;; other possibly still remaining magit buffers will be killed as
;; well AND the window setup will be restored.
(defun tvd-kill-magit-buffers()
"Restore window setup from before magit and kill all magit buffers."
(interactive)
(let ((buffers (magit-mode-get-buffers)))
(magit-restore-window-configuration)
(mapc #'kill-buffer buffers)))
(define-key magit-status-mode-map (kbd "q") #'tvd-kill-magit-buffers))

View File

@@ -185,11 +185,11 @@ _k_: kill (C-k) _s_: split _{_: wrap with { }
;; Jump to the beginning of following balanced expression. If ;; Jump to the beginning of following balanced expression. If
;; there is no following expression on the current level, jump ;; there is no following expression on the current level, jump
;; one level up backward, effectively doing sp-backward-up-sexp. ;; one level up backward, effectively doing sp-backward-up-sexp.
("C-S-<left>" . 'sp-next-sexp) ("C-S-<left>" . 'sp-previous-sexp)
;; Jump to the end of the previous balanced expression. If there ;; Jump to the end of the previous balanced expression. If there
;; is no previous expression on the current level, jupm one level ;; is no previous expression on the current level, jupm one level
;; up forward, effectively doing sp-up-sexp. ;; up forward, effectively doing sp-up-sexp.
("C-S-<right>" . 'sp-previous-sexp) ("C-S-<right>" . 'sp-next-sexp)
;; comment the whole sexp ;; comment the whole sexp
(";" . 'tvd-lisp-comment) (";" . 'tvd-lisp-comment)

View File

@@ -164,7 +164,7 @@
'(custom-safe-themes '(custom-safe-themes
'("7f1d414afda803f3244c6fb4c2c64bea44dac040ed3731ec9d75275b9e831fe5" default)) '("7f1d414afda803f3244c6fb4c2c64bea44dac040ed3731ec9d75275b9e831fe5" default))
'(package-selected-packages '(package-selected-packages
'(howm tiny tramp dictcc beacon which-key goto-last-change browse-kill-ring fringe-current-line swiper smex undo-tree fic-mode cmake-mode yaml-mode windresize web-mode use-package tablist solarized-theme smartparens rust-mode projectile persistent-scratch org-bullets markdown-mode magit iedit ibuffer-vc ibuffer-tramp hydra htmlize highlight-indentation go-mode eyebrowse elmacro dumb-jump dired-ranger dired-k dired-filter default-text-scale change-inner buffer-move)) '(blamer howm tiny tramp dictcc beacon which-key goto-last-change browse-kill-ring fringe-current-line swiper smex undo-tree fic-mode cmake-mode yaml-mode windresize web-mode use-package tablist solarized-theme smartparens rust-mode projectile persistent-scratch org-bullets markdown-mode magit iedit ibuffer-vc ibuffer-tramp hydra htmlize highlight-indentation go-mode eyebrowse elmacro dumb-jump dired-ranger dired-k dired-filter default-text-scale change-inner buffer-move))
'(safe-local-variable-values '((ruby-indent-level 4))) '(safe-local-variable-values '((ruby-indent-level 4)))
'(warning-suppress-types '((comp)))) '(warning-suppress-types '((comp))))