refactor(emacs): swap cue for jsonnet
This is the language we are doing mode configuration in at work now. Cue was nice but still ab bit new and jsonnet has been around for a lot longer. Cue also works best with go but we are not doing any of that at work so jsonnet was the winner.
This commit is contained in:
parent
9f7d45b489
commit
92c00ca15c
3 changed files with 2 additions and 121 deletions
|
|
@ -54,7 +54,6 @@
|
|||
(load-file (expand-file-name "src/lang/json.el" user-emacs-directory))
|
||||
(load-file (expand-file-name "src/lang/web.el" user-emacs-directory))
|
||||
(load-file (expand-file-name "src/lang/go.el" user-emacs-directory))
|
||||
(load-file (expand-file-name "src/lang/cue.el" user-emacs-directory))
|
||||
(load-file (expand-file-name "src/lang/docker.el" user-emacs-directory))
|
||||
(load-file (expand-file-name "src/lang/shell.el" user-emacs-directory))
|
||||
(load-file (expand-file-name "src/lang/c.el" user-emacs-directory))
|
||||
|
|
|
|||
|
|
@ -1,120 +0,0 @@
|
|||
;;; cue.el --- AMACS -*- lexical-binding: t -*-
|
||||
;;
|
||||
;; Copyright 2021 Practically.io All rights reserved
|
||||
;;
|
||||
;; Use of this source is governed by a BSD-style
|
||||
;; licence that can be found in the LICENCE file or at
|
||||
;; https://www.practically.io/copyright/
|
||||
|
||||
;; (use-package cue-mode
|
||||
;; :quelpa (cue-mode :fetcher github :repo "jdbaldry/cue-mode")
|
||||
;; :mode "\\.cue\\'")
|
||||
|
||||
;; Hook for user defined code.
|
||||
(defvar cue-mode-hook nil)
|
||||
|
||||
;; Configure keymap.
|
||||
(defvar cue-mode-map
|
||||
(let ((map (make-keymap)))
|
||||
;; TODO: implement buffer formatting.
|
||||
;; (define-key map "C-c C-r" 'cue-format-buffer)
|
||||
map)
|
||||
"Keymap for Cue major mode")
|
||||
|
||||
;; Formatting using `cue fmt`.
|
||||
(defun cue-format()
|
||||
(interactive)
|
||||
(write-region (point-min) (point-max) (buffer-file-name))
|
||||
(shell-command (concat "cue fmt " (buffer-file-name)))
|
||||
(revert-buffer :ignore-auto :noconfirm))
|
||||
|
||||
(defun cue-format-before-save ()
|
||||
"Add this to .emacs to run cue on the current buffer when saving:
|
||||
\(add-hook 'before-save-hook 'cue-format-before-save)."
|
||||
(interactive)
|
||||
(when (eq major-mode 'cue-mode) (cue-format)))
|
||||
|
||||
;; Keyword highlighting.
|
||||
(defconst cue--identifier-regexp "\\(?:\\#\\|\\#_\\|_\\)?[a-zA-Z\$_[:digit:]]+")
|
||||
(defconst cue--closed-identifier-regexp "#_?[a-zA-Z\$_[:digit:]]+")
|
||||
(defconst cue--field-regexp (concat "\\(" cue--identifier-regexp "\\??:\\)"))
|
||||
(defconst cue-font-lock-keywords
|
||||
(let (
|
||||
(keywords-regex (regexp-opt '("package" "import" "true" "false" "for" "in" "if" "let" "div" "mod" "quo" "rem") 'words))
|
||||
(type-regex (regexp-opt '("bool" "string" "int" "null" "float" "bytes" "number" "uint" "uint8" "int8" "uint16" "int16" "rune" "uint32" "int32" "uint64" "int64" "uint128" "int128" "float32" "float64") 'words)))
|
||||
(list
|
||||
`(,keywords-regex . font-lock-builtin-face)
|
||||
`(,cue--closed-identifier-regexp . font-lock-type-face)
|
||||
`(,type-regex . font-lock-constant-face)
|
||||
`(,cue--field-regexp . font-lock-function-name-face)
|
||||
))
|
||||
"Minimal highlighting expressions for Cue major mode")
|
||||
|
||||
;; Indentation.
|
||||
(defun cue-indent-line ()
|
||||
"Indent the current line close to how cuefmt would"
|
||||
(interactive)
|
||||
(beginning-of-line)
|
||||
(if (bobp)
|
||||
;; First line is never indented.
|
||||
(indent-line-to 0)
|
||||
(let ((no-hint t) indent)
|
||||
;; If we are looking at the end of a block, decrease the indent.
|
||||
(if (looking-at "\t*[]}]$")
|
||||
(progn
|
||||
(save-excursion
|
||||
(setq indent (- (current-indentation) 2)))
|
||||
;; Don't go beyond left margin.
|
||||
(if (< indent 0)
|
||||
(setq indent 0)))
|
||||
(save-excursion
|
||||
;; Iterate backwards until we find an indentation hint.
|
||||
(while no-hint
|
||||
(forward-line -1)
|
||||
;; If the previous line opened a block, increase the indent.
|
||||
(if (looking-at ".*[{\\[]$")
|
||||
(progn
|
||||
(setq indent (+ (current-indentation) 2))
|
||||
(setq no-hint nil))
|
||||
;; Else, if the previous line was a field, maintain the indent.
|
||||
(if (looking-at "\t*[[:graph:]]")
|
||||
(progn
|
||||
(setq indent (current-indentation))
|
||||
(setq no-hint nil))
|
||||
;; Else, if we reach the beginning of the file, break.
|
||||
(if (bobp)
|
||||
(setq no-hint nil)))))))
|
||||
;; If we set an indent, indent the current line to it.
|
||||
(if indent
|
||||
(indent-line-to indent)
|
||||
;; Else, set it 0.
|
||||
(indent-line-to 0)))))
|
||||
|
||||
;; Syntax table.
|
||||
(defconst cue-mode-syntax-table
|
||||
(let ((table (make-syntax-table)))
|
||||
;; Cue uses // to delimit comments
|
||||
(modify-syntax-entry ?/ ". 124b" table)
|
||||
(modify-syntax-entry ?\n "> b" table)
|
||||
table)
|
||||
"Syntax table for Cue major mode.")
|
||||
|
||||
(defun cue-mode ()
|
||||
"Major mode for editing Cue (Cuelang) files"
|
||||
(interactive)
|
||||
|
||||
(kill-all-local-variables)
|
||||
(use-local-map cue-mode-map)
|
||||
(set-syntax-table cue-mode-syntax-table)
|
||||
|
||||
(set (make-local-variable 'font-lock-defaults) '(cue-font-lock-keywords))
|
||||
(set (make-local-variable 'indent-line-function) 'cue-indent-line)
|
||||
(setq major-mode 'cue-mode)
|
||||
(setq mode-name "Cue")
|
||||
;; Cue, like Go, uses tabs.
|
||||
(setq indent-tabs-mode t)
|
||||
(run-hooks 'cue-mode-hook))
|
||||
|
||||
(add-to-list 'auto-mode-alist (cons "\\.cue\\'" 'cue-mode))
|
||||
|
||||
(provide 'cue-mode)
|
||||
|
|
@ -10,3 +10,5 @@
|
|||
:ensure t
|
||||
:hook (json-mode . lsp-deferred)
|
||||
:mode "\\.json\\'")
|
||||
|
||||
(use-package jsonnet-mode :ensure t)
|
||||
|
|
|
|||
Loading…
Reference in a new issue