[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: find-file-hook, recenter, scroll-conservatively and save-place
From: |
Gergely Risko |
Subject: |
Re: find-file-hook, recenter, scroll-conservatively and save-place |
Date: |
Fri, 01 Feb 2019 12:18:05 +0100 |
User-agent: |
GNU Emacs with Gnus |
On 2019-02-01 10:04 (Friday), martin rudalics <address@hidden> writes:
> I have no practice with 'save-place-mode' so I can't tell. From my
> experience I can only tell that it's disorienting when reverting a
> buffer doesn't preserve window start.
Thanks for catching this, the current proposal toggles the flag in
save-place's hook even on revert-buffer. Fortunately we have
revert-buffer-in-progress-p, so save-place could do like this:
(defvar-local nce/flagged-for-recenter nil)
(defun nce/flag-for-recenter ()
(when (not revert-buffer-in-progress-p)
(setq-local nce/flagged-for-recenter t)))
BTW, my previous fake implementation had some other bugs too :-(
So if anyone is interested here is a better version (still supposed to
be tested with --no-site-file --no-site-lisp --no-splash):
-=-=-=-=-=-
(save-place-mode 1)
(setq vc-follow-symlinks t)
(setq scroll-margin 3)
(setq scroll-conservatively 101)
(defvar-local nce/flagged-for-recenter nil)
(defun nce/flag-for-recenter ()
(when (not revert-buffer-in-progress-p)
;; (message "setting %s %s" (current-buffer) (selected-window))
(setq-local nce/flagged-for-recenter t)))
(defun nce/recenter-if-flagged (ad-do-it buffer &rest args)
(let ((window (apply ad-do-it buffer args)))
(when (buffer-local-value 'nce/flagged-for-recenter buffer)
(with-selected-window window
(with-current-buffer buffer
;; (message "unsetting %s" (current-buffer))
(setq-local nce/flagged-for-recenter nil)
(condition-case nil (recenter) ('error t)))))
window))
(add-hook 'find-file-hook 'nce/flag-for-recenter)
(advice-add 'display-buffer :around 'nce/recenter-if-flagged)
-=-=-=-=-=-
Martin, I will change save-place to use
`switch-to-buffer-obey-display-actions', as you suggested and will
report back as soon as I have it.
Should I prepare a patch based on these examples, so we have some
existing code to talk about or should we try to come up with something
better than buffer-local variables for passing the info?
Cheers,
Gergely
- Re: find-file-hook, recenter, scroll-conservatively and save-place, martin rudalics, 2019/02/01
- Re: find-file-hook, recenter, scroll-conservatively and save-place,
Gergely Risko <=
- Re: find-file-hook, recenter, scroll-conservatively and save-place, martin rudalics, 2019/02/01
- Re: find-file-hook, recenter, scroll-conservatively and save-place, martin rudalics, 2019/02/01
- Re: find-file-hook, recenter, scroll-conservatively and save-place, Juri Linkov, 2019/02/02