Browse Source

more elisp goodies

Jordan Dashel 3 years ago
parent
commit
7d593bb32e
1 changed files with 25 additions and 0 deletions
  1. 25 0
      emacs/functions.el

+ 25 - 0
emacs/functions.el

@@ -13,3 +13,28 @@
 	(set-buffer "worddef")
 	(ansi-color-apply-on-region (point-min) (point-max))))
     (display-buffer-pop-up-window (get-buffer "worddef") '())))
+
+;; for tidying sexps
+(defun easy-indent-sexp ()
+  (interactive)
+  (end-of-defun)
+  (backward-sexp)
+  (indent-pp-sexp)
+  (forward-sexp))
+(define-key lisp-mode-map (kbd "M-q") 'easy-indent-sexp)
+(define-key emacs-lisp-mode-map (kbd "M-q") 'easy-indent-sexp)
+
+;; for writing keybindings and notes
+(defun notate-key-sequence ()
+  (interactive)
+  (insert (key-description (cdar (help--read-key-sequence t)))))
+(define-key global-map (kbd "C-c c") 'notate-key-sequence)
+
+;; for working with messy json
+(defun tidy-json ()
+  "Tidies the json in the buffer using python."
+  (interactive)
+  (shell-command-on-region (point-min) (point-max)
+                           "python3 -m json.tool"
+                           (current-buffer)
+                           t "*Python Json Error Buffer*" t))