ReverseFlux

org-hydra

Feb 9th, 2017
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. (defhydra hydra-org-template (:color blue :hint nil)
  2. "
  3. _c_enter _q_uote _e_macs-lisp _L_aTeX:
  4. _l_atex _E_xample _p_erl _i_ndex:
  5. _a_scii _v_erse _P_erl tangled _I_NCLUDE:
  6. _s_rc _n_ote plant_u_ml _H_TML:
  7. _h_tml ^ ^ ^ ^ _A_SCII:
  8. "
  9. ("s" (hot-expand "<s"))
  10. ("E" (hot-expand "<e"))
  11. ("q" (hot-expand "<q"))
  12. ("v" (hot-expand "<v"))
  13. ("n" (let (text) ; org-reveal speaker notes
  14. (when (region-active-p)
  15. (setq text (buffer-substring (region-beginning) (region-end)))
  16. (delete-region (region-beginning) (region-end)))
  17. (insert "#+BEGIN_NOTES\n\n#+END_NOTES")
  18. (forward-line -1)
  19. (when text (insert text))))
  20. ("c" (hot-expand "<c"))
  21. ("l" (hot-expand "<l"))
  22. ("h" (hot-expand "<h"))
  23. ("a" (hot-expand "<a"))
  24. ("L" (hot-expand "<L"))
  25. ("i" (hot-expand "<i"))
  26. ("e" (hot-expand "<s" "emacs-lisp"))
  27. ("p" (hot-expand "<s" "perl"))
  28. ("u" (hot-expand "<s" "plantuml :file CHANGE.png"))
  29. ("P" (hot-expand "<s" "perl" ":results output :exports both :shebang \"#!/usr/bin/env perl\"\n"))
  30. ("I" (hot-expand "<I"))
  31. ("H" (hot-expand "<H"))
  32. ("A" (hot-expand "<A"))
  33. ("<" self-insert-command "ins")
  34. ("o" nil "quit"))
  35.  
  36. (defun hot-expand (str &optional mod header)
  37. "Expand org template.
  38.  
  39. STR is a structure template string recognised by org like <s. MOD is a
  40. string with additional parameters to add the begin line of the
  41. structure element. HEADER string includes more parameters that are
  42. prepended to the element after the #+HEADERS: tag."
  43. (let (text)
  44. (when (region-active-p)
  45. (setq text (buffer-substring (region-beginning) (region-end)))
  46. (delete-region (region-beginning) (region-end))
  47. (deactivate-mark))
  48. (when header (insert "#+HEADERS: " header))
  49. (insert str)
  50. (org-try-structure-completion)
  51. (when mod (insert mod) (forward-line))
  52. (when text (insert text))))
  53.  
  54. (define-key org-mode-map "<"
  55. (lambda () (interactive)
  56. (if (or (region-active-p) (looking-back "^"))
  57. (hydra-org-template/body)
  58. (self-insert-command 1))))
Advertisement
Add Comment
Please, Sign In to add comment