helpers.el 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 ()
  40. "Display last pb url content, see *last-pb-url*"
  41. (interactive)
  42. (let* ((url (if *last-pb-url* *last-pb-url* (error "*last-pb-url* void")))
  43. (r
  44. (shell-command-to-string (format "curl -s %s" url))))
  45. (switch-to-buffer
  46. (get-buffer-create url))
  47. (insert r)))