Skip to content

Instantly share code, notes, and snippets.

@davidwalter0
Last active August 16, 2019 01:22
Show Gist options
  • Save davidwalter0/1f859a72352412096208d52b6f9154c8 to your computer and use it in GitHub Desktop.
Save davidwalter0/1f859a72352412096208d52b6f9154c8 to your computer and use it in GitHub Desktop.
emacs: go.mod and go.sum highlighting
;;; package --- mode for go.mod files
;;; Commentary:
;;; font-lock syntax for go.mod files
;;;
(setq vgo-highlights
'(
;;; go.sum
("^\\([^ ]*\\) *[^ ]* h1:*[^ ]*=$" . (1 font-lock-keyword-face))
("^[^ ]* *\\([^ ]*\\) h1:*\\([^ ]*=\\)$" . (1 font-lock-builtin-face))
("^[^ ]* *[^ ]* h1:*\\([^ ]*=\\)$" . (1 font-lock-function-name-face))
("^[^ ]* *[^ ]* h1\\(:\\)*[^ ]*=$" . (1 font-lock-comment-face))
("^[^ ]* *[^ ]* \\(h1\\)*[^ ]*=$" . (1 font-lock-function-name-face))
;; go.mod
("\\()\\).*$" . (1 font-lock-comment-face))
("\\((\\).*$" . (1 font-lock-comment-face))
("\\(=>\\).*$" . (1 font-lock-comment-face))
("\\(//.*\\)$" . (1 font-lock-comment-face))
("=> *\\([^ ]*\\) *.*$" . (1 font-lock-keyword-face))
("^\\(module\\|require\\|exclude\\|replace\\|go\\)" . font-lock-function-name-face)
("\\([^ ]*\\) *=> *\\([^ ]*\\) *.*$" . (1 font-lock-keyword-face))
("^require *\\([^ ]*\\) *[^ ]* *.*$" . (1 font-lock-keyword-face))
("^require *[^ ]* *\\([^ ]*\\) *.*$" . (1 font-lock-builtin-face))
("^exclude *\\([^ ]*\\) *[^ ]* *.*$" . (1 font-lock-keyword-face))
("^exclude *[^ ]* *\\([^ ]*\\) *.*$" . (1 font-lock-builtin-face))
("^.* => *[^ ]* *\\([^ ]*\\)$" . (1 font-lock-builtin-face))
("^\t*\\([^ ]*\\).*//.*$" . (1 font-lock-keyword-face))
("^\t*\\([^ ]*\\).*$" . (1 font-lock-keyword-face))
("^\t*[^ ]* *\\([^ ]*\\) *//.*$" . (1 font-lock-builtin-face))
("^\t*[^ ]* *\\([^ ]*\\)$" . (1 font-lock-builtin-face))
))
(define-derived-mode vgo-mode fundamental-mode "vgo"
"major mode for editing vgo language code."
(setq font-lock-defaults '(vgo-highlights)))
;;; (delete '("\\.mod$\\'" . vgo-mode) auto-mode-alist)
(add-to-list 'auto-mode-alist '("\\go\.mod\\'" . vgo-mode))
(add-to-list 'auto-mode-alist '("\\go\.sum\\'" . vgo-mode))
(provide 'vgo-mode)
@davidwalter0
Copy link
Author

image
image

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