helpers.el 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. (defun display-full-buffer-path ()
  2. (interactive)
  3. "Little helper for showing full file path in minibuffer"
  4. (message (buffer-file-name)))
  5. ;;; See great post here:
  6. ;;; https://www.manueluberti.eu/emacs/2018/02/17/magit-bury-buffer/
  7. (defun mu-magit-kill-buffers ()
  8. "Restore window configuration and kill all Magit buffers."
  9. (interactive)
  10. (let ((buffers (magit-mode-get-buffers)))
  11. (magit-restore-window-configuration)
  12. (mapc #'kill-buffer buffers)))
  13. (defcustom *last-pb-url* nil
  14. "Contains the URL of the last post to the pastebin."
  15. :set (lambda (sym val)
  16. (set-default sym val)
  17. (message "Set %s to %s" sym val)))
  18. ;; See: https://with-emacs.com/posts/tutorials/almost-all-you-need-to-know-about-variables/
  19. (defmacro csetq (sym val)
  20. `(funcall (or (get ',sym 'custom-set) 'set-default) ',sym ,val))
  21. (defun post-region-to-pb ()
  22. "Post buffer to http://chate.io pastebin"
  23. (interactive)
  24. (csetq *last-pb-url*
  25. (substring
  26. (with-output-to-string
  27. (shell-command-on-region
  28. (region-beginning)
  29. (region-end)
  30. "curl -s -F \"file=@-\" -H \"expire:60min\" http://chate.io:669"
  31. standard-output))
  32. 0 -1))
  33. (message *last-pb-url*)
  34. ;; There may be a more direct way to
  35. ;; do this?
  36. (with-temp-buffer
  37. (insert *last-pb-url*)
  38. (clipboard-kill-region (point-min) (point-max))))
  39. (defun display-pb (&optional url-arg)
  40. "Display either last pb url content, or passed URL.
  41. Can also be used to display HTML/text via curl in new buf."
  42. (interactive)
  43. (let* ((url (if url-arg url-arg *last-pb-url*))
  44. (r
  45. (shell-command-to-string (format "curl -s %s" url))))
  46. (switch-to-buffer
  47. (get-buffer-create url))
  48. (insert r)))