From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Michael Heerdegen Newsgroups: gmane.emacs.devel Subject: Re: set-window-start moves point without scrolling Date: Tue, 19 Mar 2013 17:26:42 +0100 Message-ID: <878v5juzi5.fsf@web.de> References: <87zjy05nwu.fsf@web.de> <83k3p412e4.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1363710418 32416 80.91.229.3 (19 Mar 2013 16:26:58 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 19 Mar 2013 16:26:58 +0000 (UTC) Cc: Magnar Sveen To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Mar 19 17:27:23 2013 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UHzNc-0003kh-Oj for ged-emacs-devel@m.gmane.org; Tue, 19 Mar 2013 17:27:16 +0100 Original-Received: from localhost ([::1]:41366 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UHzNF-0002nG-9s for ged-emacs-devel@m.gmane.org; Tue, 19 Mar 2013 12:26:53 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:46235) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UHzNB-0002n6-OE for emacs-devel@gnu.org; Tue, 19 Mar 2013 12:26:51 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UHzN9-0002fE-Je for emacs-devel@gnu.org; Tue, 19 Mar 2013 12:26:49 -0400 Original-Received: from mout.web.de ([212.227.17.12]:64132) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UHzN9-0002f1-9H for emacs-devel@gnu.org; Tue, 19 Mar 2013 12:26:47 -0400 Original-Received: from drachen.dragon ([89.204.135.124]) by smtp.web.de (mrweb003) with ESMTPSA (Nemesis) id 0MNtP9-1UL0Ry0DON-0072t5; Tue, 19 Mar 2013 17:26:46 +0100 Mail-Followup-To: emacs-devel@gnu.org, Magnar Sveen In-Reply-To: <83k3p412e4.fsf@gnu.org> (Eli Zaretskii's message of "Tue, 19 Mar 2013 05:42:27 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) X-Provags-ID: V02:K0:2CEHhny+ramILRzqWcGkgJysBEioV4loCN3ZLBMa/aE QLk2iscSQlvFIdK1rkja9HDASgusvWlJCWEUAS2hjH6y4sCcOx +THp+gPwMWx+cJKqagGx+Ple1ievIN/Jzox5O4/XBWP+SDSdAY WelDBs5O3DXYTt2epxEMXJy2j/o+9Ar7pEHQTzAd2lljm2m5F9 aKxpRojHc0fjAnLdhW2rtcC8aHIPIPIdOQyXPcYwdE= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 212.227.17.12 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 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-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:157960 Archived-At: Eli Zaretskii writes: > > (progn > > (setq-default scroll-margin 2) > > (pop-to-buffer (get-buffer-create "test")) > > (insert "1\n2\n3") > > (goto-char 1) > > (set-window-start nil (window-start))) > > > > Then, point in buffer "test" is at the beginning of line 3. > Feature. You set the scroll-margin to 2, so Emacs avoids putting > point inside the margin. Ok, I see, thanks. > Does this give you trouble in any real-life situation? Dunno. The background: yesterday, I tried "multiple-cursors" by Magnar Sveen (whom I CC'd): https://github.com/magnars/multiple-cursors.el The idea is, yes, to simulate multiple cursors. To avoid performing of automatic window scrolling when the current editing command is performed at the positions of the "other" cursors, these actions are wrapped in this macro: (defmacro mc/save-window-scroll (&rest forms) "Saves and restores the window scroll position" `(let ((p (set-marker (make-marker) (point))) (start (set-marker (make-marker) (window-start))) (hscroll (window-hscroll))) ,@forms (goto-char p) (set-window-start nil start) (set-window-hscroll nil hscroll) (set-marker p nil) (set-marker start nil))) (the local vars should become uninterned symbols, but that's not related) This code triggers the effect in my example above: point (i.e., the "real" cursor) is moved as a side effect if point was in the first visible window line and scroll-margin > 0. How would a better implementation of this macro look like? Would it be sufficient to use a non-nil third argument for `set-window-start', or would this not reverse automatic scrolling reliably? BTW, I already tried to wrap the `set-window-hscroll' inside `save-excursion' or (let ((scroll-margin 0)) ...), but this doesn't help (I guess because scrolling is performed afterwards while redisplaying.) Thanks so far, Michael.