From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Campbell Barton Newsgroups: gmane.emacs.devel Subject: Re: Possible support for buffer local idle timers? Date: Sat, 25 Sep 2021 17:26:52 +1000 Message-ID: References: <83fstz1cyj.fsf@gnu.org> <83ee9j1b7z.fsf@gnu.org> <45045c06-9595-e106-890f-74a25c945876@gmail.com> <834kae1mya.fsf@gnu.org> <838rzqyzrk.fsf@gnu.org> 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="21871"; 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 Sat Sep 25 09:28:04 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 1mU26O-0005Rq-ES for ged-emacs-devel@m.gmane-mx.org; Sat, 25 Sep 2021 09:28:04 +0200 Original-Received: from localhost ([::1]:42552 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mU26K-0005nh-LX for ged-emacs-devel@m.gmane-mx.org; Sat, 25 Sep 2021 03:28:00 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:35386) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mU25V-00058E-Hp for emacs-devel@gnu.org; Sat, 25 Sep 2021 03:27:09 -0400 Original-Received: from mail-pj1-x1033.google.com ([2607:f8b0:4864:20::1033]:54893) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mU25S-0000p5-7t; Sat, 25 Sep 2021 03:27:09 -0400 Original-Received: by mail-pj1-x1033.google.com with SMTP id me1so8561560pjb.4; Sat, 25 Sep 2021 00:27:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=i6EGLrf7hfKMmt9/nR45jEVo4+T9s712Uv8NXgahesc=; b=kSJkk4xfRkL5LANRaDNXhA3graKFxgxhoJtDpNl1LPCkdULZUc4+Ls7V9zezHF6ALP v1f0sYWL+2KeP+5NcL2bquzLvaYuPlFDeknYvSVfBshq2dVvP0QTnb2v2jXNcgQ+Qu/M YUluosKxbxWxNUimAWthjUZKrIboFYwBkWXdg+8Krjs5/6kxG0pmMrEcTz1TWiWim0/w hvpFv3kV7Lqhzup+HqgupcvCclRkWgy1dgV101FDZpkSNgu1kOFT1SaOgjFvsCnCtewY yuFLsf+0tC8JKjA7lARBpu/Rxzhz+YAJP1y+lNzz5Xq3AxYT5zlB7Wgt3xQulPFaSGqS qjFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=i6EGLrf7hfKMmt9/nR45jEVo4+T9s712Uv8NXgahesc=; b=G4fPTxtmvSoYC1pxnu4KsMn/IdzIkyEpK0qaovIOjNQOlDnaSIRHTbeZTS48UBNOXN UoIQJsmMRa+WFUZqmwaP1PHToSm5GbReWPF4cKjOaqPYR8zchWVT2pmHZ0B3uUf4oUNI DwsG5mAvZ60ybXaVcgwW2p8Qd6M5c36qifCcu1VNjAKmdqyRFBzMAuLZgxtvquSCPTHl NNNMSDtHQTZ2XU3XhFv3NpoLJwnJIrr5SMMdKWsXrBvQkYTKESfta+78oNvKJP/BZXtU HKAG6o00JNeOHQDgbZdwWBBmEXYNYr7GFk6cQLCTUm5wCvk6e6LXspgU/nGOql6S/67G w0aw== X-Gm-Message-State: AOAM531fDdwYrGpHRbDc94fKxADQFU0lIH7wcZ67XCjKxCp57RXZF6Oo dMhbfDGR2zZTQhmLpQ/IYVy8TyJJ5/mNWrN7AgtabooAx4s= X-Google-Smtp-Source: ABdhPJzeAPui4C26ClLvMjI7Wl96ZhXp7RaP+7UH2LtrwmXSx5y3Euyxi6gTzTWUkcGy3+a3YrLuiXpzOQVUhX6TPv4= X-Received: by 2002:a17:90a:b117:: with SMTP id z23mr6999636pjq.94.1632554823103; Sat, 25 Sep 2021 00:27:03 -0700 (PDT) In-Reply-To: <838rzqyzrk.fsf@gnu.org> Received-SPF: pass client-ip=2607:f8b0:4864:20::1033; envelope-from=ideasman42@gmail.com; helo=mail-pj1-x1033.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 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_ENVFROM_END_DIGIT=0.25, 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:275443 Archived-At: On Tue, Sep 21, 2021 at 8:44 PM Eli Zaretskii wrote: > > > From: Campbell Barton > > Date: Tue, 21 Sep 2021 20:19:44 +1000 > > Cc: emacs-devel@gnu.org > > > > On Tue, Sep 21, 2021 at 4:07 PM Eli Zaretskii wrote: > > > > > > > Date: Tue, 21 Sep 2021 10:36:05 +1000 > > > > From: Campbell Barton > > > > > > > > > . does the timer start measuring idle time only when the buffer is > > > > > the current buffer, or regardless of that? > > > > > > > > would just go with default behavior of global idle timers since a user > > > > switching buffers will typically reset idle timers. > > > > > > What do you mean by "reset timers" here? > > > > I assume that the the act of switching the buffer will cause Emacs not > > to be idle, so after switching buffers idle timers will begin to run > > again as their deadlines are met. > > No, that is not necessarily true. "Idle" means there's no input for > Emacs to process, but it doesn't mean Emacs is not doing anything. It > could run some timer-related code which switches buffers, for example. Thanks for the info, I have the impression that it would be difficult to implement a buffer local timer that provides the kind of guarantees script authors may expect from a built-in library. Nevertheless I have found a solution for buffer-local-idle-timers, where the global idle timer is created/destroyed as needed. A summary of the solution: - A buffer local window-state-change-hook is used to detect changes to the buffer (enabling the global-idle-timer if the local mode is enabled). - the global-idle-timer will remove itself if it runs on a buffer that doesn't have the minor mode active. - Buffers use a buffer local "dirty" tag so buffers that are activated and lose focus before the idle timer runs will still be refreshed (if they are visible) next time the idle timer is triggered. This is a small package that demonstrates the solution: https://emacs.stackexchange.com/a/68662/2418 -- - Campbell