Skip to content

Instantly share code, notes, and snippets.

@eddieh
Created July 23, 2025 02:46
Show Gist options
  • Save eddieh/4b2152c15ea9ec10f1b286a900c48f76 to your computer and use it in GitHub Desktop.
Save eddieh/4b2152c15ea9ec10f1b286a900c48f76 to your computer and use it in GitHub Desktop.
Modify Generate Your Projects (GYP) files .gyp & .gypi handling in Emacs 30.1
(defun e/modify-gyp-syntax ()
"Generate Your Projects (GYP) files .gyp & .gypi files look like JSON,
but can have # comments and single quotes are permitted as string
delimiters. It also permits trailing commas at the end of list and
dictionary content."
(when (and (stringp buffer-file-name)
(string-match "\\.gypi?\\'" buffer-file-name))
(let ((gyp-syntax-table (copy-syntax-table js-mode-syntax-table)))
(modify-syntax-entry ?# "<" gyp-syntax-table)
(modify-syntax-entry ?\n ">" gyp-syntax-table)
(modify-syntax-entry ?\' "\"" gyp-syntax-table)
(set-syntax-table gyp-syntax-table))))
(add-to-list 'auto-mode-alist '("\\.gypi?\\'" . js-json-mode))
(add-hook 'js-json-mode-hook (lambda ()
(e/modify-gyp-syntax)
(editorconfig-apply)))
@eddieh
Copy link
Author

eddieh commented Jul 23, 2025

Also applies EditorConfig rules manually since the built-in editorconfig-mode and js-json-mode don't seem to like each other.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment