Generate different colors for TODO keywords and tags
This commit is contained in:
parent
214eb35081
commit
abf97c386a
3 changed files with 58 additions and 1 deletions
|
@ -181,6 +181,12 @@ unit-test-oni-highlight-indent-guides:
|
|||
- package
|
||||
script: make unit-test-oni-highlight-indent-guides TEST_ARCHIVE=$(realpath bin/)
|
||||
|
||||
unit-test-oni-org:
|
||||
stage: unit-test
|
||||
dependencies:
|
||||
- package
|
||||
script: make unit-test-oni-org TEST_ARCHIVE=$(realpath bin/)
|
||||
|
||||
unit-test-oni-php:
|
||||
stage: unit-test
|
||||
dependencies:
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
;; Author: Tom Willemse <tom@ryuslash.org>
|
||||
;; Keywords: local
|
||||
;; Version: 2020.0108.161333
|
||||
;; Version: 2020.0113.225010
|
||||
;; Package-Requires: (oni-yasnippet org-plus-contrib org-bullets hydra org-wild-notifier)
|
||||
|
||||
;; This program is free software; you can redistribute it and/or modify
|
||||
|
@ -130,6 +130,37 @@ After running it once remove it from `org-capture-after-finalize-hook'."
|
|||
(interactive)
|
||||
(find-file (oni-org-expand-to-home "documents/gtd/index.org")))
|
||||
|
||||
(defun oni-org-color-for (object)
|
||||
"Generate a hex color by taking the first 6 characters of OBJECT’s MD5 sum."
|
||||
(format "#%s" (substring (md5 object) 0 6)))
|
||||
|
||||
(defun oni-org-generate-todo-keyword-faces ()
|
||||
"Create faces for all todo keywords in the current buffer."
|
||||
(when-let ((keywords (cl-remove-if (lambda (tag) (assoc tag org-todo-keyword-faces))
|
||||
org-todo-keywords-1)))
|
||||
(append org-todo-keyword-faces
|
||||
(mapcar (lambda (keyword) (cons keyword (oni-org-color-for keyword)))
|
||||
keywords))))
|
||||
|
||||
(defun oni-org-generate-tag-faces ()
|
||||
"Create faces for all the tags in the current buffer."
|
||||
(when-let ((tags (cl-remove-if (lambda (tag) (assoc (car tag) org-tag-faces))
|
||||
(org-get-buffer-tags))))
|
||||
(append org-tag-faces
|
||||
(mapcar (lambda (tag)
|
||||
(let ((tag (car tag)))
|
||||
(cons tag (oni-org-color-for tag))))
|
||||
tags))))
|
||||
|
||||
(defun oni-org-set-todo-keyword-faces ()
|
||||
"Set ‘org-todo-keyword-faces’ to all different colors."
|
||||
(setq org-todo-keyword-faces (oni-org-generate-todo-keyword-faces)))
|
||||
|
||||
(defun oni-org-set-tag-faces ()
|
||||
"Set ‘org-tag-faces’ to all different colors."
|
||||
(setq org-tag-faces (oni-org-generate-tag-faces))
|
||||
(org-set-tag-faces 'org-tag-faces org-tag-faces))
|
||||
|
||||
;;;###autoload(autoload 'oni-hydra-org/body "oni-org")
|
||||
(defhydra oni-hydra-org (:color blue)
|
||||
"Org"
|
||||
|
@ -203,6 +234,8 @@ After running it once remove it from `org-capture-after-finalize-hook'."
|
|||
|
||||
(add-hook 'org-mode-hook 'auto-fill-mode)
|
||||
(add-hook 'org-mode-hook 'flyspell-mode)
|
||||
(add-hook 'org-mode-hook #'oni-org-set-todo-keyword-faces)
|
||||
(add-hook 'org-mode-hook #'oni-org-set-tag-faces)
|
||||
|
||||
(unless (eq system-type 'windows-nt)
|
||||
(require 'org-bullets)
|
||||
|
|
18
test/oni-org-test.el
Normal file
18
test/oni-org-test.el
Normal file
|
@ -0,0 +1,18 @@
|
|||
(ert-deftest oni-org-test-color-for ()
|
||||
"Test that ‘oni-org-color-for’ returns a hex color name."
|
||||
(should (string= "#acbd18" (oni-org-color-for "foo"))))
|
||||
|
||||
(ert-deftest oni-org-test-generate-todo-keyword-faces ()
|
||||
"Test that ‘oni-org-generate-todo-keyword-faces’ returns a list of colors."
|
||||
(let ((org-todo-keywords-1 '("foo" "bar")))
|
||||
(should (equal (oni-org-generate-todo-keyword-faces)
|
||||
'(("foo" . "#acbd18")
|
||||
("bar" . "#37b51d"))))))
|
||||
|
||||
(ert-deftest oni-org-test-generate-tag-faces ()
|
||||
"Test that ‘oni-org-generate-tag-faces’ returns a list of colors."
|
||||
(cl-letf (((symbol-function 'org-get-buffer-tags)
|
||||
(lambda () '(("foo") ("bar")))))
|
||||
(should (equal (oni-org-generate-tag-faces)
|
||||
'(("foo" . "#acbd18")
|
||||
("bar" . "#37b51d"))))))
|
Loading…
Reference in a new issue