From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Lars Ingebrigtsen Newsgroups: gmane.emacs.devel Subject: Re: master e8488bcc9c: Avoid having font locking triggering unnecessary auto-saving Date: Mon, 09 May 2022 19:40:00 +0200 Message-ID: <87mtfq38r3.fsf@gnus.org> References: <165191796540.22789.3432288633082546349@vcs2.savannah.gnu.org> <20220507100605.B7CA7C051FF@vcs2.savannah.gnu.org> <87fsli7uhf.fsf@gnus.org> <87bkw67rru.fsf@gnus.org> <8735hi7r7k.fsf@gnus.org> <87ilqe4roc.fsf@gnus.org> <83levau0r4.fsf@gnu.org> <87v8ue3b9g.fsf@gnus.org> 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="38018"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) Cc: monnier@iro.umontreal.ca, emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon May 09 19:45:07 2022 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 1no7RT-0009eW-9E for ged-emacs-devel@m.gmane-mx.org; Mon, 09 May 2022 19:45:07 +0200 Original-Received: from localhost ([::1]:51374 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1no7RR-0006op-Eh for ged-emacs-devel@m.gmane-mx.org; Mon, 09 May 2022 13:45:05 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:46346) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1no7Nn-0002nP-My for emacs-devel@gnu.org; Mon, 09 May 2022 13:41:19 -0400 Original-Received: from quimby.gnus.org ([2a01:4f9:2b:f0f::2]:34610) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1no7Ni-0001kP-VD; Mon, 09 May 2022 13:41:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org; s=20200322; h=Content-Transfer-Encoding:Content-Type:MIME-Version:Message-ID :In-Reply-To:Date:References:Subject:Cc:To:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=rqKuXWik7HY+dD0mdQyPYX2hK4c1DpBRYjuWVrdT9BY=; b=S0k7kcOKBKeobXsvX43khXGPuS 2TFAuTEotbbwu4PBzDdWnJFvEix6LKrO2AspuDWjrzrrDmCahVRU319pnPzuuq3z7/5Gp/GD9c0G5 iXVRZVFTAI0mXujCyR0XVhny7q4ATzdS3Nr3qsKAEAz/JnAVxj0vXHpmxLiUSfC53+yk=; Original-Received: from [84.212.220.105] (helo=xo) by quimby.gnus.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1no7Ma-0008L1-78; Mon, 09 May 2022 19:40:06 +0200 Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAABGdBTUEAALGPC/xhBQAAACBj SFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAJ1BMVEWTakWLkExqi2Nc hoJbZWF2mDx0XjacVDa+OS7SWzfaaEvllUL////FmuvDAAAAAWJLR0QMgbNRYwAAAAd0SU1FB+YF CREmIFx1+G4AAAGQSURBVDjLlZFBboNADEXdRYPUHZE4QAknCD1BwgUaafZZVGTLqg65QOgJynCC zhyhXK72eIABkUW/hAT/je3vAcDpKd6mrH1aeIkPcZywv8v3aT4Hio4eikOaZkFFTOcV6V2psVNB 3Uclp3QdKAJpdhxajSShQSyZDuVZpjidHNm9OVCWAM++RkpcMgYk6aeUlHAGD9wk5QscAe4E9MSv 3spzWn+fsQcSbTuB4ljAOQgcD41oOmAV7ug8hyCCUJTjw+2XAQ6CqIo+JSOzCZAqQLL9XV3YaUgD 9L3cgjiTX7n0oskRuRv52kxgLtoOca0RdfDfjW6bthlF6S+SSXvx+x1Ra7i6F+T39ssTrFHDme+E QlCmq5zGWmtr5Z+PogXJZPHw0X6xk6Bix9iFjF6cG3wCCHZVoLsHwNj/VjwAejG6k6ykOdC685fZ robluwRraqq/LTekCoO6/kaCWprLKDejH+oDddCLfgV2tjNW0/+0c+AH4P02gr4PSW0DMNTIHzTL VjTWoZ8QGMnDvun+AJ1S4H6FTqoDAAAAJXRFWHRkYXRlOmNyZWF0ZQAyMDIyLTA1LTA5VDE3OjM4 OjMyKzAwOjAwsmT7BwAAACV0RVh0ZGF0ZTptb2RpZnkAMjAyMi0wNS0wOVQxNzozODozMiswMDow MMM5Q7sAAAAASUVORK5CYII= X-Now-Playing: A Certain Ratio's _Sextet_: "Lucinda" In-Reply-To: <87v8ue3b9g.fsf@gnus.org> (Lars Ingebrigtsen's message of "Mon, 09 May 2022 18:45:47 +0200") Received-SPF: pass client-ip=2a01:4f9:2b:f0f::2; envelope-from=larsi@gnus.org; helo=quimby.gnus.org X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 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:289543 Archived-At: The following builds (from bootstrap), all the tests pass, and it seems to work. But I'd like some more eyeballs on it anyway. =F0=9F=98=93 diff --git a/doc/lispref/buffers.texi b/doc/lispref/buffers.texi index d8cf3d7919..3e3b0bd9f0 100644 --- a/doc/lispref/buffers.texi +++ b/doc/lispref/buffers.texi @@ -541,10 +541,12 @@ Buffer Modification @ref{Text}. =20 @defun buffer-modified-p &optional buffer -This function returns @code{t} if the buffer @var{buffer} has been modified -since it was last read in from a file or saved, or @code{nil} -otherwise. If @var{buffer} is not supplied, the current buffer -is tested. +This function returns non-@code{nil} if the buffer @var{buffer} has +been modified since it was last read in from a file or saved, or +@code{nil} otherwise. If @var{buffer} has been autosaved after +@var{buffer} was last modified, the symbol @code{autosaved} is +returned. If @var{buffer} is not supplied, the current buffer is +tested. @end defun =20 @defun set-buffer-modified-p flag diff --git a/lisp/subr.el b/lisp/subr.el index 01549cc6f7..54c9f35264 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -4594,21 +4594,17 @@ with-silent-modifications someone else, running buffer modification hooks, and other things of that nature." (declare (debug t) (indent 0)) - (let ((modified (make-symbol "modified")) - (tick (make-symbol "tick"))) + (let ((modified (make-symbol "modified"))) `(let* ((,modified (buffer-modified-p)) - (,tick (buffer-modified-tick)) (buffer-undo-list t) (inhibit-read-only t) (inhibit-modification-hooks t)) (unwind-protect (progn ,@body) - ;; We restore the buffer tick count, too, because otherwise - ;; we'll trigger a new auto-save. - (internal--set-buffer-modified-tick ,tick) - (unless ,modified - (restore-buffer-modified-p nil)))))) + (when (or (not ,modified) + (eq ,modified 'autosaved)) + (restore-buffer-modified-p ,modified)))))) =20 (defmacro with-output-to-string (&rest body) "Execute BODY, return the text it sent to `standard-output', as a string= ." diff --git a/src/buffer.c b/src/buffer.c index 6334e197f0..d830943994 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -1376,12 +1376,23 @@ DEFUN ("buffer-local-variables", Fbuffer_local_vari= ables, DEFUN ("buffer-modified-p", Fbuffer_modified_p, Sbuffer_modified_p, 0, 1, 0, - doc: /* Return t if BUFFER was modified since its file was last rea= d or saved. -No argument or nil as argument means use current buffer as BUFFER. */) + doc: /* Return non-nil if BUFFER was modified since its file was la= st read or saved. +No argument or nil as argument means use current buffer as BUFFER. + +If BUFFER has been autosaved after BUFFER was last modified, the +symbol `autosaved' is returned. */) (Lisp_Object buffer) { struct buffer *buf =3D decode_buffer (buffer); - return BUF_SAVE_MODIFF (buf) < BUF_MODIFF (buf) ? Qt : Qnil; + if (BUF_SAVE_MODIFF (buf) < BUF_MODIFF (buf)) + { + if (BUF_AUTOSAVE_MODIFF (buf) =3D=3D BUF_MODIFF (buf)) + return Qautosaved; + else + return Qt; + } + else + return Qnil; } =20 DEFUN ("force-mode-line-update", Fforce_mode_line_update, @@ -1475,16 +1486,19 @@ DEFUN ("restore-buffer-modified-p", Frestore_buffer= _modified_p, recent-auto-save-p from t to nil. Vice versa, if FLAG is non-nil and SAVE_MODIFF>=3Dauto_save_modified we risk changing recent-auto-save-p from nil to t. */ - SAVE_MODIFF =3D (NILP (flag) - /* FIXME: This unavoidably sets recent-auto-save-p to nil. */ - ? MODIFF - /* Let's try to preserve recent-auto-save-p. */ - : SAVE_MODIFF < MODIFF ? SAVE_MODIFF - /* If SAVE_MODIFF =3D=3D auto_save_modified =3D=3D MODIFF, - we can either decrease SAVE_MODIFF and auto_save_modified - or increase MODIFF. */ - : modiff_incr (&MODIFF)); - + if (NILP (flag)) + /* This unavoidably sets recent-auto-save-p to nil. */ + SAVE_MODIFF =3D MODIFF; + else + { + if (EQ (flag, Qautosaved)) + BUF_AUTOSAVE_MODIFF (b) =3D MODIFF; + /* If SAVE_MODIFF =3D=3D auto_save_modified =3D=3D MODIFF, we can ei= ther + decrease SAVE_MODIFF and auto_save_modified or increase + MODIFF. */ + else if (SAVE_MODIFF >=3D MODIFF) + SAVE_MODIFF =3D modiff_incr (&MODIFF); + } return flag; } =20 @@ -6465,5 +6479,7 @@ Functions (implicitly) running this hook are `get-buf= fer-create', defsubr (&Soverlay_put); defsubr (&Srestore_buffer_modified_p); =20 + DEFSYM (Qautosaved, "autosaved"); + Fput (intern_c_string ("erase-buffer"), Qdisabled, Qt); } --=20 (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no