Subject: Re: bug#77138: [PATCH] Add major mode for highlighting .npmrc files

From: Konstantin Kharlamov <[email-masked]>
Date: Sat, 22 Mar 2025 22:25:56 +0300

On Sat, 2025-03-22 at 22:23 +0300, Konstantin Kharlamov wrote:
> On Sat, 2025-03-22 at 22:21 +0300, Konstantin Kharlamov wrote:
> > On Sat, 2025-03-22 at 21:19 +0200, Eli Zaretskii wrote:
> > > > From: Konstantin Kharlamov <[email-masked]>
> > > > Cc: [email-masked], [email-masked]
> > > > Date: Sat, 22 Mar 2025 20:36:42 +0300
> > > > 
> > > > On Sat, 2025-03-22 at 17:41 +0200, Eli Zaretskii wrote:
> > > > > > From: Konstantin Kharlamov <[email-masked]>
> > > > > > Cc: [email-masked]
> > > > > > Date: Sat, 22 Mar 2025 17:29:09 +0300
> > > > > > 
> > > > > > On Sat, 2025-03-22 at 14:26 +0000, Stefan Kangas wrote:
> > > > > > > Konstantin Kharlamov <[email-masked]> writes:
> > > > > > > 
> > > > > > > >  * New Modes and Packages in Emacs 31.1
> > > > > > > > 
> > > > > > > > +** New major modes that don't depend on the tree-
> > > > > > > > sitter
> > > > > > > > library
> > > > > > > 
> > > > > > > Do we really need this explicit headline?
> > > > > > 
> > > > > > I don't have a preference, but I see that just a few lines
> > > > > > below
> > > > > > there'
> > > > > > s a headline about "tree-sitter based new modes", so if we
> > > > > > don't
> > > > > > add
> > > > > > the new headline it might look off.
> > > > > 
> > > > > We mention that a mode is based on tree-sitter because those
> > > > > modes
> > > > > will not be available in Emacs built without tree-sitter.
> > > > 
> > > > Yeah, I understand.
> > > > 
> > > > So, do you want me to change anything here?
> > > 
> > > I think the "that don't depend on the tree-sitter library" part
> > > is
> > > better removed.
> > 
> > Okay, done, patch is attached 😊
> 
> …I haven't reduced the heading there to `***` though.  I am not
> completely sure if it's needed or not. Because again, the "newly
> added
> modes" below all have heading `***`…

Anyway, patch is attached if you want the version with heading reduced.

I also added the bug number to the commit title.
From 7b2f71f81efa3cce6243f742bdc69bff6f4fbc15 Mon Sep 17 00:00:00 2001
From: Konstantin Kharlamov <[email-masked]>
Date: Thu, 20 Mar 2025 19:17:32 +0300
Subject: [PATCH] Add major mode for highlighting .npmrc files (Bug#77138)

* etc/NEWS: mention the new mode.
* lisp/textmodes/conf-mode.el (conf-npmrc-mode-syntax-table): new
variable.
* lisp/textmodes/conf-mode.el (conf-npmrc-mode): new major mode
derived from conf-mode for highlighting .npmrc files.
* lisp/files.el (auto-mode-alist): associate the new mode with .npmrc
filename.
---
 etc/NEWS                    |  3 +++
 lisp/files.el               |  1 +
 lisp/textmodes/conf-mode.el | 14 ++++++++++++++
 3 files changed, 18 insertions(+)

diff --git a/etc/NEWS b/etc/NEWS
index 0797fc03217..5fd23ffa5ed 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1597,6 +1597,9 @@ highlight the fill-column indicators.  By default this is disabled.
 
 * New Modes and Packages in Emacs 31.1
 
+** New major mode 'conf-npmrc-mode'.
+A major mode based on conf-mode purposed for editing ".npmrc" files.
+
 ** New major modes based on the tree-sitter library
 
 *** New major mode 'markdown-ts-mode'.
diff --git a/lisp/files.el b/lisp/files.el
index f85021f0d69..151f20868e7 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -3207,6 +3207,7 @@ auto-mode-alist
     ("\\.properties\\(?:\\.[a-zA-Z0-9._-]+\\)?\\'" . conf-javaprop-mode)
     ("\\.toml\\'" . conf-toml-mode)
     ("\\.desktop\\'" . conf-desktop-mode)
+    ("\\.npmrc\\'" . conf-npmrc-mode)
     ("/\\.redshift\\.conf\\'" . conf-windows-mode)
     ("\\`/etc/\\(?:DIR_COLORS\\|ethers\\|.?fstab\\|.*hosts\\|lesskey\\|login\\.?de\\(?:fs\\|vperm\\)\\|magic\\|mtab\\|pam\\.d/.*\\|permissions\\(?:\\.d/.+\\)?\\|protocols\\|rpc\\|services\\)\\'" . conf-space-mode)
     ("\\`/etc/\\(?:acpid?/.+\\|aliases\\(?:\\.d/.+\\)?\\|default/.+\\|group-?\\|hosts\\..+\\|inittab\\|ksysguarddrc\\|opera6rc\\|passwd-?\\|shadow-?\\|sysconfig/.+\\)\\'" . conf-mode)
diff --git a/lisp/textmodes/conf-mode.el b/lisp/textmodes/conf-mode.el
index 6540cb0813c..246761c332e 100644
--- a/lisp/textmodes/conf-mode.el
+++ b/lisp/textmodes/conf-mode.el
@@ -136,6 +136,13 @@ conf-unix-mode-syntax-table
     table)
   "Syntax table in use in Unix style `conf-mode' buffers.")
 
+(defvar conf-npmrc-mode-syntax-table
+  (let ((table (make-syntax-table conf-mode-syntax-table)))
+    (modify-syntax-entry ?\; "<" table)
+    (modify-syntax-entry ?# "<" table)
+    table)
+  "Syntax table in use in npmrc `conf-mode' buffers.")
+
 (defvar conf-javaprop-mode-syntax-table
   (make-syntax-table conf-unix-mode-syntax-table)
   "Syntax table in use in Java properties buffers.")
@@ -664,6 +671,13 @@ conf-desktop-mode
   (conf-mode-initialize "#" 'conf-desktop-font-lock-keywords)
   (conf-quote-normal nil))
 
+;;;###autoload
+(define-derived-mode conf-npmrc-mode conf-mode "Conf[npmrc]"
+  :syntax-table conf-npmrc-mode-syntax-table
+ "Conf Mode starter for .npmrc files.
+Comments start with `#' and `;'. For details see `conf-mode'."
+ (conf-mode-initialize "#"))
+
 (provide 'conf-mode)
 
 ;;; conf-mode.el ends here
-- 
2.48.1