From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.devel Subject: Re: find-file-hook, recenter, scroll-conservatively and save-place Date: Thu, 31 Jan 2019 22:57:18 +0200 Organization: LINKOV.NET Message-ID: <878sz0o9nd.fsf@mail.linkov.net> References: <877eelupkc.fsf@errge.nilcons.com> <5C52FCDD.7010803@gmx.at> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="234490"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (x86_64-pc-linux-gnu) Cc: Gergely Risko , emacs-devel@gnu.org To: martin rudalics Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Jan 31 22:23:43 2019 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gpJoD-000yt5-UN for ged-emacs-devel@m.gmane.org; Thu, 31 Jan 2019 22:23:42 +0100 Original-Received: from localhost ([127.0.0.1]:32847 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpJoC-0002fL-Nc for ged-emacs-devel@m.gmane.org; Thu, 31 Jan 2019 16:23:40 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:41990) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpJmK-0001B4-8c for emacs-devel@gnu.org; Thu, 31 Jan 2019 16:21:45 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpJmJ-000433-4H for emacs-devel@gnu.org; Thu, 31 Jan 2019 16:21:44 -0500 Original-Received: from common.maple.relay.mailchannels.net ([23.83.214.38]:31791) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gpJmI-00042f-K6 for emacs-devel@gnu.org; Thu, 31 Jan 2019 16:21:43 -0500 X-Sender-Id: dreamhost|x-authsender|jurta@jurta.org Original-Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 033C23E4316; Thu, 31 Jan 2019 21:21:40 +0000 (UTC) Original-Received: from pdx1-sub0-mail-a13.g.dreamhost.com (unknown [100.96.33.121]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 9CCF53E4551; Thu, 31 Jan 2019 21:21:39 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|jurta@jurta.org Original-Received: from pdx1-sub0-mail-a13.g.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384) by 0.0.0.0:2500 (trex/5.16.2); Thu, 31 Jan 2019 21:21:39 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|jurta@jurta.org X-MailChannels-Auth-Id: dreamhost X-Illegal-Chemical: 045fe0ed1291caeb_1548969699834_693098826 X-MC-Loop-Signature: 1548969699833:840065202 X-MC-Ingress-Time: 1548969699833 Original-Received: from pdx1-sub0-mail-a13.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a13.g.dreamhost.com (Postfix) with ESMTP id 5051B8066B; Thu, 31 Jan 2019 13:21:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=jurta.org; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; s=jurta.org; bh=yNrdJFJ4redw7Jft/0TgpmbYcI8=; b=K 7KE5ooH8Hokj7kyDPBaarceZiE4fh/jHQhsdknt+rYLAVA25S9IkSuBUlRzsMY2S xXsU0VJYvHpg8hNx50IXe/Gge4mQb6xR4meMBvy+N6pzDfCPeyhN1L/p/zr7VcYV 9O5K9AGce9KJZvZ1c2ON3bGIapC2Fmok8y46LNPwbI= Original-Received: from mail.jurta.org (m91-129-111-71.cust.tele2.ee [91.129.111.71]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: jurta@jurta.org) by pdx1-sub0-mail-a13.g.dreamhost.com (Postfix) with ESMTPSA id 6B2AF8066A; Thu, 31 Jan 2019 13:21:35 -0800 (PST) X-DH-BACKEND: pdx1-sub0-mail-a13 In-Reply-To: <5C52FCDD.7010803@gmx.at> (martin rudalics's message of "Thu, 31 Jan 2019 14:49:17 +0100") X-VR-OUT-STATUS: OK X-VR-OUT-SCORE: -100 X-VR-OUT-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedtledrjeeigdduhedtucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuggftfghnshhusghstghrihgsvgdpffftgfetoffjqffuvfenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvufhofhffjgfkfgggtgesthdtredttdertdenucfhrhhomheplfhurhhiucfnihhnkhhovhcuoehjuhhrihesjhhurhhtrgdrohhrgheqnecukfhppeeluddruddvledrudduuddrjedunecurfgrrhgrmhepmhhouggvpehsmhhtphdphhgvlhhopehmrghilhdrjhhurhhtrgdrohhrghdpihhnvghtpeeluddruddvledrudduuddrjedupdhrvghtuhhrnhdqphgrthhhpefluhhrihcunfhinhhkohhvuceojhhurhhisehjuhhrthgrrdhorhhgqedpmhgrihhlfhhrohhmpehjuhhriheslhhinhhkohhvrdhnvghtpdhnrhgtphhtthhopehruhgurghlihgtshesghhmgidrrghtnecuvehluhhsthgvrhfuihiivgeptd X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 23.83.214.38 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:232868 Archived-At: >> 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 >> tried. > > Juri, should we handle this somehow? I don't like the default recentering too. I had to fix it with a lot of customization, e.g. (add-hook 'xref-after-jump-hook 'reposition-window) (add-hook 'xref-after-return-hook 'reposition-window) (add-hook 'find-function-after-hook 'reposition-window) ;; Let `C-M-a' (beginning-of-defun) not scroll the window ;; when after jumping point stays within current window bounds (advice-add 'beginning-of-defun :around (lambda (orig-fun &rest args) (let ((w-s (window-start)) (w-e (window-end))) (apply orig-fun args) (when (and ;; Only when used interactively (eq this-command 'beginning-of-defun) ;; And only when jumping outside of window ;; to the center of the window (or (< (point) w-s) (> (point) w-e))) (recenter 11)))) '((name . recenter))) ;; Save and restore window start positions on returning to previous search (setq isearch-push-state-function (lambda () ;; Recenter new search hits outside of window boundaries (when (and isearch-success (not (pos-visible-in-window-p))) ;; reposition-window takes too much time in large buffers (if (or (eq major-mode 'fundamental-mode) (> (buffer-size) 1000000)) (recenter 11) (condition-case nil ;; Prevent errors from reposition-window (reposition-window) (error nil)))) `(lambda (cmd) (when isearch-success (set-window-start nil ,(window-start)))))) > That is, provide 'window-point' and 'window-start' action alist entries > with the former allowing the 'switch-to-buffer-preserve-window-point' > logic (among others) and the latter optionally allowing to recenter. Like switch-to-buffer-preserve-window-point used in dired-find-file? > I don't know how 'save-place' could pass these on to the > 'pop-to-buffer' call in 'find-file' though. Can you think > of any other use cases where these would be helpful? Interesting question. Maybe introduce two new buffer-local variables 'window-point' and 'window-start' that a hook could set and then display-buffer could read and call functions window-point and window-start? These buffer-local values should be used only once and should be reverted to nil after the first use. BTW, a related question: should save-place save window-start as well? It should be easy to implement after this problem is solved.