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 00:47:01 +0100 [thread overview]
Message-ID: <87imy4tmoa.fsf@errge.nilcons.com> (raw)
In-Reply-To: 5C534206.7020100@gmx.at
On 2019-01-31 19:44 (Thursday), martin rudalics <rudalics@gmx.at> writes:
> When 'display-buffer' finds a '(window-start . recenter) ALIST entry
> it would call 'recenter' after assigning the window buffer.
I reproduced this behavior with advices and hooks in current Emacs, so
we can play with it. This is a self-contained ~/.emacs (that I'm
testing 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 ()
(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)
(setq-local nce/flagged-for-recenter nil)
(with-selected-window window
(with-current-buffer buffer
(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)
-=-=-=-=-=-=-=-=-=-=-
It works quite well and it's a lot better than my previous find-file
based solution (sent to Eli), because we only need one advice on
display-buffer and not on all the various find file stuff.
I only discovered one issue, startup.el contains this regarding
command line parsing:
-=-=-=-=-=-=-=-=-=-=-
(let ((displayable-buffers-len (length displayable-buffers))
;; `nondisplayed-buffers-p' is true if there exist buffers
;; in `displayable-buffers' that were not displayed to the
;; user.
(nondisplayed-buffers-p nil))
(when (> displayable-buffers-len 0)
(switch-to-buffer (car displayable-buffers))) <------
(when (> displayable-buffers-len 1)
(switch-to-buffer-other-window (car (cdr displayable-buffers)))
;; Focus on the first buffer.
(other-window -1))
(when (> displayable-buffers-len 2)
-=-=-=-=-=-=-=-=-=-=-
Here, the second file is properly recenterd, because it uses
switch-to-buffer-other-window (so our display-buffer is called), but
the first file is simply displayed with switch-to-buffer. So I guess
we would have to put a recenter here in startup.el conditional on the
buffer-local variable that was meant to display-buffer by the
save-place hook. Or maybe replace the marked switch-to-buffer call
with: (display-buffer (...) '(display-buffer-same-window))
Gergely
next prev parent reply other threads:[~2019-01-31 23:47 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 [this message]
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
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87imy4tmoa.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 public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).