diff options
author | Martin Polden <martin.polden@gmail.com> | 2016-02-26 12:19:29 +0100 |
---|---|---|
committer | Martin Polden <martin.polden@gmail.com> | 2016-02-26 12:20:47 +0100 |
commit | ae0167f4fc8b1967da69aa38de56e1fcd145cae3 (patch) | |
tree | 2589a6f50fca8a860c31a5714446a2fe189e368c /lisp/init-javascript.el | |
parent | 0b5bc699739e6161dfcb4eb7ef8042728ea362df (diff) |
Define functions in :config
Diffstat (limited to 'lisp/init-javascript.el')
-rw-r--r-- | lisp/init-javascript.el | 55 |
1 files changed, 28 insertions, 27 deletions
diff --git a/lisp/init-javascript.el b/lisp/init-javascript.el index 0571c85..309e883 100644 --- a/lisp/init-javascript.el +++ b/lisp/init-javascript.el @@ -11,34 +11,35 @@ :bind (:map js-mode-map ;; C-c p runs formats json with jq - ("C-c p" . jq-reformat))) + ("C-c p" . jq-reformat)) -;; use jq for reformatting json -(defun jq-reformat-region (begin end) - (interactive "r") - (if (executable-find "jq") - (let* ((tmpfile (make-temp-file "jq")) - (errbuf (get-buffer-create "*jq errors*")) - (result (call-process-region begin end "jq" nil - `((:file ,tmpfile) ,tmpfile) nil - "--monochrome-output" "--ascii-output" - ".")) - (success (zerop result)) - (resbuf (if success (current-buffer) errbuf))) - (with-current-buffer resbuf - (insert-file-contents tmpfile nil nil nil t)) - (if success - (progn - (kill-buffer errbuf) - (message "Reformatted JSON")) - (message "Failed to reformat JSON. Check errors for details")) - (delete-file tmpfile)) - (message "Could not find jq in PATH."))) + :config + ;; use jq for reformatting json + (defun jq-reformat-region (begin end) + (interactive "r") + (if (executable-find "jq") + (let* ((tmpfile (make-temp-file "jq")) + (errbuf (get-buffer-create "*jq errors*")) + (result (call-process-region begin end "jq" nil + `((:file ,tmpfile) ,tmpfile) nil + "--monochrome-output" "--ascii-output" + ".")) + (success (zerop result)) + (resbuf (if success (current-buffer) errbuf))) + (with-current-buffer resbuf + (insert-file-contents tmpfile nil nil nil t)) + (if success + (progn + (kill-buffer errbuf) + (message "Reformatted JSON")) + (message "Failed to reformat JSON. Check errors for details")) + (delete-file tmpfile)) + (message "Could not find jq in PATH."))) -(defun jq-reformat () - (interactive) - (if (use-region-p) - (jq-reformat-region (region-beginning) (region-end)) - (jq-reformat-region (point-min) (point-max)))) + (defun jq-reformat () + (interactive) + (if (use-region-p) + (jq-reformat-region (region-beginning) (region-end)) + (jq-reformat-region (point-min) (point-max))))) (provide 'init-javascript) |