[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

find-file-hook, recenter, scroll-conservatively and save-place

From: Gergely Risko
Subject: find-file-hook, recenter, scroll-conservatively and save-place
Date: Thu, 31 Jan 2019 10:46:59 +0100
User-agent: GNU Emacs with Gnus


I'm using save-place in my .emacs and I also set scroll-conservatively
to 101 with a scroll-margin of 3.

I like the smooth scrolling experience, but I would prefer to have new
files open at their previous save-place location recentered in their
window, not at the end.  This works as intended with
scroll-conservatively 0, but breaks with scroll-conservatively 101.

I did the following digging:
  - scroll-conservatively achieves its behavior in redisplay
    asynchronously to find-file-hook, therefore any kind of dynamic
    binding hackery of setting scroll-conservatively temporarily to 0
    doesn't work for me in save-place,
  - recenter refuses to run when the current window is not showing the
    current buffer (makes sense),
  - find-file-hook is ran with the new buffer as current, but the window
    is not changed to the new buffer yet.

If I have this in find-file-hook:

(defun test ()
  (message "foobar: %s %s" (current-buffer) (selected-window))

And I open new-file.c while standing in old-file.c, I receive this:

Debugger entered--returning value: "foobar: old-file.c #<window 85 on 

My question: is there a better hook that we could use for save-place
restoration purposes?

I also looked into xref, and there the behavior is much better: the
(recenter) is included in the default configuration of
xref-after-jump-hook and it works in all the scenarios that I have


reply via email to

[Prev in Thread] Current Thread [Next in Thread]