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#68648: 30.0.50; read-only-mode-hook's are not executed when buffer-read-only is t Date: Thu, 01 Feb 2024 09:17:13 -0500 Message-ID: References: <86a5ov6h9n.fsf@gnu.org> <868r441pn4.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="39299"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: bjorn.bidar@thaodan.de, 68648@debbugs.gnu.org, Stefan Kangas To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Feb 01 15:18:16 2024 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 1rVXtP-000A1Y-BT for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 01 Feb 2024 15:18:15 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rVXt5-0004ik-Fy; Thu, 01 Feb 2024 09:17:55 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rVXt3-0004hP-KR for bug-gnu-emacs@gnu.org; Thu, 01 Feb 2024 09:17:53 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rVXt2-0000N8-KF for bug-gnu-emacs@gnu.org; Thu, 01 Feb 2024 09:17:53 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rVXtC-0004SY-8f for bug-gnu-emacs@gnu.org; Thu, 01 Feb 2024 09:18:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 01 Feb 2024 14:18:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 68648 X-GNU-PR-Package: emacs Original-Received: via spool by 68648-submit@debbugs.gnu.org id=B68648.170679706417116 (code B ref 68648); Thu, 01 Feb 2024 14:18:02 +0000 Original-Received: (at 68648) by debbugs.gnu.org; 1 Feb 2024 14:17:44 +0000 Original-Received: from localhost ([127.0.0.1]:40628 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rVXst-0004Rz-OG for submit@debbugs.gnu.org; Thu, 01 Feb 2024 09:17:44 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:4244) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rVXso-0004Rj-9l for 68648@debbugs.gnu.org; Thu, 01 Feb 2024 09:17:42 -0500 Original-Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id AF00D4416BF; Thu, 1 Feb 2024 09:17:21 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1706797040; bh=fQxLf4DGjJho3dlrFyRRpOaDTE4miyNDRKgx98eZZfA=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=CgxmQ6ZXuUhnMrak5405um80YFSFxnLRnAWSQON+Ylc1pfhCx+o+niSuVrUznyI4w oT7KmhrlE+NWUhWcETOo8YnTEOfV+xq/I0brzIyzsw3WuDWHsONAArmDNK+lTQfHQa dGl6O9CudjqiR9MBd5VtJrpSYFHO7k8KK5jUWwgzb1ewsj2KYWrTGmocDGhyL9Z60L zzox6gpovwfFD0fVeyw07WVu1cmfBWxkDNRIJU0amXgRIErzoPYyfDZeMJpONtJoeS swtsmqjcOBfWMsDeFynNoFYUlnbNVlDumjMeFRSnpNDnEGD/NQj8UhHsvINilhgZ02 CzxJFblcw/mlQ== Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 466124416B6; Thu, 1 Feb 2024 09:17:20 -0500 (EST) Original-Received: from pastel (69-165-153-17.dsl.teksavvy.com [69.165.153.17]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 1B8941201F9; Thu, 1 Feb 2024 09:17:20 -0500 (EST) In-Reply-To: <868r441pn4.fsf@gnu.org> (Eli Zaretskii's message of "Thu, 01 Feb 2024 11:48:31 +0200") 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-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:279291 Archived-At: >> > >> 1. (add-hook 'read-only-mode-hook (lambda () (print "foobar"))) >> > >> 2. open file that is read-only >> > >> 3. foobar should be print but isn't. >> > > That's because read-only-mode is not entered when you visit a >> > > write-protected file. >> > It does look like the mode is entered because when calling >> > read-only-mode it is disabled. I agree that it's far from clear that "read-only-mode is not entered". >> That's only a circumstantial evidence. read-only-mode is a thin >> wrapper around buffer-read-only variable, but setting buffer-read-only >> directly (which is what we do when you visit a write-protected file) >> doesn't invoke the mode function, and thus the mode hook is not run. That's the technical explanation of what happens, but it's not very satisfactory as a justification for why it should happen. >> For the same reason, the setting of view-read-only is not honored in >> the scenario you described. I don't understand what you're trying to say here: emacs --eval '(setq view-read-only t)' -Q /etc/password does put me in `view-mode`, so the setting of `view-read-only` seems to be honored. > Stefan & Stefan, any comments or opinions on this issue? I' debating > whether to do anything (and if so, what) about this, or close this bug > as wontfix. [ This a bug of my own making, when I decided to replace `toggle-read-only` with`read-only-mode`. ] I'd be in favor of replacing the `(setq buffer-read-only t)` with `(read-only-mode 1)`, but it will require other changes: since calling `read-only-mode` will handle `view-read-only`, it might make for a nice simplification, but since the code is fairly complex over there, it might also make things worse. Stefan