functions.el 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. (defun define-word ()
  2. ;; TODO: needs refinement
  3. (interactive)
  4. (let ((myword (word-at-point)))
  5. ;; (message (shell-command-to-string (concat "mw " myword)))))
  6. (with-current-buffer (current-buffer)
  7. (save-excursion
  8. (set-buffer "worddef")
  9. (erase-buffer)))
  10. (call-process "mw" nil "worddef" nil myword)
  11. (with-current-buffer (current-buffer)
  12. (save-excursion
  13. (set-buffer "worddef")
  14. (ansi-color-apply-on-region (point-min) (point-max))))
  15. (display-buffer-pop-up-window (get-buffer "worddef") '())))
  16. ;; for tidying sexps
  17. (defun easy-indent-sexp ()
  18. (interactive)
  19. (end-of-defun)
  20. (backward-sexp)
  21. (indent-pp-sexp)
  22. (forward-sexp))
  23. (define-key lisp-mode-map (kbd "M-q") 'easy-indent-sexp)
  24. (define-key emacs-lisp-mode-map (kbd "M-q") 'easy-indent-sexp)
  25. ;; for writing keybindings and notes
  26. (defun notate-key-sequence ()
  27. (interactive)
  28. (insert (key-description (cdar (help--read-key-sequence t)))))
  29. (define-key global-map (kbd "C-c c") 'notate-key-sequence)
  30. ;; for working with messy json
  31. (defun tidy-json ()
  32. "Tidies the json in the buffer using python."
  33. (interactive)
  34. (shell-command-on-region (point-min) (point-max)
  35. "python3 -m json.tool"
  36. (current-buffer)
  37. t "*Python Json Error Buffer*" t))