From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: JD Smith Newsgroups: gmane.emacs.devel Subject: Re: Temporarily select-window, without updating mode-line face and cursor fill? Date: Sun, 2 May 2021 22:08:49 -0400 Message-ID: <81F181EB-D3C1-4619-B42A-1F49321EC544@gmail.com> References: <56F746A2-B842-421E-8FBF-EA5E93EA26CE@gmail.com> <83pmya8d49.fsf@gnu.org> <904A57C8-C268-412F-815F-782017F47D5D@gmail.com> <83eeep8w0m.fsf@gnu.org> Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.80.0.2.43\)) 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="27075"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon May 03 04:09:36 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 1ldO1g-0006x1-3H for ged-emacs-devel@m.gmane-mx.org; Mon, 03 May 2021 04:09:36 +0200 Original-Received: from localhost ([::1]:58242 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ldO1f-0008Sv-4a for ged-emacs-devel@m.gmane-mx.org; Sun, 02 May 2021 22:09:35 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:60324) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ldO11-00082z-6s for emacs-devel@gnu.org; Sun, 02 May 2021 22:08:55 -0400 Original-Received: from mail-qk1-x72a.google.com ([2607:f8b0:4864:20::72a]:46605) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ldO0z-0001Fm-H1; Sun, 02 May 2021 22:08:55 -0400 Original-Received: by mail-qk1-x72a.google.com with SMTP id 76so1943080qkn.13; Sun, 02 May 2021 19:08:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=UD57/xIC6B2Hzu1J5hZgfO1kcekT2RXYrW2r/3zwdBE=; b=MVj7EJscDDgIUQ+fNqx5bfU00q/htESeDKC0kn0i4HSugspc95pmydhqws5VqVsha8 lTA58NvcGTedRMci7ZVu0HWpCQeeUrfUi4eCnulvanQwl/jRO5J5UbIm0/nUkl4EudHw LZVaci/ijcUu8iBswfrCiV8fW5Io+6N/xdrMau+Si9wsSqabmn0eAZR0SUkREQhE+6tN 4e77rkHzgqS32wTIC3MElKxM/XTm9ANFvHymPss7AodpnrANZx7kQZw4p88fLG4x77NL xzWZJB3eY6fX4cQkljuYGr53at/IDN8tmuFZLLCgN7Q20G52+TK9Nj2lGB542U43vpqI V53A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=UD57/xIC6B2Hzu1J5hZgfO1kcekT2RXYrW2r/3zwdBE=; b=b00ZAjwm67CeuOlXVGB/Tx1Z5TScvGRoas7zOAG0734zXdiTy/rnfpEwSGG/Wrlgvc jv2xhSvOAw75xG2+tlW3kn8U2Z0Aey3xhl0ZZTdOCuj3lyPJqNa7GHHhKhi/p6q3MJFO weIqosvA2Tzug7cdHqEgsgS3Ljoiu66BW/55LQgDPx8g60F34OW4TV3ge0sXL8XWKrB+ 5oLAdCbo7UA+kOIoq2u6q0CIjDECXfVBjATGoNIGTsIQr2ma97Gb4j8aDKfAIYQBd7mf Q2LU1gt5vzAfg5ra4nFQmzcOtbmePZB9Zo029ZiqqlR1hkbYuctz9zb8YBa8DXRxoxTk WQqA== X-Gm-Message-State: AOAM5305Xd3y0GRdY+5zwi444Zpi1T9ZeD16JTF2DwsGcko45Pz0ekLq b5kJYXrWCYd+HsPhvzPM6E4r769tk6IjtA== X-Google-Smtp-Source: ABdhPJzV48UNdcsGH+aiCB2BUrFo6Ns6AzgJyl8jZBayDEWYPeG3oHYYjT5Gg7ZckapfkP0u2ZidgQ== X-Received: by 2002:a05:620a:70e:: with SMTP id 14mr17379165qkc.278.1620007731171; Sun, 02 May 2021 19:08:51 -0700 (PDT) Original-Received: from smtpclient.apple (cm-134-228-25-135.buckeyecom.net. [134.228.25.135]) by smtp.gmail.com with ESMTPSA id q23sm8118601qtl.25.2021.05.02.19.08.50 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 02 May 2021 19:08:50 -0700 (PDT) In-Reply-To: <83eeep8w0m.fsf@gnu.org> X-Mailer: Apple Mail (2.3654.80.0.2.43) Received-SPF: pass client-ip=2607:f8b0:4864:20::72a; envelope-from=jdtsmith@gmail.com; helo=mail-qk1-x72a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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:268790 Archived-At: For very large file, line-number-at-pos, which uses count-lines, if far = too slow to be used in a modeline :eval. I suspect this is why the = =E2=80=9C%l=E2=80=9D mode line formatter does not itself use = count-lines. Here=E2=80=99s my analysis of that (on top of some 7yr old = complaints about the speed of line-number-at-pos): = https://emacs.stackexchange.com/questions/3821/a-faster-method-to-obtain-l= ine-number-at-pos-in-large-buffers/64656#64656 Summary: format-mode-line is >10x faster on =E2=80=9Crandom=E2=80=9D = lines, and thousands of times faster for =E2=80=9Cnearby lines=E2=80=9D = (presumably due to caching). The latter is particular important for = rapid scrolling updates.=20 I managed to get this working quite well on large files (like = /usr/dict/words); see https://github.com/jdtsmith/mlscroll. I indeed = use count-lines for incrementing line count from window-start to = window-end, since they are =E2=80=9Cclose=E2=80=9D, and have simplified = the fast line count to: (defun mlscroll-fast-line-number-at-pos (pos &optional win) (let ((old (window-point win))) (set-window-point win pos) (prog1 (string-to-number (format-mode-line "%l" 0 win)) (set-window-point win old)))) 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 > On May 2, 2021, at 2:55 AM, Eli Zaretskii wrote: >=20 >> From: JD Smith >> Date: Sat, 1 May 2021 18:17:46 -0400 >> Cc: emacs-devel@gnu.org >>=20 >> (defun mlscroll-fast-line-number-at-pos (pos &optional win) >> "Line number at position. >> Compute line number at position POS. Uses fast mode-line >> formatting. If WIN is non-nil, find line number at position within >> that window." >> (string-to-number >> (if win >> (let ((old (window-point win))) >> (set-window-point win pos) >> (prog1 >> (format-mode-line "%l" 0 win) >> (set-window-point win old))) >> (save-excursion >> (goto-char pos) >> (format-mode-line "%l" 0))))) >=20 > I don't recommend using format-mode-line for counting lines. Why not > use count-lines instead?