2018-05-14 04:46:45 +00:00
|
|
|
;;; funcs.el --- JSON Layer functions File for Spacemacs
|
|
|
|
;;
|
2021-03-22 20:11:29 +00:00
|
|
|
;; Copyright (c) 2012-2021 Sylvain Benner & Contributors
|
2018-05-14 04:46:45 +00:00
|
|
|
;;
|
|
|
|
;; Author: Muneeb Shaikh <muneeb@reversehack.in>
|
|
|
|
;; URL: https://github.com/syl20bnr/spacemacs
|
|
|
|
;;
|
|
|
|
;; This file is not part of GNU Emacs.
|
|
|
|
;;
|
2021-03-24 03:31:44 +00:00
|
|
|
;; This program is free software; you can redistribute it and/or modify
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
|
|
|
;;
|
|
|
|
;; This program is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
;;
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
|
|
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2018-05-14 04:46:45 +00:00
|
|
|
|
2020-06-23 20:19:51 +00:00
|
|
|
(defun spacemacs//json-setup-company ()
|
|
|
|
"Conditionally setup company based on backend."
|
2021-03-18 04:25:03 +00:00
|
|
|
;; Activate lsp company explicitly to activate
|
|
|
|
;; standard backends as well
|
|
|
|
(when (eq json-backend 'lsp)
|
|
|
|
(spacemacs|add-company-backends
|
|
|
|
:backends company-capf
|
|
|
|
:modes json-mode)))
|
2020-06-23 20:19:51 +00:00
|
|
|
|
|
|
|
(defun spacemacs//json-setup-backend ()
|
|
|
|
"Conditionally setup json backend."
|
2021-03-18 04:25:03 +00:00
|
|
|
(when (eq json-backend 'lsp)
|
|
|
|
(lsp)))
|
2020-06-23 20:19:51 +00:00
|
|
|
|
2018-05-14 04:46:45 +00:00
|
|
|
(defun spacemacs/json-navigator-dwim (arg &optional start end)
|
|
|
|
"Display the JSON hierarchy of the whole buffer or the active region.
|
|
|
|
If ARG is a universal prefix argument then display the hierarchy after point."
|
|
|
|
(interactive "P\nr")
|
|
|
|
(if arg
|
|
|
|
(json-navigator-navigate-after-point)
|
|
|
|
(if (equal start end)
|
|
|
|
(save-excursion (json-navigator-navigate-region (point-min) (point-max)))
|
|
|
|
(json-navigator-navigate-region start end))))
|
|
|
|
|
|
|
|
(defun spacemacs/json-reformat-dwim (arg &optional start end)
|
|
|
|
"Reformat the whole buffer of the active region.
|
|
|
|
If ARG is non-nil (universal prefix argument) then try to decode the strings.
|
2018-05-24 02:12:30 +00:00
|
|
|
If ARG is a numerical prefix argument then specify the indentation level."
|
2018-05-14 04:46:45 +00:00
|
|
|
(interactive "P\nr")
|
|
|
|
(let ((json-reformat:indent-width js-indent-level)
|
|
|
|
(json-reformat:pretty-string? nil))
|
|
|
|
(cond
|
|
|
|
((numberp arg) (setq json-reformat:indent-width arg))
|
|
|
|
(arg (setq json-reformat:pretty-string? t)))
|
|
|
|
(if (equal start end)
|
|
|
|
(save-excursion (json-reformat-region (point-min) (point-max)))
|
|
|
|
(json-reformat-region start end))))
|
2018-09-22 20:08:44 +00:00
|
|
|
|
|
|
|
(defun spacemacs/json-setup-prettier ()
|
|
|
|
"Tell prettier the content is to be parsed as JSON regardless of any file
|
|
|
|
extensions."
|
|
|
|
(setq-local prettier-js-args '("--parser=json")))
|