From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Dima Kogan Newsgroups: gmane.emacs.devel Subject: Re: Clarification about auto-revert-mode and inotify Date: Tue, 21 Oct 2014 10:59:29 -0700 Message-ID: <878uk9s3mh.fsf@secretsauce.net> References: <87vbnd9aab.fsf@secretsauce.net> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1413914574 9406 80.91.229.3 (21 Oct 2014 18:02:54 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 21 Oct 2014 18:02:54 +0000 (UTC) Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Oct 21 20:02:48 2014 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 1Xgdlb-0005E3-W8 for ged-emacs-devel@m.gmane.org; Tue, 21 Oct 2014 20:02:44 +0200 Original-Received: from localhost ([::1]:52835 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xgdlb-0003NV-Jn for ged-emacs-devel@m.gmane.org; Tue, 21 Oct 2014 14:02:43 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:60205) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XgdlG-0003MG-II for emacs-devel@gnu.org; Tue, 21 Oct 2014 14:02:28 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XgdlB-0000Xc-6p for emacs-devel@gnu.org; Tue, 21 Oct 2014 14:02:22 -0400 Original-Received: from out3-smtp.messagingengine.com ([66.111.4.27]:54178) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XgdlB-0000XW-30 for emacs-devel@gnu.org; Tue, 21 Oct 2014 14:02:17 -0400 Original-Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by gateway2.nyi.internal (Postfix) with ESMTP id 720F420E21 for ; Tue, 21 Oct 2014 14:02:16 -0400 (EDT) Original-Received: from frontend1 ([10.202.2.160]) by compute3.internal (MEProxy); Tue, 21 Oct 2014 14:02:16 -0400 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=x-sasl-enc:references:from:to:cc:subject :date:in-reply-to:message-id:mime-version:content-type; s= smtpout; bh=NsHbJjjQREZmyykAvRHUMwmgiXA=; b=jkUOI6ORwjMXVLsJOSYc FHvkjSRTPXlTFhcadvgqGxtFZoO6bVSIR/KIR9qy4iPIn4rpLc7va7+G+3tVTyms cuqUjAzJRBgJg5/Iak/hb3VlXUgRfiqZRnB6N8MMwyNdyCMYfxXBy53FWx5mpntm 65K6H4ZN15DHqDkBEeXSm/M= X-Sasl-enc: UqaWBYy/afQWT4WQm993PYFNpa0uHt2MbiaGCd0M9CLH 1413914536 Original-Received: from shorty.local (unknown [23.243.192.221]) by mail.messagingengine.com (Postfix) with ESMTPA id 27B27C00008; Tue, 21 Oct 2014 14:02:16 -0400 (EDT) Original-Received: from ip6-localhost ([::1] helo=shorty.local) by shorty.local with esmtp (Exim 4.82_1-5b7a7c0-XX) (envelope-from ) id 1Xgdl8-00043v-UJ; Tue, 21 Oct 2014 11:02:14 -0700 In-reply-to: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 66.111.4.27 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:175657 Archived-At: --=-=-= Content-Type: text/plain Stefan Monnier writes: >> NEWS; does this mean simply that auto-revert is more efficient? > > Indeed, IIUC the current auto-revert-mode implementation only uses the > file-notification code to reduce the amount of polling, but the revert > itself is still only performed from the 5s timer. > > I don't think there's a strong technical reason for that, OK. I'm attaching a prototype patch to fix this. It updates the buffer immediately when a change is detected, unless the previous such update happened very recently. If it DID happen very recently, the normal timer-based update kicks in later. Is such a patch reasonable? If so, I'll add the proper comments and docstrings, and resubmit it. dima --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=emacs_notify_immediate_prototype.patch diff --git a/lisp/autorevert.el b/lisp/autorevert.el index f1074e2..00e1664 100644 --- a/lisp/autorevert.el +++ b/lisp/autorevert.el @@ -531,6 +533,15 @@ will use an up-to-date value of `auto-revert-interval'" ;; Fallback to file checks. (set (make-local-variable 'auto-revert-use-notify) nil)))) + + +(defvar auto-revert-notify-lockout-timer nil + "Lockout timer used by Auto-Revert Mode.") +(make-variable-buffer-local 'auto-revert-notify-lockout-timer) + +(defvar auto-revert-notify-lockout-interval 3 + "Lockout interval for the notify timers") + (defun auto-revert-notify-handler (event) "Handle an EVENT returned from file notification." (with-demoted-errors @@ -566,6 +577,15 @@ will use an up-to-date value of `auto-revert-interval'" (file-name-nondirectory buffer-file-name))))) ;; Mark buffer modified. (setq auto-revert-notify-modified-p t) + + (unless (timerp auto-revert-notify-lockout-timer) + (auto-revert-handler 1) + + (setq auto-revert-notify-lockout-timer + (run-with-timer auto-revert-notify-lockout-interval nil + (lambda () + (setq auto-revert-notify-lockout-timer nil))))) + ;; No need to check other buffers. (cl-return))))))))) --=-=-=--