Prevent scrolling on magit refresh & toc-org

This commit is contained in:
Henrik Lissner 2020-04-04 00:30:14 -04:00
parent a381f59261
commit 2ceac53421
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 26 additions and 1 deletions

View file

@ -746,7 +746,18 @@ compelling reason, so..."
(use-package! toc-org ; auto-table of contents
:hook (org-mode . toc-org-enable)
:config (setq toc-org-hrefify-default "gh"))
:config
(setq toc-org-hrefify-default "gh")
(defadvice! +org-inhibit-scrolling-a (orig-fn &rest args)
"Prevent the jarring scrolling that occurs when the-ToC is regenerated."
:around #'toc-org-insert-toc
(let ((p (set-marker (make-marker) (point)))
(s (window-start)))
(prog1 (apply orig-fn args)
(goto-char p)
(set-window-start nil s t)
(set-marker p nil)))))
(use-package! org-bullets ; "prettier" bullets

View file

@ -42,6 +42,20 @@
"~/.cache/")
"git/credential/socket")))
;; Prevent scrolling when manipulating magit-status hunks. Otherwise you must
;; reorient yourself every time you stage/unstage/discard/etc a hunk.
;; Especially so on larger projects."
(defvar +magit--pos nil)
(add-hook! 'magit-pre-refresh-hook
(defun +magit--set-window-state-h ()
(setq-local +magit--pos (list (current-buffer) (point) (window-start)))))
(add-hook! 'magit-post-refresh-hook
(defun +magit--restore-window-state-h ()
(when (and +magit--pos (eq (current-buffer) (car +magit--pos)))
(goto-char (cadr +magit--pos))
(set-window-start nil (caddr +magit--pos) t)
(kill-local-variable '+magit--pos))))
;; Magit uses `magit-display-buffer-traditional' to display windows, by
;; default, which is a little primitive. `+magit-display-buffer' marries
;; `magit-display-buffer-fullcolumn-most-v1' with