all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Gergely Risko <gergely@risko.hu>
To: emacs-devel@gnu.org
Subject: Re: find-file-hook, recenter, scroll-conservatively and save-place
Date: Fri, 01 Feb 2019 12:18:05 +0100	[thread overview]
Message-ID: <87ef8ru58y.fsf@errge.nilcons.com> (raw)
In-Reply-To: 5C540BAF.3000602@gmx.at

On 2019-02-01 10:04 (Friday), martin rudalics <rudalics@gmx.at> 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




  reply	other threads:[~2019-02-01 11:18 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-31  9:46 find-file-hook, recenter, scroll-conservatively and save-place Gergely Risko
2019-01-31 13:46 ` Gergely Risko
2019-01-31 14:43   ` Eli Zaretskii
2019-01-31 15:31     ` Gergely Risko
2019-01-31 13:49 ` martin rudalics
2019-01-31 14:32   ` Eli Zaretskii
2019-01-31 18:44     ` martin rudalics
2019-01-31 23:47       ` Gergely Risko
2019-02-01  9:05         ` martin rudalics
2019-01-31 20:57   ` Juri Linkov
2019-01-31 22:45     ` Gergely Risko
2019-02-01  9:05       ` martin rudalics
2019-02-02 21:03       ` Juri Linkov
2019-02-03 20:18         ` Juri Linkov
2019-02-01  9:04     ` martin rudalics
2019-02-01 11:18       ` Gergely Risko [this message]
2019-02-02  9:30         ` martin rudalics

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ef8ru58y.fsf@errge.nilcons.com \
    --to=gergely@risko.hu \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.