changelog shortlog graph tags branches changeset files revisions annotate raw help

Mercurial > core / emacs/lib/ulang.el

changeset 626: cc13027df6fa
parent: a304c9713a51
child: 3af20cb389e8
author: Richard Westhaver <ellis@rwest.io>
date: Mon, 26 Aug 2024 20:09:01 -0400
permissions: -rw-r--r--
description: ulang and cli updates
1 ;;; ulang.el --- ulang compliance lib -*- lexical-binding:t -*-
2 
3 ;; Copyright (C) 2023
4 
5 ;; Author: <ellis@zor>
6 ;; Keywords: comm
7 
8 ;; This program is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
12 
13 ;; This program is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
17 
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with this program. If not, see <https://www.gnu.org/licenses/>.
20 
21 ;;; Commentary:
22 
23 ;;
24 
25 
26 ;;; Code:
27 (require 'org)
28 (require 'ox)
29 
30 (defgroup ulang nil
31  "CC Universal Language.")
32 
33 (defvar ulang-link-history nil)
34 (defvar ulang-file-history nil)
35 
36 (defvar ulang-categories
37  (list "note" "link" "code" "doc" "project" "data"))
38 
39 ;; FIX 2024-08-26: doesn't work
40 (defun org-category-allowed-values (prop)
41  (when (string= (upcase prop) "CATEGORY")
42  (append ulang-categories (list ":ETC"))))
43 
44 (cl-pushnew #'org-category-allowed-values org-property-allowed-value-functions)
45 
46 ;;;###autoload
47 (defun dblock-insert-links (regexp)
48  "Create dblock to insert links matching REGEXP."
49  (interactive (list (read-regexp "Insert links matching: " nil ulang-links-history)))
50  (org-create-dblock (list :name "links"
51  :regexp regexp
52  :id-only nil))
53  (org-update-dblock))
54 
55 (org-dynamic-block-define "links" 'dblock-insert-links)
56 
57 (org-export-translate-to-lang (list '("Table of Contents" "Index")) "ulang")
58 ;; (setq org-export-global-macros nil)
59 
60 ;; todo keywords
61 (setq org-stuck-projects '("+PROJECT/-DONE" ("NEXT") nil ""))
62 
63 (setq org-todo-keywords
64  '((sequence "TBD(0!)" "TODO(t!)" "NEXT(n!)" "WIP(i!)" "|" "DONE(d!)")
65  (sequence "HOLD(H@/!)" "WIP(!)" "|")
66  (sequence "WAIT(W@/!)" "WIP(!)" "|")
67  (sequence "RESEARCH(s!)" "REPORT(c!)" "|")
68  (sequence "OUTLINE(O!)" "DRAFT(M!)" "REVIEW(V!)" "|")
69  (type "FIND(q!)" "READ(r@!)" "WATCH(A@!)" "HACK(h!)"
70  "CODE(c!)" "BENCH(b!)" "DEPLOY(D!)" "RUN(X!)"
71  "REFILE(w!)"
72  "LOG(L!)" "GOTO(g!)" "|")
73  (type "FIXME(f!)" "WIP(!)" "TEST(T!)" "|")
74  (type "PROJECT(p!)" "PRODUCT(P!)" "SPRINT(S!)" "RELEASE(R!)" "|")
75  (sequence "|" "DONE(d!)" "NOPE(x@!)")))
76 
77 (setq org-todo-keyword-faces
78  '(("PROJECT" . (:foreground "lightseagreen" :weight bold))
79  ("PRODUCT" . (:foreground "olivedrab" :weight bold))
80  ("RELEASE" . (:foreground "maroon3" :weight bold))
81  ("RESEARCH" . (:foreground "maroon2" :weight bold))
82  ("HACK" . (:foreground "maroon3" :weight bold))
83  ("TBD" . (:foreground "darkred2" :weight bold))
84  ;; ("NOTE" . (:foreground "tomato2" :weight bold))
85  ("CODE" . (:foreground "bisque" :weight bold :background "midnightblue"))
86  ("HOLD" . (:foreground "red1" :weight bold :background "yellow1"))
87  ("WAIT" . (:foreground "red4" :weight bold :background "yellow1"))
88  ("WIP" . (:foreground "darkorchid2" :weight bold))
89  ("NOPE" . (:foreground "hotpink" :weight bold :background "darkgreen"))))
90 
91 ;; link abbrevs
92 (setq org-link-abbrev-alist
93  '(("vc" . "https://vc.compiler.company/%s")
94  ("comp" . "https://compiler.company/%s")
95  ("cdn" . "https://cdn.compiler.company/%s")
96  ("packy" . "https://packy.compiler.company/%s")
97  ("yt" . "https://youtube.com/watch?v=%s")
98  ("wikipedia" . "https://en.wikipedia.org/wiki/%s")
99  ("reddit" . "https://reddit.com/%s")
100  ("hn" . "https://news.ycombinator.com/%s")
101  ("so" . "https://stackoverflow.com/%s")))
102 
103 ;;; IDs
104 (defun org-custom-id-get (&optional pom create prefix)
105  "Get the CUSTOM_ID property of the entry at point-or-marker POM.
106  If POM is nil, refer to the entry at point. If the entry does
107  not have an CUSTOM_ID, the function returns nil. However, when
108  CREATE is non nil, create a CUSTOM_ID if none is present
109  already. PREFIX will be passed through to `org-id-new'. In any
110  case, the CUSTOM_ID of the entry is returned."
111  (interactive)
112 (org-with-point-at pom
113  (let ((id (org-entry-get nil "CUSTOM_ID"))
114  ;; use CUSTOM_ID for links
115  (org-id-link-to-org-use-id 'create-if-interactive-and-no-custom-id))
116  (cond
117  ((and id (stringp id) (string-match "\\S-" id))
118  id)
119  (create
120  (setq id (org-id-new prefix))
121  (org-entry-put pom "CUSTOM_ID" id)
122  (org-id-add-location id (buffer-file-name (buffer-base-buffer)))
123  id)))))
124 
125 ;;;###autoload
126 (defun org-id-add-to-headlines-in-file ()
127  "Add ID properties to all headlines in the
128  current file which do not already have one."
129  (interactive)
130  (org-map-entries (lambda () (org-id-get (point) 'create))))
131 
132 (defun org-custom-id-add-to-headlines-in-file ()
133  "Add CUSTOM_ID properties to all headlines in the
134  current file which do not already have one."
135  (interactive)
136  (org-map-entries (lambda () (org-custom-id-get (point) 'create))))
137 
138 (defun org-id-add-to-headlines-in-files (&optional files)
139  (interactive)
140  (with-temp-buffer
141  (dolist (f (or files org-agenda-files))
142  (find-file f)
143  (org-id-add-to-headlines-in-file)
144  (save-buffer))))
145 
146 (defun org-id-add-to-headlines-in-directory (&optional dir)
147  (interactive)
148  (let ((dir (or dir org-directory)))
149  (org-id-add-to-headlines-in-files
150  (directory-files-recursively dir "[.]org$"))))
151 
152 (message "Initialized ULANG.")
153 
154 (provide 'ulang)
155 ;;; ulang.el ends here