init-org.el 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. (use-package org
  2. :mode ("\\.org\\'" . org-mode)
  3. :bind
  4. (:prefix-map qrthi/org-prefix
  5. :prefix "C-c o"
  6. ("a" . org-agenda)
  7. ("c" . org-capture)
  8. ("l" . org-store-link)
  9. ("t d" . org-clock-display)
  10. ("t g" . org-clock-goto)
  11. ("t l" . org-clock-in-last)
  12. ("t o" . org-clock-out)
  13. ("t r" . org-clock-report)
  14. ("t s" . org-clock-cancel)
  15. ("t i" . org-clock-in)
  16. )
  17. (:map org-mode-map
  18. ("M-h" . backward-kill-word)
  19. ("C-c >" . org-demote-subtree)
  20. ("C-c <" . org-promote-subtree)
  21. ("C-c o m f" . org-metaright)
  22. ("C-c o m b" . org-metaleft)
  23. ("C-c o m n" . org-metadown)
  24. ("C-c o m p" . org-metaup)
  25. )
  26. :custom
  27. (org-agenda-files `(,org-directory))
  28. ;; (org-agenda-sticky nil)
  29. (org-agenda-restore-windows-after-quit t)
  30. (org-cycle-level-faces nil)
  31. (org-clocktable-defaults
  32. '(:maxlevel 5 :scope subtree :block untilnow :wstart 1 :mstart 1 :indent t
  33. ))
  34. (org-directory (expand-file-name "org" qrthi/directory-documents))
  35. (org-todo-keywords
  36. '((sequence "TODO(t)" "IN-PROGRESS(i)" "WAITING(w)" "DONE(d)")
  37. ;; (sequence "TODO" "IN-PROGRESS" "|" "WAITING" "DONE")
  38. ))
  39. (org-todo-keyword-faces
  40. '(("TODO" . org-warning)
  41. ("WAITING" . org-agenda-dimmed-todo-face)))
  42. (org-src-window-setup 'current-window)
  43. (org-babel-load-languages
  44. '((emacs-lisp . t)
  45. (scheme . t)
  46. (ledger . t)
  47. (scheme . t)
  48. (python . t)
  49. (awk . t)))
  50. (org-clock-into-drawer "CLOCKING")
  51. (org-clock-persist t)
  52. :init
  53. (defun qrthi/org-fast-todo-selection (&optional current-state)
  54. "Fast TODO keyword selection with single keys.
  55. Returns the new TODO keyword, or nil if no state change should occur.
  56. When CURRENT-STATE is given and selection letters are not unique globally,
  57. prefer a state in the current sequence over on in another sequence."
  58. (let* ((fulltable org-todo-key-alist)
  59. (head (org-get-todo-sequence-head current-state))
  60. (done-keywords org-done-keywords) ;; needed for the faces.
  61. (maxlen (apply 'max (mapcar
  62. (lambda (x)
  63. (if (stringp (car x)) (string-width (car x)) 0))
  64. fulltable)))
  65. (expert (equal org-use-fast-todo-selection 'expert))
  66. (prompt "")
  67. (fwidth (+ maxlen 3 1 3))
  68. (ncol (/ (- (window-width) 4) fwidth))
  69. tg cnt e c tbl subtable
  70. groups ingroup in-current-sequence)
  71. (save-excursion
  72. (save-window-excursion
  73. (if expert
  74. (set-buffer (get-buffer-create " *Org todo*"))
  75. ;; (delete-other-windows)
  76. (set-window-buffer (split-window-vertically) (get-buffer-create " *Org todo*"))
  77. (org-switch-to-buffer-other-window " *Org todo*"))
  78. (erase-buffer)
  79. (setq-local org-done-keywords done-keywords)
  80. (setq tbl fulltable cnt 0)
  81. (while (setq e (pop tbl))
  82. (cond
  83. ((equal e '(:startgroup))
  84. (push '() groups) (setq ingroup t)
  85. (unless (= cnt 0)
  86. (setq cnt 0)
  87. (insert "\n"))
  88. (setq prompt (concat prompt "{"))
  89. (insert "{ "))
  90. ((equal e '(:endgroup))
  91. (setq ingroup nil cnt 0 in-current-sequence nil)
  92. (setq prompt (concat prompt "}"))
  93. (insert "}\n"))
  94. ((equal e '(:newline))
  95. (unless (= cnt 0)
  96. (setq cnt 0)
  97. (insert "\n")
  98. (setq e (car tbl))
  99. (while (equal (car tbl) '(:newline))
  100. (insert "\n")
  101. (setq tbl (cdr tbl)))))
  102. (t
  103. (setq tg (car e) c (cdr e))
  104. (if (equal tg head) (setq in-current-sequence t))
  105. (when ingroup (push tg (car groups)))
  106. (when in-current-sequence (push e subtable))
  107. (setq tg (org-add-props tg nil 'face
  108. (org-get-todo-face tg)))
  109. (when (and (= cnt 0) (not ingroup)) (insert " "))
  110. (setq prompt (concat prompt "[" (char-to-string c) "] " tg " "))
  111. (insert "[" c "] " tg (make-string
  112. (- fwidth 4 (length tg)) ?\ ))
  113. (when (and (= (setq cnt (1+ cnt)) ncol)
  114. ;; Avoid lines with just a closing delimiter.
  115. (not (equal (car tbl) '(:endgroup))))
  116. (insert "\n")
  117. (when ingroup (insert " "))
  118. (setq cnt 0)))))
  119. (insert "\n")
  120. (goto-char (point-min))
  121. (unless expert (org-fit-window-to-buffer))
  122. (message (concat "[a-z..]:Set [SPC]:clear"
  123. (if expert (concat "\n" prompt) "")))
  124. (setq c (let ((inhibit-quit t)) (read-char-exclusive)))
  125. (setq subtable (nreverse subtable))
  126. (cond
  127. ((or (= c ?\C-g)
  128. (and (= c ?q) (not (rassoc c fulltable))))
  129. (setq quit-flag t))
  130. ((= c ?\ ) nil)
  131. ((setq e (or (rassoc c subtable) (rassoc c fulltable))
  132. tg (car e))
  133. tg)
  134. (t (setq quit-flag t)))))))
  135. (defalias 'org-fast-todo-selection 'qrthi/org-fast-todo-selection)
  136. (org-clock-persistence-insinuate)
  137. )