Mercurial > hg > dotemacs
changeset 195:8ef7ef4aad42
json-mode: version 1.7.0
author | Jordi Gutiérrez Hermoso <jordigh@octave.org> |
---|---|
date | Tue, 26 Nov 2019 14:34:03 -0500 |
parents | 6ad571bbb951 |
children | 1f4ccb3575d2 |
files | dotemacs.el.orig elpa/json-mode-1.2.0/json-mode-autoloads.el elpa/json-mode-1.2.0/json-mode-pkg.el elpa/json-mode-1.2.0/json-mode.el elpa/json-mode-1.7.0/json-mode-autoloads.el elpa/json-mode-1.7.0/json-mode-pkg.el elpa/json-mode-1.7.0/json-mode.el elpa/json-navigator-readme.txt elpa/json-reformat-0.0.6/json-reformat-autoloads.el elpa/json-reformat-0.0.6/json-reformat-pkg.el elpa/json-reformat-0.0.6/json-reformat.el elpa/json-snatcher-1.0.0/json-snatcher-autoloads.el elpa/json-snatcher-1.0.0/json-snatcher-pkg.el elpa/json-snatcher-1.0.0/json-snatcher.el |
diffstat | 11 files changed, 1209 insertions(+), 45 deletions(-) [+] |
line wrap: on
line diff
new file mode 100644 --- /dev/null +++ b/dotemacs.el.orig @@ -0,0 +1,520 @@ +(add-to-list 'load-path "~/.emacs.d/packages/") +(package-initialize) + +(defalias 'perl-mode 'cperl-mode) + +(require 'legalese) + +(require 'rainbow-mode) + +(require 'stripes) + +(require 'matlab) + +(require 'tabbar) + +(require 'bar-cursor) + +(require 'fill-column-indicator) + +(require 'adaptive-wrap) + +(require 'rpm-spec-mode) + +(require 'mediawiki) + +(require 'd-mode) + +(require 'sdlang-mode) + +(require 'fish-mode) + +(elpy-enable) + +;; Let's highlight the current line in windows +(global-hl-line-mode) + +;; I think I like the idea of the cursor being more indicative of +;; where the point is. +(bar-cursor-mode) + +;; Show where the fill column is +(fci-mode) + +;(require 'erc-highlight-mode) +(setq erc-input-line-position -2) + +;; Use org-mode to write blogthings +(setq load-path (cons "~/.emacs.d/packages/org2blog" load-path)) +(require 'org2blog) + +;; Enable ditaa for org-babel +(setq org-ditaa-jar-path "/usr/share/ditaa/ditaa.jar") +(org-babel-do-load-languages + 'org-babel-load-languages + '((ditaa . t))) + +;; Don't prompt, just evaluate the ditaa region! +(setq org-confirm-babel-evaluate nil) + +;; And show me the image right there once you're done. +(add-hook 'org-babel-after-execute-hook 'org-display-inline-images) + + +(setq org2blog-server-url "http://jordi.inversethought.com/xmlrpc.php" + org2blog-server-user "jordigh" + org2blog-server-weblog-id "") + +;; Remember where I was when I last opened a file +(save-place-mode 1) + +;; I have decided that I usually want long lines to scroll off to the +;; right, not that bizarro folding that wraps lines in the middle of +;; words +(setq-default truncates-lines t) + +(server-start) + +;; I want tramp to obey the $PATH that is set on the remote host +(require 'tramp) +(add-to-list 'tramp-remote-path 'tramp-own-remote-path) + +;; wtf is this crap? begone! +(setq transient-mark-mode nil) + +(global-set-key (kbd "C-S-n") 'tabbar-forward-tab) +(global-set-key (kbd "C-S-p") 'tabbar-backward-tab) +(global-set-key (kbd "C-c C-S-n") 'tabbar-forward-group) +(global-set-key (kbd "C-c C-S-p") 'tabbar-backward-group) + +(global-set-key (kbd "C-S-j") 'windmove-down) +(global-set-key (kbd "C-S-k") 'windmove-up) +(global-set-key (kbd "C-S-h") 'windmove-left) +(global-set-key (kbd "C-S-l") 'windmove-right) + +(global-set-key (kbd "C-x <SPC>") 'gud-break) +(global-set-key (kbd "M-<down>") 'gud-next) +(global-set-key (kbd "M-<right>") 'gud-step) +(global-set-key (kbd "M-<left>") 'gud-finish) +(global-set-key (kbd "M-<RET>") 'gud-cont) +(global-unset-key (kbd "C-x <DEL>")) +(global-set-key (kbd "C-x <DEL>") 'gud-remove) +(global-unset-key (kbd "C-x C-z")) +(global-set-key (kbd "C-x C-z") 'gud-stop-subjob) + +;; Like pdb's "until" +(global-set-key (kbd "C-<return>") + (lambda () (interactive) + (progn + (gud-tbreak (line-number-at-pos)) + (gud-cont (line-number-at-pos))))) + +;; web-mode doesn't seem to have another way of figuring out which +;; engine to use, but Django templates is all I care about for now. +(setq web-mode-engines-alist + '(("django" . "\\.html\\'")) + +) + +;; I've grown used to this indentation style. +;; I want to see +;; +;; lolomgwtf( +;; brb, +;; bbq, +;; ) +;; +;; and not +; +;; lolomgwtf( +;; brb, +;; bbq, +;; ) +;; +;; H/T fledermaus +(defun modest-arglist-indentation () + (c-set-offset 'arglist-close 0) + (c-set-offset 'arglist-intro '+)) +(add-hook 'd-mode-hook 'modest-arglist-indentation) + +;;; H/T Stefan Monnier +(defun unfill-paragraph (&optional region) + "Takes a multi-line paragraph and makes it into a single line of text." + (interactive (progn (barf-if-buffer-read-only) '(t))) + (let ((fill-column (point-max))) + (fill-paragraph nil region))) + +;;; http://stackoverflow.com/a/23382008 +(require 'ansi-color) +(defun display-ansi-colors () + (interactive) + (ansi-color-apply-on-region (point-min) (point-max))) + +;;; H/T Tom Tromey +(defun insert-filename-and-line-at-point (path) + "Just insert the full absolute pathname including the line +number at point, like in gcc error messages." + (interactive (progn (barf-if-buffer-read-only) '(t))) + (let ((fname . (buffer-file-name))) + (insert fname ":" (int-to-string (line-number-at-pos))))) + +;; The default selection keys for company-mode are M-n and M-p, eww. +(require 'company) +(define-key company-active-map (kbd "C-p") 'company-select-previous-or-abort) +(define-key company-active-map (kbd "C-n") 'company-select-next-or-abort) + +(global-set-key (kbd "M-Q") 'unfill-paragraph) + +;; Only killing the current buffer is useful (thanks to madpickle of #emacs) +(global-set-key (kbd "C-x k") + (lambda () (interactive) (kill-buffer (current-buffer)))) + +;; I never use this function, and I frequently typo it when trying to +;; hit C-x C-f +(global-unset-key (kbd "C-x f")) + +;; Make dired visit directory or file in the same buffer +(put 'dired-find-alternate-file 'disabled nil) +(add-hook 'dired-mode-hook + (lambda () + (local-set-key (kbd "<RET>") 'dired-find-alternate-file))) + +;; I want to optionally rename buffers sometimes when saving + +;; I want <RET> to indent the next line in python-mode. This swaps +;; the standard definitions of <RET> and C-j. +(add-hook 'python-mode-hook + (lambda () + (local-set-key (kbd "<RET>") 'newline-and-indent) + (local-set-key (kbd "C-j") 'newline))) + +(setq auto-mode-alist + (append + '( + ("\\.m\\'" . octave-mode) + ("\\.eml\\'" . mail-mode) + ("\\.d[i]?\\'" . d-mode) + ("\\.pro\\'" . conf-mode) ;; Qt project files + ("\\.php\\'" . web-mode) ;; Default php mode isn't as good + ("\\.?hgrc\\'" . conf-mode) + ("\\.spec\\'" . rpm-spec-mode) + ("hg-editor-.\\{6\\}\\.commit\\.hg\\.txt\\'" . diff-mode) + ("evo[A-Z0-9]\\{6\\}\\'" . mail-mode)) + auto-mode-alist)) + +;; Scroll smoothly +(setq scroll-step 1000) +(setq scroll-conservatively 1000) + +;; This ido thing looks interesting... +(ido-mode 1) + +(setq default-major-mode 'text-mode) +(global-unset-key "\C-z") + +;; po-mode seems to have forgotten to bind this key, because it does +;; bind C-_ +(add-hook 'po-mode-hook + (lambda () + (local-set-key (kbd "C-/") 'po-undo))) + +;; Don't like it when several windows open upon emacs startup +;; (Thanks theseb of #emacs) +(add-hook 'window-setup-hook 'delete-other-windows) +(add-to-list 'same-window-buffer-names "*Buffer List*") + +;; Set auto-fill for all modes +;(setq-default auto-fill-function 'do-auto-fill) + +;ibuffer is the only decent one +(global-set-key (kbd "C-x C-b") 'ibuffer) + +;Make GUD put output in a different buffer +(setq gdb-separate-io t) + +;; Highlight "FIXME: and TODO:" +(font-lock-add-keywords + 'c-mode + '(("\\<\\(FIXME\\)" 1 font-lock-warning-face t))) + +(font-lock-add-keywords + 'c++-mode + '(("\\<\\(FIXME\\):" 1 font-lock-warning-face t))) + +(font-lock-add-keywords + 'c-mode + '(("\\<\\(TODO\\):" 1 font-lock-warning-face t))) + +(font-lock-add-keywords + 'c++-mode + '(("\\<\\(TODO\\):" 1 font-lock-warning-face t))) + +;; Let auto-fill end lines with a full stop. +(setq sentence-end-double-space nil) + +;; Don't let ediff open a new frame +(setq ediff-window-setup-function 'ediff-setup-windows-plain) + +;; Don't like stuff to indent when I don't hit <TAB> +(setq electric-indent-mode nil) + +;; Menus are for wimps +(menu-bar-mode -1) + +(put 'narrow-to-region 'disabled nil) + +;;; Inserts a relative pathname interactively +(defun insert-relative-path (path) + (interactive (list (read-file-name "Path to insert relatively: "))) + (insert (file-relative-name path default-directory))) + +; Add cmake listfile names to the mode list. +(setq auto-mode-alist + (append + '(("CMakeLists\\.txt\\'" . cmake-mode)) + '(("\\.cmake\\'" . cmake-mode)) + auto-mode-alist)) + +(defun set-tab-width (width) + (interactive "nSet tab width: ") + (setq tab-width width)) + +;; "Fix" the horrible asn1-mode mess +(add-hook 'asn1-mode-hook + (lambda () + (setq indent-line-function #'indent-relative) + (setq case-fold-search t))) + +;; vc-mode can't work with all of my hg customisations, but this +;; undoes most of them +(setenv "HGPLAIN" "1") + +;; What it says on the tin +(add-hook 'mail-mode-hook 'turn-on-auto-fill) + +;; Some info vi-like keybindings +(add-hook 'Info-mode-hook + (lambda () + (local-unset-key (kbd "l")) + (local-set-key (kbd ";") 'Info-history-back) + (local-set-key (kbd "h") 'backward-char) + (local-set-key (kbd "l") 'forward-char) + (local-set-key (kbd "j") 'next-line) + (local-set-key (kbd "k") 'previous-line) + (local-set-key (kbd "/") 'Info-search))) + +;; moar vi +(add-hook 'doc-view-mode-hook + (lambda () + (local-unset-key (kbd "k")) + (local-set-key (kbd "j") 'doc-view-next-line-or-next-page) + (local-set-key (kbd "k") 'doc-view-previous-line-or-previous-page) + (local-set-key (kbd "h") 'image-backward-hscroll) + (local-set-key (kbd "l") 'image-forward-hscroll))) + +(setq doc-view-continuous t) + +;; Something seems to clobber whitespace-mode, this should fix it +(whitespace-toggle-options 'whitespace-style) + +(defun hide-ctrl-M () + "Hides the annoying '^M' showing up in files containing mixed +UNIX and DOS line endings." + (interactive) + (setq buffer-display-table (make-display-table)) + (aset buffer-display-table ?\^M [])) + +(add-hook 'magit-mode-hook + (lambda () + ;; I always run magit side-by-side to the code I'm reading + (local-set-key (kbd "<RET>") (lambda () + (interactive) + (magit-visit-item t))))) + +(custom-set-variables + ;; custom-set-variables was added by Custom. + ;; If you edit it by hand, you could mess it up, so be careful. + ;; Your init file should contain only one such instance. + ;; If there is more than one, they won't work right. + '(LaTeX-indent-level 2) + '(LaTeX-item-indent 0) + '(TeX-PDF-mode t) + '(TeX-brace-indent-level 2) + '(TeX-debug-bad-boxes t) + '(TeX-debug-warnings t) + '(TeX-display-help nil) + '(TeX-engine (quote xetex)) + '(TeX-newline-function (quote reindent-then-newline-and-indent)) + '(TeX-output-view-style + (quote + (("^dvi$" + ("^landscape$" "^pstricks$\\|^pst-\\|^psfrag$") + "%(o?)dvips -t landscape %d -o && gv %f") + ("^dvi$" "^pstricks$\\|^pst-\\|^psfrag$" "%(o?)dvips %d -o && gv %f") + ("^dvi$" + ("^a4\\(?:dutch\\|paper\\|wide\\)\\|sem-a4$" "^landscape$") + "%(o?)xdvi %dS -paper a4r -s 0 %d") + ("^dvi$" "^a4\\(?:dutch\\|paper\\|wide\\)\\|sem-a4$" "%(o?)xdvi %dS -paper a4 %d") + ("^dvi$" + ("^a5\\(?:comb\\|paper\\)$" "^landscape$") + "%(o?)xdvi %dS -paper a5r -s 0 %d") + ("^dvi$" "^a5\\(?:comb\\|paper\\)$" "%(o?)xdvi %dS -paper a5 %d") + ("^dvi$" "^b5paper$" "%(o?)xdvi %dS -paper b5 %d") + ("^dvi$" "^letterpaper$" "%(o?)xdvi %dS -paper us %d") + ("^dvi$" "^legalpaper$" "%(o?)xdvi %dS -paper legal %d") + ("^dvi$" "^executivepaper$" "%(o?)xdvi %dS -paper 7.25x10.5in %d") + ("^dvi$" "." "%(o?)xdvi %dS %d") + ("^pdf$" "." "evince %o %(outpage)") + ("^html?$" "." "netscape %o")))) + '(TeX-view-program-selection + (quote + (((output-dvi style-pstricks) + "dvips and gv") + (output-dvi "Evince") + (output-pdf "Evince") + (output-html "xdg-open")))) + '(add-log-mailing-address "jordigh@octave.org") + '(auto-compression-mode t nil (jka-compr)) + '(c-offsets-alist (quote ((substatement-open . 0) (innamespace . 0)))) + '(case-fold-search t) + '(column-number-mode t) + '(comint-input-autoexpand (quote history)) + '(comint-move-point-for-output (quote all)) + '(comint-prompt-read-only t) + '(comint-scroll-to-bottom-on-input (quote all)) + '(compilation-scroll-output t) + '(confirm-kill-emacs (quote yes-or-no-p)) + '(cperl-auto-newline nil) + '(cperl-close-paren-offset 0) + '(cperl-electric-backspace-untabify nil) + '(cperl-highlight-variables-indiscriminately t) + '(cperl-merge-trailing-else nil) + '(current-language-environment "UTF-8") + '(debian-changelog-full-name "Jordi Gutiérrez Hermoso") + '(debian-changelog-mailing-address "jordigh@octave.org") + '(default-input-method "latin-1-prefix") + '(ecb-options-version "2.32") + '(ecb-tip-of-the-day nil) + '(ediff-split-window-function (quote split-window-horizontally)) + '(elpy-interactive-python-command "ipython") + '(elpy-modules + (quote + (elpy-module-company elpy-module-eldoc elpy-module-flymake elpy-module-pyvenv elpy-module-yasnippet elpy-module-sane-defaults))) + '(elpy-rpc-ignored-buffer-size 10240000) + '(elpy-rpc-timeout 5) + '(erc-input-line-position 0 t) + '(erc-modules + (quote + (highlight-nicknames scrolltobottom completion autojoin button fill irccontrols list match menu move-to-prompt netsplit networks noncommands readonly ring stamp track))) + '(gdb-max-frames 1000) + '(global-font-lock-mode t nil (font-lock)) + '(gud-pdb-command-name "pdb") + '(ido-auto-merge-work-directories-length -1) + '(indent-tabs-mode nil) + '(inhibit-startup-buffer-menu t) + '(inhibit-startup-screen t) + '(jde-jdk-registry (quote (("1.6.0" . "/usr/lib/jvm/java-6-openjdk")))) + '(js2-auto-indent-flag nil) + '(js2-bounce-indent-flag nil) + '(js2-enter-indents-newline nil) + '(js2-mirror-mode nil) + '(legalese-default-author "Jordi Gutiérrez Hermoso") + '(legalese-default-copyright "Jordi Gutiérrez Hermoso <jordigh@octave.org>") + '(make-backup-files nil) + '(org-startup-folded nil) + '(package-archives + (quote + (("melpa-stable" . "https://stable.melpa.org/packages/") + ("gnu" . "http://elpa.gnu.org/packages/")))) + '(package-selected-packages + (quote + (rjsx-mode mastodon rust-mode systemd fountain-mode markdown-mode magit js2-mode yaml-mode web-mode undo-tree puppet-mode nginx-mode json-mode jade-mode idomenu haml-mode goto-last-change flymake-haml elpy dockerfile-mode))) + '(safe-local-variable-values + (quote + ((encoding . utf-8) + (eval when + (and + (buffer-file-name) + (string-match-p "\\.h\\'" + (buffer-file-name)) + (not + (string-match-p "/gnulib/" + (buffer-file-name)))) + (c++-mode) + (c-set-style "gnu")) + (eval when + (string-match "\\.in\\'" + (buffer-file-name)) + (html-mode)) + (eval when + (string-match "\\.h\\'" + (buffer-file-name)) + (unless + (string-match "/gnulib/" + (buffer-file-name)) + (c++-mode) + (c-set-style "gnu"))) + (py-indent-offset . 4) + (eval when + (string-match "\\.h\\'" + (buffer-file-name)) + (c++-mode) + (c-set-style "gnu"))))) + '(savehist-mode t nil (savehist)) + '(select-enable-clipboard t) + '(select-enable-primary t) + '(show-paren-mode t) + '(tab-width 2) + '(tabbar-mode t nil (tabbar)) + '(text-mode-hook (quote (text-mode-hook-identify))) + '(tool-bar-mode nil) + '(tramp-default-method "ssh") + '(tramp-remote-process-environment + (quote + ("HISTFILE=$HOME/.tramp_history" "HISTSIZE=1" "LC_ALL=C" "TERM=dumb" "EMACS=t" "INSIDE_EMACS='24.3.1,tramp:2.2.6-24.3'" "CDPATH=" "HISTORY=" "MAIL=" "MAILCHECK=" "MAILPATH=" "PAGER=\"\"" "autocorrect=" "HGPLAIN=1" "correct="))) + '(transient-mark-mode nil) + '(uniquify-buffer-name-style (quote forward) nil (uniquify)) + '(vc-follow-symlinks nil) + '(w3m-default-display-inline-images t) + '(w3m-use-cookies t) + '(web-mode-markup-indent-offset 4)) +(custom-set-faces + ;; custom-set-faces was added by Custom. + ;; If you edit it by hand, you could mess it up, so be careful. + ;; Your init file should contain only one such instance. + ;; If there is more than one, they won't work right. + '(default ((t (:inherit nil :stipple nil :background "grey20" :foreground "white" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight normal :height 98 :width normal :foundry "unknown" :family "Liberation Mono")))) + '(diff-added ((t (:foreground "lime green")))) + '(diff-changed ((t (:foreground "orange")))) + '(diff-file-header ((((class color) (background light)) (:background "lightblue" :bold t)))) + '(diff-header ((nil (:foreground "skyblue")))) + '(diff-refine-added ((t (:inherit diff-refine-change :background "#114411")))) + '(diff-refine-changed ((((class color) (min-colors 88) (background dark)) (:background "navyblue")))) + '(diff-refine-removed ((t (:inherit diff-refine-change :background "#441111")))) + '(diff-removed ((t (:foreground "orangered")))) + '(ecb-tag-header-face ((((class color) (background dark)) (:background "DarkGreen")))) + '(ediff-even-diff-A ((t (:background "#444")))) + '(ediff-even-diff-B ((t (:background "Grey" :foreground "black")))) + '(ediff-even-diff-C ((t (:background "#666")))) + '(ediff-odd-diff-A ((t (:background "#666")))) + '(ediff-odd-diff-B ((t (:background "#666")))) + '(ediff-odd-diff-C ((t (:background "Grey" :foreground "black")))) + '(erc-input-face ((t (:foreground "yellow")))) + '(erc-my-nick-face ((t (:foreground "lightblue" :weight bold)))) + '(erc-notice-face ((t (:foreground "lightgreen" :weight bold)))) + '(flymake-errline ((t (:background "#332525")))) + '(flymake-warnline ((t (:background "#404033")))) + '(highlight ((((class color) (min-colors 88) (background dark)) (:background "#555")))) + '(magit-diff-add ((((class color) (background dark)) (:foreground "lime green")))) + '(magit-diff-del ((t (:inherit diff-removed)))) + '(markdown-code-face ((t (:inherit fixed-pitch :background "#3a0a0a")))) + '(mode-line ((t (:background "#C90" :foreground "#000000" :box (:line-width -1 :style released-button))))) + '(monky-header ((t (:background "#666")))) + '(rpm-spec-package-face ((((class color) (background dark)) (:foreground "#F88")))) + '(rpm-spec-tag-face ((((class color) (background dark)) (:foreground "light blue")))) + '(rst-level-1-face ((t (:background "grey10"))) t) + '(rst-level-2-face ((t (:background "grey10"))) t) + '(rst-level-3-face ((t (:background "grey10"))) t) + '(show-ws-tab ((t (:background "Black")))) + '(stripes-face ((t (:background "#444"))))) +
rename from elpa/json-mode-1.2.0/json-mode-autoloads.el rename to elpa/json-mode-1.7.0/json-mode-autoloads.el --- a/elpa/json-mode-1.2.0/json-mode-autoloads.el +++ b/elpa/json-mode-1.7.0/json-mode-autoloads.el @@ -2,20 +2,12 @@ ;; ;;; Code: - -;;;### (autoloads (json-mode json-mode-beautify-ordered json-mode-beautify) -;;;;;; "json-mode" "json-mode.el" (21797 19307 164820 295000)) -;;; Generated autoloads from json-mode.el +(add-to-list 'load-path (directory-file-name + (or (file-name-directory #$) (car load-path)))) -(autoload 'json-mode-beautify "json-mode" "\ -Beautify / pretty-print from BEG to END, and optionally PRESERVE-KEY-ORDER. - -\(fn &optional PRESERVE-KEY-ORDER)" t nil) - -(autoload 'json-mode-beautify-ordered "json-mode" "\ -Beautify / pretty-print from BEG to END preserving key order. - -\(fn)" t nil) + +;;;### (autoloads nil "json-mode" "json-mode.el" (0 0 0 0)) +;;; Generated autoloads from json-mode.el (autoload 'json-mode "json-mode" "\ Major mode for editing JSON files @@ -24,14 +16,20 @@ (add-to-list 'auto-mode-alist '("\\.json$" . json-mode)) -;;;*** - -;;;### (autoloads nil nil ("json-mode-pkg.el") (21797 19307 175675 -;;;;;; 579000)) +(autoload 'json-mode-show-path "json-mode" "\ + + +\(fn)" t nil) + +(autoload 'json-mode-beautify "json-mode" "\ +Beautify / pretty-print the active region (or the entire buffer if no active region). + +\(fn)" t nil) + +(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "json-mode" '("json-"))) ;;;*** -(provide 'json-mode-autoloads) ;; Local Variables: ;; version-control: never ;; no-byte-compile: t
rename from elpa/json-mode-1.2.0/json-mode-pkg.el rename to elpa/json-mode-1.7.0/json-mode-pkg.el --- a/elpa/json-mode-1.2.0/json-mode-pkg.el +++ b/elpa/json-mode-1.7.0/json-mode-pkg.el @@ -1,1 +1,2 @@ -(define-package "json-mode" "1.2.0" "Major mode for editing JSON files" (quote nil)) +;;; -*- no-byte-compile: t -*- +(define-package "json-mode" "1.7.0" "Major mode for editing JSON files" '((json-reformat "0.0.5") (json-snatcher "1.0.0")) :commit "9ba01b868a6b138feeff82b9eb0abd331d29325f" :authors '(("Josh Johnston")) :maintainer '("Josh Johnston") :url "https://github.com/joshwnj/json-mode")
rename from elpa/json-mode-1.2.0/json-mode.el rename to elpa/json-mode-1.7.0/json-mode.el --- a/elpa/json-mode-1.2.0/json-mode.el +++ b/elpa/json-mode-1.7.0/json-mode.el @@ -1,10 +1,12 @@ ;;; json-mode.el --- Major mode for editing JSON files -;; Copyright (C) 2011-2013 Josh Johnston +;; Copyright (C) 2011-2014 Josh Johnston ;; Author: Josh Johnston ;; URL: https://github.com/joshwnj/json-mode -;; Version: 1.2.0 +;; Package-Version: 1.7.0 +;; Version: 1.6.0 +;; Package-Requires: ((json-reformat "0.0.5") (json-snatcher "1.0.0")) ;; 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 @@ -27,6 +29,8 @@ (require 'js) (require 'rx) +(require 'json-snatcher) +(require 'json-reformat) (defconst json-mode-quoted-string-re (rx (group (char ?\") @@ -57,30 +61,6 @@ ) "Level one font lock.") -(defconst json-mode-beautify-command-python2 - "python2 -c \"import sys,json,collections; data=json.loads(sys.stdin.read(),object_pairs_hook=collections.OrderedDict); print json.dumps(data,sort_keys=%s,indent=4,separators=(',',': ')).decode('unicode_escape').encode('utf8','replace')\"") -(defconst json-mode-beautify-command-python3 - "python3 -c \"import sys,json,codecs,collections; data=json.loads(sys.stdin.read(),object_pairs_hook=collections.OrderedDict); print((codecs.getdecoder('unicode_escape')(json.dumps(data,sort_keys=%s,indent=4,separators=(',',': '))))[0])\"") - -;;;###autoload -(defun json-mode-beautify (&optional preserve-key-order) - "Beautify / pretty-print from BEG to END, and optionally PRESERVE-KEY-ORDER." - (interactive "P") - (shell-command-on-region (if (use-region-p) (region-beginning) (point-min)) - (if (use-region-p) (region-end) (point-max)) - (concat (if (executable-find "env") "env " "") - (format (if (executable-find "python2") - json-mode-beautify-command-python2 - json-mode-beautify-command-python3) - (if preserve-key-order "False" "True"))) - (current-buffer) t)) - -;;;###autoload -(defun json-mode-beautify-ordered () - "Beautify / pretty-print from BEG to END preserving key order." - (interactive) - (json-mode-beautify t)) - ;;;###autoload (define-derived-mode json-mode javascript-mode "JSON" "Major mode for editing JSON files" @@ -88,8 +68,40 @@ ;;;###autoload (add-to-list 'auto-mode-alist '("\\.json$" . json-mode)) +(add-to-list 'auto-mode-alist '("\\.jsonld$" . json-mode)) + +;;;###autoload +(defun json-mode-show-path () + (interactive) + (let ((temp-name "*json-path*")) + (with-output-to-temp-buffer temp-name (jsons-print-path)) + + (let ((temp-window (get-buffer-window temp-name))) + ;; delete the window if we have one, + ;; so we can recreate it in the correct position + (if temp-window + (delete-window temp-window)) + + ;; always put the temp window below the json window + (set-window-buffer (if (fboundp 'split-window-below) + (split-window-below) + (split-window-vertically)) temp-name)) + )) + +(define-key json-mode-map (kbd "C-c C-p") 'json-mode-show-path) + +;;;###autoload +(defun json-mode-beautify () + "Beautify / pretty-print the active region (or the entire buffer if no active region)." + (interactive) + (let ((json-reformat:indent-width js-indent-level) + (json-reformat:pretty-string? t)) + (if (use-region-p) + (json-reformat-region (region-beginning) (region-end)) + (json-reformat-region (buffer-end -1) (buffer-end 1))))) (define-key json-mode-map (kbd "C-c C-f") 'json-mode-beautify) + (provide 'json-mode) ;;; json-mode.el ends here
new file mode 100644 --- /dev/null +++ b/elpa/json-navigator-readme.txt @@ -0,0 +1,1 @@ +View and navigate JSON structures
new file mode 100644 --- /dev/null +++ b/elpa/json-reformat-0.0.6/json-reformat-autoloads.el @@ -0,0 +1,31 @@ +;;; json-reformat-autoloads.el --- automatically extracted autoloads +;; +;;; Code: + +(add-to-list 'load-path (directory-file-name + (or (file-name-directory #$) (car load-path)))) + + +;;;### (autoloads nil "json-reformat" "json-reformat.el" (0 0 0 0)) +;;; Generated autoloads from json-reformat.el + +(autoload 'json-reformat-region "json-reformat" "\ +Reformat the JSON in the specified region. + +If you want to customize the reformat style, +please see the documentation of `json-reformat:indent-width' +and `json-reformat:pretty-string?'. + +\(fn BEGIN END)" t nil) + +(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "json-reformat" '("json-reformat"))) + +;;;*** + +;; Local Variables: +;; version-control: never +;; no-byte-compile: t +;; no-update-autoloads: t +;; coding: utf-8 +;; End: +;;; json-reformat-autoloads.el ends here
new file mode 100644 --- /dev/null +++ b/elpa/json-reformat-0.0.6/json-reformat-pkg.el @@ -0,0 +1,2 @@ +;;; -*- no-byte-compile: t -*- +(define-package "json-reformat" "0.0.6" "Reformatting tool for JSON" 'nil :commit "b9bd375ec1deb10d2ba09c409bdcf99c56d7a716" :keywords '("json") :authors '(("Wataru MIYAGUNI" . "gonngo@gmail.com")) :maintainer '("Wataru MIYAGUNI" . "gonngo@gmail.com") :url "https://github.com/gongo/json-reformat")
new file mode 100644 --- /dev/null +++ b/elpa/json-reformat-0.0.6/json-reformat.el @@ -0,0 +1,219 @@ +;;; json-reformat.el --- Reformatting tool for JSON + +;; Author: Wataru MIYAGUNI <gonngo@gmail.com> +;; URL: https://github.com/gongo/json-reformat +;; Package-Version: 0.0.6 +;; Version: 0.0.6 +;; Keywords: json + +;; Copyright (c) 2012 Wataru MIYAGUNI +;; +;; MIT License +;; +;; Permission is hereby granted, free of charge, to any person obtaining +;; a copy of this software and associated documentation files (the +;; "Software"), to deal in the Software without restriction, including +;; without limitation the rights to use, copy, modify, merge, publish, +;; distribute, sublicense, and/or sell copies of the Software, and to +;; permit persons to whom the Software is furnished to do so, subject to +;; the following conditions: +;; +;; The above copyright notice and this permission notice shall be +;; included in all copies or substantial portions of the Software. +;; +;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +;; LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +;; OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +;; WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + +;;; Commentary: + +;; json-reformat.el is a reformatting tool for JSON (http://json.org/). +;; +;; ## Usage +;; +;; 1. Specify region +;; 2. Call 'M-x json-reformat-region' +;; +;; ## Customize +;; +;; - `json-reformat:indent-width' +;; - `json-reformat:pretty-string?' +;; + +;;; Code: + +(require 'json) +(eval-when-compile (require 'cl)) + +(unless (require 'subr-x nil t) + ;; built-in subr-x from 24.4 + (defsubst hash-table-keys (hash-table) + "Return a list of keys in HASH-TABLE." + (let ((keys '())) + (maphash (lambda (k _v) (push k keys)) hash-table) + keys))) + +(put 'json-reformat-error 'error-message "JSON Reformat error") +(put 'json-reformat-error 'error-conditions '(json-reformat-error error)) + +(defconst json-reformat:special-chars-as-pretty-string + '((?\" . ?\") + (?\\ . ?\\))) + +(defcustom json-reformat:indent-width 4 + "How much indentation `json-reformat-region' should do at each level." + :type 'integer + :group 'json-reformat) + +(defcustom json-reformat:pretty-string? nil + "Whether to decode the string. + +Example: + +{\"name\":\"foobar\",\"nick\":\"foo \\u00e4 bar\",\"description\":\"<pre>\\nbaz\\n</pre>\"} + +If nil: + + { + \"name\": \"foobar\", + \"nick\": \"foo \\u00e4 bar\", + \"description\": \"<pre>\\nbaz\\n<\\/pre>\" + } + +Else t: + + { + \"name\": \"foobar\", + \"nick\": \"foo ä bar\", + \"description\": \"<pre> + baz + </pre>\" + }" + :type 'boolean + :group 'json-reformat) + +(defun json-reformat:indent (level) + (make-string (* level json-reformat:indent-width) ? )) + +(defun json-reformat:number-to-string (val) + (number-to-string val)) + +(defun json-reformat:symbol-to-string (val) + (cond ((equal 't val) "true") + ((equal json-false val) "false") + (t (symbol-name val)))) + +(defun json-reformat:encode-char-as-pretty (char) + (setq char (encode-char char 'ucs)) + (let ((special-char (car (rassoc char json-reformat:special-chars-as-pretty-string)))) + (if special-char + (format "\\%c" special-char) + (format "%c" char)))) + +(defun json-reformat:string-to-string (val) + (if json-reformat:pretty-string? + (format "\"%s\"" (mapconcat 'json-reformat:encode-char-as-pretty val "")) + (json-encode-string val))) + +(defun json-reformat:vector-to-string (val level) + (if (= (length val) 0) "[]" + (concat "[\n" + (mapconcat + 'identity + (loop for v across val + collect (concat + (json-reformat:indent (1+ level)) + (json-reformat:print-node v (1+ level)) + )) + (concat ",\n")) + "\n" (json-reformat:indent level) "]" + ))) + +(defun json-reformat:print-node (val level) + (cond ((hash-table-p val) (json-reformat:tree-to-string (json-reformat:tree-sibling-to-plist val) level)) + ((numberp val) (json-reformat:number-to-string val)) + ((vectorp val) (json-reformat:vector-to-string val level)) + ((null val) "null") + ((symbolp val) (json-reformat:symbol-to-string val)) + (t (json-reformat:string-to-string val)))) + +(defun json-reformat:tree-sibling-to-plist (root) + (let (pl) + (dolist (key (reverse (hash-table-keys root)) pl) + (setq pl (plist-put pl key (gethash key root)))))) + +(defun json-reformat:tree-to-string (root level) + (concat "{\n" + (let (key val str) + (while root + (setq key (car root) + val (cadr root) + root (cddr root)) + (setq str + (concat str (json-reformat:indent (1+ level)) + "\"" key "\"" + ": " + (json-reformat:print-node val (1+ level)) + (when root ",") + "\n" + ))) + str) + (json-reformat:indent level) + "}")) + +(defun json-reformat-from-string (string) + (with-temp-buffer + (insert string) + (goto-char (point-min)) + (condition-case errvar + (let ((json-key-type 'string) + (json-object-type 'hash-table) + json-tree) + (setq json-tree (json-read)) + (json-reformat:print-node json-tree 0)) + (json-error + (signal 'json-reformat-error + (list (error-message-string errvar) + (line-number-at-pos (point)) + (point))))))) + +;;;###autoload +(defun json-reformat-region (begin end) + "Reformat the JSON in the specified region. + +If you want to customize the reformat style, +please see the documentation of `json-reformat:indent-width' +and `json-reformat:pretty-string?'." + (interactive "*r") + (let ((start-line (line-number-at-pos begin)) + (start-pos begin)) + (save-excursion + (save-restriction + (narrow-to-region begin end) + (goto-char (point-min)) + (let (reformatted) + (condition-case errvar + (progn + (setq reformatted + (json-reformat-from-string + (buffer-substring-no-properties (point-min) (point-max)))) + (delete-region (point-min) (point-max)) + (insert reformatted)) + (json-reformat-error + (let ((reason (nth 1 errvar)) + (line (nth 2 errvar)) + (position (nth 3 errvar))) + (message + "JSON parse error [Reason] %s [Position] In buffer, line %d (char %d)" + reason + (+ start-line line -1) + (+ start-pos position -1)))))))))) + +(provide 'json-reformat) + +;;; json-reformat.el ends here
new file mode 100644 --- /dev/null +++ b/elpa/json-snatcher-1.0.0/json-snatcher-autoloads.el @@ -0,0 +1,27 @@ +;;; json-snatcher-autoloads.el --- automatically extracted autoloads +;; +;;; Code: + +(add-to-list 'load-path (directory-file-name + (or (file-name-directory #$) (car load-path)))) + + +;;;### (autoloads nil "json-snatcher" "json-snatcher.el" (0 0 0 0)) +;;; Generated autoloads from json-snatcher.el + +(autoload 'jsons-print-path "json-snatcher" "\ +Print the path to the JSON value under point, and save it in the kill ring. + +\(fn)" t nil) + +(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "json-snatcher" '("jsons-"))) + +;;;*** + +;; Local Variables: +;; version-control: never +;; no-byte-compile: t +;; no-update-autoloads: t +;; coding: utf-8 +;; End: +;;; json-snatcher-autoloads.el ends here
new file mode 100644 --- /dev/null +++ b/elpa/json-snatcher-1.0.0/json-snatcher-pkg.el @@ -0,0 +1,2 @@ +;;; -*- no-byte-compile: t -*- +(define-package "json-snatcher" "1.0.0" "Grabs the path to JSON values in a JSON file" '((emacs "24")) :commit "c4cecc0a5051bd364373aa499c47a1bb7a5ac51c" :authors '(("Sterling Graham" . "sterlingrgraham@gmail.com")) :maintainer '("Sterling Graham" . "sterlingrgraham@gmail.com") :url "http://github.com/sterlingg/json-snatcher")
new file mode 100644 --- /dev/null +++ b/elpa/json-snatcher-1.0.0/json-snatcher.el @@ -0,0 +1,351 @@ +;;; json-snatcher.el --- Grabs the path to JSON values in a JSON file -*- lexical-binding: t -*- + +;; Copyright (C) 2013 Sterling Graham <sterlingrgraham@gmail.com> + +;; Author: Sterling Graham <sterlingrgraham@gmail.com> +;; URL: http://github.com/sterlingg/json-snatcher +;; Package-Version: 1.0.0 +;; Version: 1.0 +;; Package-Requires: ((emacs "24")) + +;; This file is not part of GNU Emacs. + +;;; Commentary: +;; +;; Well this was my first excursion into ELisp programmming. It didn't go too badly once +;; I fiddled around with a bunch of the functions. +;; +;; The process of getting the path to a JSON value at point starts with +;; a call to the jsons-print-path function. +;; +;; It works by parsing the current buffer into a list of parse tree nodes +;; if the buffer hasn't already been parsed in the current Emacs session. +;; While parsing, the region occupied by the node is recorded into the +;; jsons-parsed-regions hash table as a list.The list contains the location +;; of the first character occupied by the node, the location of the last +;; character occupied, and the path to the node. The parse tree is also stored +;; in the jsons-parsed list for possible future use. +;; +;; Once the buffer has been parsed, the node at point is looked up in the +;; jsons-curr-region list, which is the list of regions described in the +;; previous paragraph for the current buffer. If point is not in one of these +;; interval ranges nil is returned, otherwise the path to the value is returned +;; in the form [<key-string>] for objects, and [<loc-int>] for arrays. +;; eg: ['value1'][0]['value2'] gets the array at with name value1, then gets the +;; 0th element of the array (another object), then gets the value at 'value2'. +;; + +;;; Installation: +;; +;; IMPORTANT: Works ONLY in Emacs 24 due to the use of the lexical-binding variable. +;; +;; To install add the json-snatcher.el file to your load-path, and +;; add the following lines to your .emacs file: +;;(require 'json-snatcher) +;; (defun js-mode-bindings () +;; "Sets a hotkey for using the json-snatcher plugin." +;; (when (string-match "\\.json$" (buffer-name)) +;; (local-set-key (kbd "C-c C-g") 'jsons-print-path))) +;; (add-hook 'js-mode-hook 'js-mode-bindings) +;; (add-hook 'js2-mode-hook 'js-mode-bindings) +;; +;; This binds the key to snatch the path to the JSON value to C-c C-g only +;; when either JS mode, or JS2 mode is active on a buffer ending with +;; the .json extension. + +;;; License: + +;; 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 GNU Emacs; see the file COPYING. If not, write to the +;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +;; Boston, MA 02110-1301, USA. + +;;; Code: + + +(defvar jsons-curr-token 0 + "The current character in the buffer being parsed.") +(defvar jsons-parsed (make-hash-table :test 'equal) + "Hashes each open buffer to the parse tree for that buffer.") +(defvar jsons-parsed-regions (make-hash-table :test 'equal) + "Hashes each open buffer to the ranges in the buffer for each of the parse trees nodes.") +(defvar jsons-curr-region () "The node ranges in the current buffer.") +(defvar jsons-path-printer 'jsons-print-path-python "Default jsons path printer") +(add-hook 'kill-buffer-hook 'jsons-remove-buffer) + +(defun jsons-consume-token () + "Return the next token in the stream." + (goto-char jsons-curr-token) + (let* ((delim_regex "\\([\][\\{\\}:,]\\)") + ;; TODO: Improve this regex. Although now it SEEMS to be working, and can be + ;; used to validate escapes if needed later. The second half of the string regex is pretty + ;; pointless at the moment. I did it this way, so that the code closely mirrors + ;; the RFC. + (string_regex "\\(\"\\(\\([^\"\\\\\r\s\t\n]\\)*\\([\r\s\t\n]\\)*\\|\\(\\(\\\\\\\\\\)*\\\\\\(\\([^\r\s\t\n]\\|\\(u[0-9A-Fa-f]\\{4\\}\\)\\)\\)\\)\\)+\"\\)") + (num_regex "\\(-?\\(0\\|\\([1-9][[:digit:]]*\\)\\)\\(\\.[[:digit:]]+\\)?\\([eE][-+]?[[:digit:]]+\\)?\\)") + (literal_regex "\\(true\\|false\\|null\\)") + (full_regex (concat "\\(" delim_regex "\\|" literal_regex "\\|" string_regex "\\|" num_regex "\\)"))) + + (if (re-search-forward full_regex (point-max) "Not nil") + (progn + (setq jsons-curr-token (match-end 0)) + (buffer-substring-no-properties (match-beginning 0) (match-end 0))) + (message "Reached EOF. Possibly invalid JSON.")))) + +(defun jsons-array (path) + "Create a new json array object that contain the identifier \"json-array\". +a list of the elements contained in the array, and the PATH to the array." + (let*( + (token (jsons-consume-token)) + (array "json-array") + (elements ()) + (i 0)) + (while (not (string= token "]")) + (if (not (string= token ",")) + (let ((json-val (jsons-value token path i))) + (setq i (+ i 1)) + (push json-val elements) + (setq token (jsons-consume-token))) + (setq token (jsons-consume-token)))) + (list array (reverse elements) path))) + +(defun jsons-literal (token path) + "Given a TOKEN and PATH, this function return the PATH to the literal." + (let ((match_start (match-beginning 0)) + (match_end (match-end 0))) + (progn + (setq jsons-curr-region (append (list (list match_start match_end path)) jsons-curr-region)) + (list "json-literal" token path (list match_start match_end))))) + +(defun jsons-member (token path) + "This function is called when a member in a JSON object needs to be parsed. +Given the current TOKEN, and the PATH to this member." + (let* ((member ()) + (value token) + (range_start (match-beginning 0)) + (range_end (match-end 0)) + ) + (setq member (list "json-member" token)) + (if (not (string= (jsons-consume-token) ":")) + (error "Encountered token other than : in jsons-member") + nil) + (let ((json-val (jsons-value (jsons-consume-token) (cons value path) nil))) + (setq member (list member (append json-val + (list range_start range_end)))) + (setq jsons-curr-region (append (list (list range_start range_end (elt json-val 2))) jsons-curr-region)) + member))) + +(defun jsons-number (token path) + "This function will return a json-number given by the current TOKEN. +PATH points to the path to this number. A json-number is defined as per +the num_regex in the `jsons-get-tokens' function." + (progn + (setq jsons-curr-region (append (list (list (match-beginning 0) (match-end 0) path)) jsons-curr-region)) + (list "json-number" token path))) + +(defun jsons-object (path) + "This function is called when a { is encountered while parsing. +PATH is the path in the tree to this object." + (let*( + (token (jsons-consume-token)) + (members (make-hash-table :test 'equal)) + (object (list "json-object" members path))) + (while (not (string= token "}")) + (if (not (string= token ",")) + (let ((json-mem (jsons-member token path))) + (puthash (elt (elt json-mem 0) 1) (elt json-mem 1) (elt object 1)) + (setq token (jsons-consume-token))) + (setq token (jsons-consume-token)))) + object)) + +(defun jsons-string (token path) + "This function is called when a string is encountered while parsing. +The TOKEN is the current token being examined. +The PATH is the path to this string." +(let ((match_start (match-beginning 0)) + (match_end (match-end 0))) + (progn + (setq jsons-curr-region (append (list (list match_start match_end path)) jsons-curr-region)) + (list "json-string" token path (list match_start match_end))))) + +(defun jsons-value (token path array-index) + "A value, which is either an object, array, string, number, or literal. +The is-array variable is nil if inside an array, or the index in +the array that it occupies. +TOKEN is the current token being parsed. +PATH is the path to this value. +ARRAY-INDEX is non-nil if the value is contained within an array, and +points to the index of this value in the containing array." +;;TODO: Refactor the if array-index statement. + (if array-index + (if (jsons-is-number token) + (list "json-value" (jsons-number token (cons array-index path)) (list (match-beginning 0) (match-end 0))) + (cond + ((string= token "{") (jsons-object (cons array-index path))) + ((string= token "[") (jsons-array (cons array-index path))) + ((string= (substring token 0 1) "\"") (jsons-string token (cons array-index path))) + (t (jsons-literal token (cons array-index path))))) + (if (jsons-is-number token) + (list "json-value" (jsons-number token path) path (list (match-beginning 0) (match-end 0))) + (cond + ((string= token "{") (jsons-object path)) + ((string= token "[") (jsons-array path)) + ((string= (substring token 0 1) "\"") (jsons-string token path)) + (t (jsons-literal token path)))))) + + +(defun jsons-get-path () + "Function to check whether we can grab the json path from the cursor position in the json file." + (let ((i 0) + (node nil)) + (setq jsons-curr-region (gethash (current-buffer) jsons-parsed-regions)) + (when (not (gethash (current-buffer) jsons-parsed)) + (jsons-parse)) + (while (< i (length jsons-curr-region)) + (let* + ((json_region (elt jsons-curr-region i)) + (min_token (elt json_region 0)) + (max_token (elt json_region 1))) + (when (and (> (point) min_token) (< (point) max_token)) + (setq node (elt json_region 2)))) + (setq i (+ i 1))) + node)) + +(defun jsons-is-number (str) + "Test to see whether STR is a valid JSON number." + (progn + (match-end 0) + (save-match-data + (if (string-match "^\\(-?\\(0\\|\\([1-9][[:digit:]]*\\)\\)\\(\\.[[:digit:]]+\\)?\\([eE][-+]?[[:digit:]]+\\)?\\)$" str) + (progn + (match-end 0) + t) + nil)))) + +(defun jsons-parse () + "Parse the file given in file, return a list of nodes representing the file." + (save-excursion + (setq jsons-curr-token 0) + (setq jsons-curr-region ()) + (if (not (gethash (current-buffer) jsons-parsed)) + (let* ((token (jsons-consume-token)) + (return_val nil)) + (cond + ((string= token "{") (setq return_val (jsons-object ()))) + ((string= token "[") (setq return_val (jsons-array ()))) + (t nil)) + (puthash (current-buffer) return_val jsons-parsed) + (puthash (current-buffer) jsons-curr-region jsons-parsed-regions) + return_val) + (gethash (current-buffer) jsons-parsed)))) + +(defun jsons-print-to-buffer (node buffer) + "Prints the given NODE to the BUFFER specified in buffer argument. +TODO: Remove extra comma printed after lists of object members, and lists of array members." + (let ((id (elt node 0))) + (cond + ((string= id "json-array") + (progn + (jsons-put-string buffer "[") + (mapc (lambda (x) (progn + (jsons-print-to-buffer buffer x) + (jsons-put-string buffer ",") )) (elt node 1)) + (jsons-put-string buffer "]"))) + ((string= id "json-literal") + (jsons-put-string buffer (elt node 1))) + ((string= id "json-member") + (jsons-put-string buffer (elt node 1)) + (jsons-put-string buffer ": ") + (jsons-print-to-buffer buffer (elt node 2))) + ((string= id "json-number") + (jsons-put-string buffer (elt node 1))) + ((string= id "json-object") + (progn + (jsons-put-string buffer "{") + (maphash (lambda (key value) + (progn + (jsons-put-string buffer key) + (jsons-put-string buffer ":") + (jsons-print-to-buffer buffer value) + (jsons-put-string buffer ","))) (elt node 1)) + (jsons-put-string buffer "}"))) + ((string= id "json-string") + (jsons-put-string buffer (elt node 1))) + ((string= id "json-value") + (jsons-print-to-buffer buffer (elt node 1))) + (t nil)))) + +(defun jsons-print-path-jq () + "Print the jq path to the JSON value under point, and save it in the kill ring." + (let* ((path (jsons-get-path)) + (i 0) + (jq_str ".") + key) + (setq path (reverse path)) + (while (< i (length path)) + (if (numberp (elt path i)) + (progn + (setq jq_str (concat jq_str "[" (number-to-string (elt path i)) "]")) + (setq i (+ i 1))) + (progn + (setq key (elt path i)) + (setq jq_str (concat jq_str (substring key 1 (- (length key) 1)))) + (setq i (+ i 1)))) + (when (elt path i) + (unless (numberp (elt path i)) + (setq jq_str (concat jq_str "."))))) + (progn (kill-new jq_str) + (princ jq_str)))) + +(defun jsons-print-path-python () + "Print the python path to the JSON value under point, and save it in the kill ring." + (let ((path (jsons-get-path)) + (i 0) + (python_str "")) + (setq path (reverse path)) + (while (< i (length path)) + (if (numberp (elt path i)) + (progn + (setq python_str (concat python_str "[" (number-to-string (elt path i)) "]")) + (setq i (+ i 1))) + (progn + (setq python_str (concat python_str "[" (elt path i) "]")) + (setq i (+ i 1))))) + (progn (kill-new python_str) + (princ python_str)))) + +;;;###autoload +(defun jsons-print-path () + "Print the path to the JSON value under point, and save it in the kill ring." + (interactive) + (funcall jsons-path-printer)) + +(defun jsons-put-string (buffer str) + "Append STR to the BUFFER specified in the argument." + (save-current-buffer + (set-buffer (get-buffer-create buffer)) + (insert (prin1-to-string str t)))) + +(defun jsons-remove-buffer () + "Used to clean up the token regions, and parse tree used by the parser." + (progn + (remhash (current-buffer) jsons-parsed) + (remhash (current-buffer) jsons-parsed-regions))) + +(provide 'json-snatcher) + +;; Local-Variables: +;; indent-tabs-mode: nil +;; End: + +;;; json-snatcher.el ends here