From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#56637: 28.1.90; [FR] Allow a way around font-lock-mode being unconditionally disabled in " *hidden*" buffers Date: Tue, 19 Jul 2022 13:01:38 -0400 Message-ID: References: <874jzdhh5m.fsf@localhost> <83mtd5m54h.fsf@gnu.org> Reply-To: Stefan Monnier Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="19863"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) Cc: 56637@debbugs.gnu.org, yantar92@gmail.com To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Jul 19 19:07:13 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1oDqgj-0004up-Og for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 19 Jul 2022 19:07:13 +0200 Original-Received: from localhost ([::1]:41816 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oDqgi-0004Qv-Iv for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 19 Jul 2022 13:07:12 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:42290) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDqbi-0005ab-Jp for bug-gnu-emacs@gnu.org; Tue, 19 Jul 2022 13:02:08 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:57324) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oDqbi-0002kz-AU for bug-gnu-emacs@gnu.org; Tue, 19 Jul 2022 13:02:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oDqbi-0004OS-3O for bug-gnu-emacs@gnu.org; Tue, 19 Jul 2022 13:02:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 19 Jul 2022 17:02:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 56637 X-GNU-PR-Package: emacs Original-Received: via spool by 56637-submit@debbugs.gnu.org id=B56637.165825011416871 (code B ref 56637); Tue, 19 Jul 2022 17:02:02 +0000 Original-Received: (at 56637) by debbugs.gnu.org; 19 Jul 2022 17:01:54 +0000 Original-Received: from localhost ([127.0.0.1]:55083 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oDqbY-0004O2-PP for submit@debbugs.gnu.org; Tue, 19 Jul 2022 13:01:53 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:56592) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oDqbS-0004Nh-P0 for 56637@debbugs.gnu.org; Tue, 19 Jul 2022 13:01:50 -0400 Original-Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 20B6B802B3; Tue, 19 Jul 2022 13:01:41 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 923C88025B; Tue, 19 Jul 2022 13:01:39 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1658250099; bh=17IF3A27f5fVNdfNjiQ2EJzQuaGUDJ97loSj+AaQI+w=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=JZ/d/6LRb49mKQsvrmUQmp+/OpENbYpSNFogyg8T1hsNGizMHf1yU4iWI2fGjBdUq 6UB2OaU6oDzRG9ToWaVGK/WKO5TtlYzIvv0UmcXQR/iTfKZ+NfIEmC5BAD+igJescG y0k+CWwSYG6Eft4zXKutUm/xINRhcP0Rt9hsNXrwRYXg7a4WCp4sk0y24BmlUumgIw tbUWEHAtsZwheHic0G7F7zLoQrCV/cX9SoPuTb8oqvKO5ry79ek/DVxWxnWhzZ5PRh ev8gFfGZeqXzBw9/YjfW2FILszjnu99LVKkS/zwB/E3c2x21RffnOsKxWM3PXrb4uK HDatpp7CcUUlw== Original-Received: from pastel (unknown [45.72.196.165]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 5546912020A; Tue, 19 Jul 2022 13:01:39 -0400 (EDT) In-Reply-To: <83mtd5m54h.fsf@gnu.org> (Eli Zaretskii's message of "Tue, 19 Jul 2022 19:36:30 +0300") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:237459 Archived-At: >> FWIW, I do think it would be good to remove the rule that font-lock is >> never enabled in temp buffers. > I don't. I think we agree :-) More seriously, I didn't mean to remove it willy-nilly, but that it's a desirable goal and the question is how to get there. We could start by adding a new variable `font-lock-allow-in-temporary-buffer`, which packages could set buffer-locally in those rare temp buffers where they do want to enable font-lock, as in the untested patch below. Of course, the problem in `font-lock-ensure` is orthogonal to this. Stefan diff --git a/lisp/font-core.el b/lisp/font-core.el index f92d1e38306..f74d1d854a0 100644 --- a/lisp/font-core.el +++ b/lisp/font-core.el @@ -78,6 +78,13 @@ font-lock-function ;; The mode for which font-lock was initialized, or nil if none. (defvar font-lock-major-mode) +(defvar-local font-lock-allow-in-temporary-buffer nil + "If non-nil, override the temp-buffer limitation. +Normally `font-lock-mode' cannot be enabled in buffers never intended +to be displayed (i.e. temp buffers and batch mode). +Set this variable to non-nil in those rare buffers where `font-lock-mode' +is needed even though they'll never be displayed.") + (define-minor-mode font-lock-mode "Toggle syntax highlighting in this buffer (Font Lock mode). @@ -131,13 +138,14 @@ font-lock-mode :after-hook (font-lock-initial-fontify) ;; Don't turn on Font Lock mode if we don't have a display (we're running a ;; batch job) or if the buffer is invisible (the name starts with a space). - (when (or noninteractive (eq (aref (buffer-name) 0) ?\s)) + (when (and (or noninteractive (eq (aref (buffer-name) 0) ?\s)) + (not font-lock-allow-in-temporary-buffers)) (setq font-lock-mode nil)) (funcall font-lock-function font-lock-mode) ;; Arrange to unfontify this buffer if we change major mode later. (if font-lock-mode - (add-hook 'change-major-mode-hook 'font-lock-change-mode nil t) - (remove-hook 'change-major-mode-hook 'font-lock-change-mode t))) + (add-hook 'change-major-mode-hook #'font-lock-change-mode nil t) + (remove-hook 'change-major-mode-hook #'font-lock-change-mode t))) ;; Get rid of fontification for the old major mode. ;; We do this when changing major modes.