]> git.eshelyaron.com Git - emacs.git/commitdiff
Add major mode for highlighting npmrc files (Bug#77138)
authorKonstantin Kharlamov <Hi-Angel@yandex.ru>
Thu, 20 Mar 2025 16:17:32 +0000 (19:17 +0300)
committerEshel Yaron <me@eshelyaron.com>
Mon, 31 Mar 2025 08:32:14 +0000 (10:32 +0200)
* 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
files.

(cherry picked from commit 891f51fe118597ffe58d5d817fff693db3188639)

lisp/files.el
lisp/textmodes/conf-mode.el

index 97d6280b5c60e695ce8a28040ff4a1c15a3164fb..d65937ee03fa6002c1259dfc88544e230cf420cf 100644 (file)
@@ -3252,6 +3252,8 @@ ARC\\|ZIP\\|LZH\\|LHA\\|ZOO\\|[JEW]AR\\|XPI\\|RAR\\|CBR\\|7Z\\|SQUASHFS\\)\\'" .
     ("\\.properties\\(?:\\.[a-zA-Z0-9._-]+\\)?\\'" . conf-javaprop-mode)
     ("\\.toml\\'" . conf-toml-mode)
     ("\\.desktop\\'" . conf-desktop-mode)
+    ;; Dot is excluded from npmrc, because global configs may lack it.
+    ("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)
index 6540cb0813c99460a301e5bb5a4c25ca529e705c..246761c332e1b5514a06de29fb6b258972f31d0b 100644 (file)
@@ -136,6 +136,13 @@ not align (only setting space according to `conf-assignment-space')."
     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 @@ For details see `conf-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