From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Kangas Newsgroups: gmane.emacs.devel Subject: Re: Temporarily select-window, without updating mode-line face and cursor fill? Date: Tue, 4 May 2021 19:49:25 -0500 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" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="26279"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Eli Zaretskii , emacs-devel@gnu.org To: Stefan Monnier , JD Smith Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed May 05 02:52:43 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 1le5mN-0006jb-2F for ged-emacs-devel@m.gmane-mx.org; Wed, 05 May 2021 02:52:43 +0200 Original-Received: from localhost ([::1]:54524 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1le5mM-0001ag-58 for ged-emacs-devel@m.gmane-mx.org; Tue, 04 May 2021 20:52:42 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:45294) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1le5jG-0007tL-SY for emacs-devel@gnu.org; Tue, 04 May 2021 20:49:31 -0400 Original-Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]:43626) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1le5jE-0008Cw-DM; Tue, 04 May 2021 20:49:30 -0400 Original-Received: by mail-pl1-x632.google.com with SMTP id v20so208705plo.10; Tue, 04 May 2021 17:49:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:in-reply-to:references:mime-version:date:message-id:subject:to :cc; bh=bsGAfH2x/WChyvG+Ai5d/TOdrNDbh3Q00gaXBknF5+c=; b=QLgQp2OvkhaB9vhX0BIcqcoR81xWqf7nq12c5FJNxH34BONaXQDJqhsAJHCq5UDrkV xKZn3pjdlLJZUmes0icZFpBtGDCm6LIsMy9japvWziaN2czknzmAp34goY8YdVI+3OCu HEhJ4oajXrcX23EWPeRUQErlsT/Q2IFb4RXjWcThS8HGRWBkZS1CVe9ENWN8zuTZgBgu 4K1Hmtqr/r+26vHzRNmwVGXN3ZElXPCk76OapX9wqgPb1MKByXssyuowvRg5ALIBMjEB fmSwp9UieUpT//3ODxnzu5t8pzh1d8DmFe9og9kVGHAt2q4b6/ExW94s+DoUxh5QMChZ ueoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:in-reply-to:references:mime-version:date :message-id:subject:to:cc; bh=bsGAfH2x/WChyvG+Ai5d/TOdrNDbh3Q00gaXBknF5+c=; b=JIAhOip+j7FItr1Xe5krut6kcFiPX9K4O2It+lqvV5rqu0eqVDj2zo7ZT0FiiTk730 SXQ2UKyPqFNVL5/bmVAKvEgMSdQCizxhe9h/ta/joaMvPBxvUWdpgUPpX9YhE6hfdJAT YLgqMx9xYD2X9acjOIXIwp9OtECL1rc3DnF1pRDJntji4Y4GOUhPFdSEYlWhaUrICO7p 3LnOHiPoYzm7BK8IHfd8RgSISftc5TcgELVK5CNRV7XiCU9Cirwroite1kotFmg6WvId ucGgvj5JLwrN4p8WA/fkcn/QqnNNK0KTupVcDctW+jnoat39wae/WFF5yFtnfi8rtx2t HZkA== X-Gm-Message-State: AOAM533h5txKqrCcmHZhEIj1FNGIARg1osPkG6PQBBrtJYfleef9Kt4k e5kQG8vR36cC4uUctyBRzpDc0LxH4rcUF96FFEg= X-Google-Smtp-Source: ABdhPJwUxblLjEEZBu8nWdoG7e8zZ1IOA8pr2DGu8eAh78yWTYaFROawe8p+BbPOJ3RwQIbEIUshOYkFP4g9uOCbo9Q= X-Received: by 2002:a17:902:ecc5:b029:ee:cb82:fbc6 with SMTP id a5-20020a170902ecc5b02900eecb82fbc6mr16542913plh.70.1620175766256; Tue, 04 May 2021 17:49:26 -0700 (PDT) Original-Received: from 753933720722 named unknown by gmailapi.google.com with HTTPREST; Tue, 4 May 2021 19:49:25 -0500 In-Reply-To: Received-SPF: pass client-ip=2607:f8b0:4864:20::632; envelope-from=stefankangas@gmail.com; helo=mail-pl1-x632.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:268892 Archived-At: Stefan Monnier writes: > We really should simply speed up `line-number-at-pos`. > It shouldn't be hard. See below what I do in nlinum.el. Interesting, it seems much faster at least in this simplistic test: (benchmark-run 100000 (line-number-at-pos)) => (5.868677411999999 0 0.0) (benchmark-run 100000 (line-number-at-pos)) => (0.9772498589999999 1 0.5954873589998897) Why not to just rename `line-number-at-pos' to `internal--line-number-at-pos and install something much like the below as `line-number-at-pos'? > (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 simplistic > ;; 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 (= pos (line-number-at-pos))) > (add-hook 'after-change-functions #'nlinum--after-change nil :local) > (setq nlinum--line-number-cache (cons (point) pos)) > pos)))