|
35 | 35 | "Major mode for editing JSON files."
|
36 | 36 | :group 'js)
|
37 | 37 |
|
| 38 | +;;;###autoload |
| 39 | +(defconst json-mode-standard-file-ext '(".json" ".jsonld") |
| 40 | + "List of JSON file extensions.") |
| 41 | + |
| 42 | +;; This is to be sure the customization is loaded. Otherwise, |
| 43 | +;; autoload discards any defun or defcustom. |
| 44 | +;;;###autoload |
| 45 | +(defsubst json-mode--update-auto-mode (filenames) |
| 46 | + "Update the `json-mode' entry of `auto-mode-alist'. |
| 47 | +
|
| 48 | +FILENAMES should be a list of file as string. |
| 49 | +Return the new `auto-mode-alist' entry" |
| 50 | + (let* ((new-regexp |
| 51 | + (rx-to-string |
| 52 | + `(seq (eval |
| 53 | + (cons 'or |
| 54 | + (append json-mode-standard-file-ext |
| 55 | + ',filenames))) eot))) |
| 56 | + (new-entry (cons new-regexp 'json-mode)) |
| 57 | + (old-entry (when (boundp 'json-mode--auto-mode-entry) |
| 58 | + json-mode--auto-mode-entry))) |
| 59 | + (setq auto-mode-alist (delete old-entry auto-mode-alist)) |
| 60 | + (add-to-list 'auto-mode-alist new-entry 'json-mode) |
| 61 | + new-entry)) |
| 62 | + |
| 63 | +;;;###autoload |
| 64 | +(defcustom json-mode-auto-mode-list '(".babelrc" ".bowerrc") |
| 65 | + "List of filename as string to pass for the JSON entry of |
| 66 | +`auto-mode-alist'. |
| 67 | +
|
| 68 | +Note however that custom `json-mode' entries in `auto-mode-alist' |
| 69 | +won’t be affected." |
| 70 | + :group 'json-mode |
| 71 | + :type '(repeat string) |
| 72 | + :set (lambda (symbol value) |
| 73 | + "Update SYMBOL with a new regexp made from VALUE. |
| 74 | +
|
| 75 | +This function calls `json-mode--update-auto-mode' to change the |
| 76 | +`json-mode--auto-mode-entry' entry in `auto-mode-alist'." |
| 77 | + (set-default symbol value) |
| 78 | + (setq json-mode--auto-mode-entry (json-mode--update-auto-mode value)))) |
| 79 | + |
| 80 | +;; Autoload needed to initalize the the `auto-list-mode' entry. |
| 81 | +;;;###autoload |
| 82 | +(defvar json-mode--auto-mode-entry (json-mode--update-auto-mode json-mode-auto-mode-list) |
| 83 | + "Regexp generated from the `json-mode-auto-mode-list'.") |
| 84 | + |
38 | 85 | (defconst json-mode-quoted-string-re
|
39 | 86 | (rx (group (char ?\")
|
40 | 87 | (zero-or-more (or (seq ?\\ ?\\)
|
|
69 | 116 | "Major mode for editing JSON files"
|
70 | 117 | (set (make-local-variable 'font-lock-defaults) '(json-font-lock-keywords-1 t)))
|
71 | 118 |
|
72 |
| -;;;###autoload |
73 |
| -(add-to-list 'auto-mode-alist '("\\.json$" . json-mode)) |
74 |
| -;;;###autoload |
75 |
| -(add-to-list 'auto-mode-alist '("\\.jsonld$" . json-mode)) |
76 |
| -;;;###autoload |
77 |
| -(add-to-list 'auto-mode-alist (cons (rx (or |
78 |
| - ".babelrc" |
79 |
| - ".bowerrc" |
80 |
| - ) eos) |
81 |
| - 'json-mode)) |
82 |
| - |
83 | 119 | ;;;###autoload
|
84 | 120 | (defun json-mode-show-path ()
|
85 | 121 | (interactive)
|
|
0 commit comments