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#74447: 30.0.92; asm-comment-char cannot be set via dir-local variables Date: Wed, 20 Nov 2024 14:36:42 -0500 Message-ID: References: <87ttc1d8j3.fsf@jklaehn.de> <86a5dtsocn.fsf@gnu.org> Reply-To: Stefan Monnier Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="40641"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 74447@debbugs.gnu.org, Johann =?UTF-8?Q?Kl=C3=A4hn?= To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Nov 20 20:37:24 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 1tDqVw-000AQK-73 for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 20 Nov 2024 20:37:24 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tDqVd-0002EO-FR; Wed, 20 Nov 2024 14:37:05 -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 1tDqVb-0002DU-M5 for bug-gnu-emacs@gnu.org; Wed, 20 Nov 2024 14:37:03 -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 1tDqVb-0006Hj-DH for bug-gnu-emacs@gnu.org; Wed, 20 Nov 2024 14:37:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:References:In-Reply-To:From:To:Subject; bh=XagiJC3lJCBdRQ1pRKwhVVqOdx+tiT/KkYphW6XR64c=; b=a40mdoiO7CRme135LypSs/kURlp5ZzdctyUym0fnMZKP4FRQUB84E6jonnHJGLEFCTEJtxuXtlaHPPtA31BvGmasTDO6yyHf7c1fSqwmw/9p4xFW6nPbjlJI+fddO7E1zxk3VKMBuncTxI3o9SvnvR7+s97RWywgFQjQwqtaPI5/YYiiHt78Qrtl3fzZTDVnPfZBxX1/OQTSgCG36AEzq2Hh5iVkh3WHAHdWzAKWrmVFCVs3u0qVpm/vaApJAjxPqagNkDCwsr5W0DOMyyuEuOYqGn4e+EHWc9dEijlTgTL/LTqXvrvTtEZBz5x9/g0jPRu1Lktx2nfx3WCW6afVVQ==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tDqVa-0004al-8K for bug-gnu-emacs@gnu.org; Wed, 20 Nov 2024 14:37: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: Wed, 20 Nov 2024 19:37:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74447 X-GNU-PR-Package: emacs Original-Received: via spool by 74447-submit@debbugs.gnu.org id=B74447.173213142017642 (code B ref 74447); Wed, 20 Nov 2024 19:37:02 +0000 Original-Received: (at 74447) by debbugs.gnu.org; 20 Nov 2024 19:37:00 +0000 Original-Received: from localhost ([127.0.0.1]:47854 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tDqVY-0004aU-7M for submit@debbugs.gnu.org; Wed, 20 Nov 2024 14:37:00 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:39522) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tDqVU-0004aA-KD for 74447@debbugs.gnu.org; Wed, 20 Nov 2024 14:36:58 -0500 Original-Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 55F85442D03; Wed, 20 Nov 2024 14:36:49 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1732131402; bh=MYZ55LYhNoeHz9r0KSabkU5oIia3dYWkJRBMaaOB4PU=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=T6wSSD7+jL08TXrjd9Y0CO5MIoJTeUujiwyRW67wEFITiKtsQf4hkj9v33fQkuhPq Y99CZC917H5/1jFYm2rNJ2JREtl4VSU5Hu6ij3RYlnF3Hn+I3ko4haAiE6dcfrNKCe No3u4KrXfIviBHNq+X2NU2HBl7VnG6KB6BaN0Pbc3ZadEmtb13Z+gXiX35G//u4Bx8 pR8wex8hP6iJoCLPVAvCkt+gpAG1FOugbicX/0cjgM4VV3Y5uMEaTxFoR1/DrTL84q FEhKR8d4lN2/HN63QVRKJaRYyGMoBJqpImR5UaNhnewKjzdPziaTmDKETkH4LuaH+x vaydeeOS2Y5lw== Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 9BE0F442CFC; Wed, 20 Nov 2024 14:36:42 -0500 (EST) Original-Received: from lechazo (lechon.iro.umontreal.ca [132.204.27.242]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 880E1120489; Wed, 20 Nov 2024 14:36:42 -0500 (EST) In-Reply-To: <86a5dtsocn.fsf@gnu.org> (Eli Zaretskii's message of "Wed, 20 Nov 2024 21:21:28 +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:295699 Archived-At: --=-=-= Content-Type: text/plain >> In `.dir-locals.el' setting `((asm-mode . ((asm-comment-char . 35))))' >> does not have the desired effect. The comment char is still `;' instead >> of `#'. The reason is that when the syntax table is adjusted according >> to the comment char in the body of `asm-mode', the dir-local variables >> haven't been loaded yet: `run-mode-hooks' (which would call >> `hack-local-variables') is only invoked _after_ the `define-derived-mode' >> body, i.e., too late. >> >> I'm using the following workaround: >> >> (defun asm-mode-set-comment-char-from-dir-local-variables () >> "Load `asm-comment-char' from dir-local variables. >> This is a HACK, since in `asm-mode', `run-mode-hooks' (which would call >> `hack-local-variables') is only invoked after the `define-derived-mode' body, >> i.e., too late." >> (let ((enable-local-variables :safe)) >> (hack-dir-local-variables) >> (when-let* ((char (alist-get 'asm-comment-char dir-local-variables-alist))) >> (setq-local asm-comment-char char)))) >> (add-hook 'asm-mode-set-comment-hook #'asm-mode-set-comment-char-from-dir-local-variables) >> >> But maybe there is a more principled approach? > > Stefan, any suggestions? IIRC there are 2 "standard" solutions: - in `asm-mode` use (add-hook 'hack-local-variables-hook #'asm--set-comment-syntax nil t) where `asm--set-comment-syntax` would be a new function that sets the syntax-table according to `asm-comment-char`. - in `asm-mode` move the syntax-table setting code to an `:after-hook` section, as in the patch below. Stefan --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=asm.patch diff --git a/lisp/progmodes/asm-mode.el b/lisp/progmodes/asm-mode.el index d47c525c5f9..76defbf6ac8 100644 --- a/lisp/progmodes/asm-mode.el +++ b/lisp/progmodes/asm-mode.el @@ -125,25 +125,29 @@ asm-mode Special commands: \\{asm-mode-map}" + :after-hook + (progn + (run-hooks 'asm-mode-set-comment-hook) + ;; Make our own local child of `asm-mode-map' + ;; so we can define our own comment character. + (use-local-map (nconc (make-sparse-keymap) asm-mode-map)) + (local-set-key (vector asm-comment-char) #'asm-comment) + (set-syntax-table (make-syntax-table asm-mode-syntax-table)) + (modify-syntax-entry asm-comment-char "< b") + + (setq-local comment-start (string asm-comment-char))) + (setq local-abbrev-table asm-mode-abbrev-table) (setq-local font-lock-defaults '(asm-font-lock-keywords)) (setq-local indent-line-function #'asm-indent-line) ;; Stay closer to the old TAB behavior (was tab-to-tab-stop). (setq-local tab-always-indent nil) - (run-hooks 'asm-mode-set-comment-hook) - ;; Make our own local child of `asm-mode-map' - ;; so we can define our own comment character. - (use-local-map (nconc (make-sparse-keymap) asm-mode-map)) - (local-set-key (vector asm-comment-char) #'asm-comment) - (set-syntax-table (make-syntax-table asm-mode-syntax-table)) - (modify-syntax-entry asm-comment-char "< b") - - (setq-local comment-start (string asm-comment-char)) (setq-local comment-add 1) (setq-local comment-start-skip "\\(?:\\s<+\\|/[/*]+\\)[ \t]*") (setq-local comment-end-skip "[ \t]*\\(\\s>\\|\\*+/\\)") - (setq-local comment-end "")) + (setq-local comment-end "") + )) (defun asm-indent-line () "Auto-indent the current line." --=-=-=--