From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Temporarily select-window, without updating mode-line face and cursor fill? Date: Sun, 02 May 2021 22:25:14 -0400 Message-ID: References: <56F746A2-B842-421E-8FBF-EA5E93EA26CE@gmail.com> <83pmya8d49.fsf@gnu.org> <904A57C8-C268-412F-815F-782017F47D5D@gmail.com> <83eeep8w0m.fsf@gnu.org> <81F181EB-D3C1-4619-B42A-1F49321EC544@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="15045"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: Eli Zaretskii , emacs-devel@gnu.org To: JD Smith Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon May 03 04:26:22 2021 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ldOHt-0003qC-P8 for ged-emacs-devel@m.gmane-mx.org; Mon, 03 May 2021 04:26:21 +0200 Original-Received: from localhost ([::1]:36564 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ldOHs-0003Zv-SM for ged-emacs-devel@m.gmane-mx.org; Sun, 02 May 2021 22:26:20 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:35376) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ldOGu-00035I-KW for emacs-devel@gnu.org; Sun, 02 May 2021 22:25:20 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:35877) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ldOGs-0002pf-Iw; Sun, 02 May 2021 22:25:20 -0400 Original-Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id E96F81001FB; Sun, 2 May 2021 22:25:16 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 79B8A1000C4; Sun, 2 May 2021 22:25:15 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1620008715; bh=kJnYvDOZStou4bHrRadJNV1ZQdnwPWltuw+DHQlJud4=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=CzX/A3mSdACQmIvj78Ltd2ZADonDMe8fheKtCuZDtDCZ0Wcy5o9YTa0bCza4DHYFH dMg18zNRhLFTa0q6wtoDDylcgV+ag2IYjbBQhoEtzuih8YHvtmVpxC8sJtH+c/o8T3 Igd+ielCt+rWZojGjAqTiaSeQ4xojaBOwDN5eJ+7c7Rmea7RNCEk69UMyIj3FpxjvG LIe1IwaMfPmAYP1vga/sq83dehKcFyOxr5bZoLFzqHVMZfdptvtA/O5BufXiFRJqLs 2XKCVPLM94hAWkqsA9a4Sp+anVBt8U0r8x/8FoHZbqC77Z4DbgcNnLaqVbIRQjW095 +G4Fg3k2zv4XA== Original-Received: from alfajor (unknown [108.161.125.61]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 4254B1201CD; Sun, 2 May 2021 22:25:15 -0400 (EDT) In-Reply-To: <81F181EB-D3C1-4619-B42A-1F49321EC544@gmail.com> (JD Smith's message of "Sun, 2 May 2021 22:08:49 -0400") Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 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-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:268793 Archived-At: > If you had any concrete suggestions for calculating window positions > (like window-start and window-end, not just buffer positions) in > a non-active window without selecting it, which is superior to my > approach, I=E2=80=99d be happy to hear.=20 We really should simply speed up `line-number-at-pos`. It shouldn't be hard. See below what I do in nlinum.el. Stefan (defvar nlinum--line-number-cache nil) (make-variable-buffer-local 'nlinum--line-number-cache) ;; We could try and avoid flushing the cache at every change, e.g. with: ;; (defun nlinum--before-change (start _end) ;; (if (and nlinum--line-number-cache ;; (< start (car nlinum--line-number-cache))) ;; (save-excursion (goto-char start) (nlinum--line-number-at-pos)))) ;; But it's far from clear that it's worth the trouble. The current simpli= stic ;; approach seems to be good enough in practice. (defun nlinum--after-change (&rest _args) (setq nlinum--line-number-cache nil)) (defun nlinum--line-number-at-pos () "Like `line-number-at-pos' but sped up with a cache. Only works right if point is at BOL." ;; (cl-assert (bolp)) (if nlinum-widen (save-excursion (save-restriction (widen) (forward-line 0) ;In case (point-min) was not at BOL. (let ((nlinum-widen nil)) (nlinum--line-number-at-pos)))) (let ((pos (if (and nlinum--line-number-cache (> (- (point) (point-min)) (abs (- (point) (car nlinum--line-number-cache))))) (funcall (if (> (point) (car nlinum--line-number-cache)) #'+ #'-) (cdr nlinum--line-number-cache) (count-lines (point) (car nlinum--line-number-cache= ))) (line-number-at-pos)))) ;;(assert (=3D pos (line-number-at-pos))) (add-hook 'after-change-functions #'nlinum--after-change nil :local) (setq nlinum--line-number-cache (cons (point) pos)) pos)))