changeset 639: | 32375ed43c74 |
parent: | 6c0e4a44c082 |
child: | 642b3b82b20d |
author: | Richard Westhaver <ellis@rwest.io> |
date: | Sun, 08 Sep 2024 12:24:33 -0400 |
permissions: | -rw-r--r-- |
description: | org-set-location |
587 | 1 | ;;; ulang.el --- ulang compliance lib -*- lexical-binding:t -*- |
50
e62a6a0d5997
organ/lexer, ulang support, gui and web stuff
ellis <ellis@rwest.io>
parents:
diff
changeset
|
2 | |
e62a6a0d5997
organ/lexer, ulang support, gui and web stuff
ellis <ellis@rwest.io>
parents:
diff
changeset
|
3 | ;; Copyright (C) 2023 |
e62a6a0d5997
organ/lexer, ulang support, gui and web stuff
ellis <ellis@rwest.io>
parents:
diff
changeset
|
4 | |
e62a6a0d5997
organ/lexer, ulang support, gui and web stuff
ellis <ellis@rwest.io>
parents:
diff
changeset
|
5 | ;; Author: <ellis@zor> |
e62a6a0d5997
organ/lexer, ulang support, gui and web stuff
ellis <ellis@rwest.io>
parents:
diff
changeset
|
6 | ;; Keywords: comm |
e62a6a0d5997
organ/lexer, ulang support, gui and web stuff
ellis <ellis@rwest.io>
parents:
diff
changeset
|
7 | |
e62a6a0d5997
organ/lexer, ulang support, gui and web stuff
ellis <ellis@rwest.io>
parents:
diff
changeset
|
8 | ;; This program is free software; you can redistribute it and/or modify |
e62a6a0d5997
organ/lexer, ulang support, gui and web stuff
ellis <ellis@rwest.io>
parents:
diff
changeset
|
9 | ;; it under the terms of the GNU General Public License as published by |
e62a6a0d5997
organ/lexer, ulang support, gui and web stuff
ellis <ellis@rwest.io>
parents:
diff
changeset
|
10 | ;; the Free Software Foundation, either version 3 of the License, or |
e62a6a0d5997
organ/lexer, ulang support, gui and web stuff
ellis <ellis@rwest.io>
parents:
diff
changeset
|
11 | ;; (at your option) any later version. |
e62a6a0d5997
organ/lexer, ulang support, gui and web stuff
ellis <ellis@rwest.io>
parents:
diff
changeset
|
12 | |
e62a6a0d5997
organ/lexer, ulang support, gui and web stuff
ellis <ellis@rwest.io>
parents:
diff
changeset
|
13 | ;; This program is distributed in the hope that it will be useful, |
e62a6a0d5997
organ/lexer, ulang support, gui and web stuff
ellis <ellis@rwest.io>
parents:
diff
changeset
|
14 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
e62a6a0d5997
organ/lexer, ulang support, gui and web stuff
ellis <ellis@rwest.io>
parents:
diff
changeset
|
15 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
e62a6a0d5997
organ/lexer, ulang support, gui and web stuff
ellis <ellis@rwest.io>
parents:
diff
changeset
|
16 | ;; GNU General Public License for more details. |
e62a6a0d5997
organ/lexer, ulang support, gui and web stuff
ellis <ellis@rwest.io>
parents:
diff
changeset
|
17 | |
e62a6a0d5997
organ/lexer, ulang support, gui and web stuff
ellis <ellis@rwest.io>
parents:
diff
changeset
|
18 | ;; You should have received a copy of the GNU General Public License |
e62a6a0d5997
organ/lexer, ulang support, gui and web stuff
ellis <ellis@rwest.io>
parents:
diff
changeset
|
19 | ;; along with this program. If not, see <https://www.gnu.org/licenses/>. |
e62a6a0d5997
organ/lexer, ulang support, gui and web stuff
ellis <ellis@rwest.io>
parents:
diff
changeset
|
20 | |
e62a6a0d5997
organ/lexer, ulang support, gui and web stuff
ellis <ellis@rwest.io>
parents:
diff
changeset
|
21 | ;;; Commentary: |
e62a6a0d5997
organ/lexer, ulang support, gui and web stuff
ellis <ellis@rwest.io>
parents:
diff
changeset
|
22 | |
e62a6a0d5997
organ/lexer, ulang support, gui and web stuff
ellis <ellis@rwest.io>
parents:
diff
changeset
|
23 | ;; |
623 | 24 | |
50
e62a6a0d5997
organ/lexer, ulang support, gui and web stuff
ellis <ellis@rwest.io>
parents:
diff
changeset
|
25 | |
e62a6a0d5997
organ/lexer, ulang support, gui and web stuff
ellis <ellis@rwest.io>
parents:
diff
changeset
|
26 | ;;; Code: |
57 | 27 | (require 'org) |
59 | 28 | (require 'ox) |
623 | 29 | |
30 | (defgroup ulang nil |
|
31 | "CC Universal Language.") |
|
32 | ||
33 | (defvar ulang-link-history nil) |
|
34 | (defvar ulang-file-history nil) |
|
586
7ce855f76e1d
net/fetch upgrades, fixes, net/err -> net/condition
Richard Westhaver <ellis@rwest.io>
parents:
428
diff
changeset
|
35 | |
631 | 36 | ;; see org-special-properties |
37 | (defvar ulang-special-properties |
|
630
f4a464cc1628
skel/vm work, added json benchmark
Richard Westhaver <ellis@rwest.io>
parents:
628
diff
changeset
|
38 | '("VERSION")) |
f4a464cc1628
skel/vm work, added json benchmark
Richard Westhaver <ellis@rwest.io>
parents:
628
diff
changeset
|
39 | |
50
e62a6a0d5997
organ/lexer, ulang support, gui and web stuff
ellis <ellis@rwest.io>
parents:
diff
changeset
|
40 | ;;;###autoload |
623 | 41 | (defun dblock-insert-links (regexp) |
57 | 42 | "Create dblock to insert links matching REGEXP." |
631 | 43 | (interactive (list (read-regexp "Insert links matching: " nil ulang-link-history))) |
57 | 44 | (org-create-dblock (list :name "links" |
45 | :regexp regexp |
|
46 | :id-only nil)) |
|
47 | (org-update-dblock)) |
|
48 | ||
623 | 49 | (org-dynamic-block-define "links" 'dblock-insert-links) |
57 | 50 | |
638 | 51 | ;; (org-export-translate-to-lang (list '("Table of Contents" "Index")) "ulang") |
623 | 52 | ;; (setq org-export-global-macros nil) |
57 | 53 | |
604
74a55d5decce
emacs org libraries and upgrades
Richard Westhaver <ellis@rwest.io>
parents:
596
diff
changeset
|
54 | ;; todo keywords |
618
5e57683a0c28
rocksdb updates and tests, emacs org config
Richard Westhaver <ellis@rwest.io>
parents:
611
diff
changeset
|
55 | (setq org-stuck-projects '("+PROJECT/-DONE" ("NEXT") nil "")) |
604
74a55d5decce
emacs org libraries and upgrades
Richard Westhaver <ellis@rwest.io>
parents:
596
diff
changeset
|
56 | |
587 | 57 | (setq org-todo-keywords |
626 | 58 | '((sequence "TBD(0!)" "TODO(t!)" "NEXT(n!)" "WIP(i!)" "|" "DONE(d!)") |
59 | (sequence "HOLD(H@/!)" "WIP(!)" "|") |
|
60 | (sequence "WAIT(W@/!)" "WIP(!)" "|") |
|
630
f4a464cc1628
skel/vm work, added json benchmark
Richard Westhaver <ellis@rwest.io>
parents:
628
diff
changeset
|
61 | (sequence "RESEARCH(s!)" "WIP(!)" "REPORT(c!)" "|") |
619 | 62 | (sequence "OUTLINE(O!)" "DRAFT(M!)" "REVIEW(V!)" "|") |
630
f4a464cc1628
skel/vm work, added json benchmark
Richard Westhaver <ellis@rwest.io>
parents:
628
diff
changeset
|
63 | (sequence "FIXME(f!)" "WIP(!)" "TEST(T!)" "|") |
626 | 64 | (type "FIND(q!)" "READ(r@!)" "WATCH(A@!)" "HACK(h!)" |
65 | "CODE(c!)" "BENCH(b!)" "DEPLOY(D!)" "RUN(X!)" |
|
630
f4a464cc1628
skel/vm work, added json benchmark
Richard Westhaver <ellis@rwest.io>
parents:
628
diff
changeset
|
66 | "REFILE(w!)" "LOG(L!)" "GOTO(g!)" "|") |
596 | 67 | (type "PROJECT(p!)" "PRODUCT(P!)" "SPRINT(S!)" "RELEASE(R!)" "|") |
626 | 68 | (sequence "|" "DONE(d!)" "NOPE(x@!)"))) |
587 | 69 | |
70 | (setq org-todo-keyword-faces |
|
71 | '(("PROJECT" . (:foreground "lightseagreen" :weight bold)) |
|
596 | 72 | ("PRODUCT" . (:foreground "olivedrab" :weight bold)) |
73 | ("RELEASE" . (:foreground "maroon3" :weight bold)) |
|
74 | ("RESEARCH" . (:foreground "maroon2" :weight bold)) |
|
75 | ("HACK" . (:foreground "maroon3" :weight bold)) |
|
630
f4a464cc1628
skel/vm work, added json benchmark
Richard Westhaver <ellis@rwest.io>
parents:
628
diff
changeset
|
76 | ("TBD" . (:foreground "brown" :weight bold)) |
596 | 77 | ("CODE" . (:foreground "bisque" :weight bold :background "midnightblue")) |
78 | ("HOLD" . (:foreground "red1" :weight bold :background "yellow1")) |
|
79 | ("WAIT" . (:foreground "red4" :weight bold :background "yellow1")) |
|
80 | ("WIP" . (:foreground "darkorchid2" :weight bold)) |
|
81 | ("NOPE" . (:foreground "hotpink" :weight bold :background "darkgreen")))) |
|
587 | 82 | |
604
74a55d5decce
emacs org libraries and upgrades
Richard Westhaver <ellis@rwest.io>
parents:
596
diff
changeset
|
83 | ;; link abbrevs |
57 | 84 | (setq org-link-abbrev-alist |
85 | '(("vc" . "https://vc.compiler.company/%s") |
|
86 | ("comp" . "https://compiler.company/%s") |
|
87 | ("cdn" . "https://cdn.compiler.company/%s") |
|
88 | ("packy" . "https://packy.compiler.company/%s") |
|
596 | 89 | ("yt" . "https://youtube.com/watch?v=%s") |
90 | ("wikipedia" . "https://en.wikipedia.org/wiki/%s") |
|
91 | ("reddit" . "https://reddit.com/%s") |
|
92 | ("hn" . "https://news.ycombinator.com/%s") |
|
93 | ("so" . "https://stackoverflow.com/%s"))) |
|
57 | 94 | |
588
0552341ac196
refactor org-id stuff to ulang, pkgbuild notes
Richard Westhaver <ellis@rwest.io>
parents:
587
diff
changeset
|
95 | ;;; IDs |
0552341ac196
refactor org-id stuff to ulang, pkgbuild notes
Richard Westhaver <ellis@rwest.io>
parents:
587
diff
changeset
|
96 | (defun org-custom-id-get (&optional pom create prefix) |
0552341ac196
refactor org-id stuff to ulang, pkgbuild notes
Richard Westhaver <ellis@rwest.io>
parents:
587
diff
changeset
|
97 | "Get the CUSTOM_ID property of the entry at point-or-marker POM. |
0552341ac196
refactor org-id stuff to ulang, pkgbuild notes
Richard Westhaver <ellis@rwest.io>
parents:
587
diff
changeset
|
98 | If POM is nil, refer to the entry at point. If the entry does |
0552341ac196
refactor org-id stuff to ulang, pkgbuild notes
Richard Westhaver <ellis@rwest.io>
parents:
587
diff
changeset
|
99 | not have an CUSTOM_ID, the function returns nil. However, when |
0552341ac196
refactor org-id stuff to ulang, pkgbuild notes
Richard Westhaver <ellis@rwest.io>
parents:
587
diff
changeset
|
100 | CREATE is non nil, create a CUSTOM_ID if none is present |
0552341ac196
refactor org-id stuff to ulang, pkgbuild notes
Richard Westhaver <ellis@rwest.io>
parents:
587
diff
changeset
|
101 | already. PREFIX will be passed through to `org-id-new'. In any |
0552341ac196
refactor org-id stuff to ulang, pkgbuild notes
Richard Westhaver <ellis@rwest.io>
parents:
587
diff
changeset
|
102 | case, the CUSTOM_ID of the entry is returned." |
0552341ac196
refactor org-id stuff to ulang, pkgbuild notes
Richard Westhaver <ellis@rwest.io>
parents:
587
diff
changeset
|
103 | (interactive) |
0552341ac196
refactor org-id stuff to ulang, pkgbuild notes
Richard Westhaver <ellis@rwest.io>
parents:
587
diff
changeset
|
104 | (org-with-point-at pom |
0552341ac196
refactor org-id stuff to ulang, pkgbuild notes
Richard Westhaver <ellis@rwest.io>
parents:
587
diff
changeset
|
105 | (let ((id (org-entry-get nil "CUSTOM_ID")) |
0552341ac196
refactor org-id stuff to ulang, pkgbuild notes
Richard Westhaver <ellis@rwest.io>
parents:
587
diff
changeset
|
106 | ;; use CUSTOM_ID for links |
0552341ac196
refactor org-id stuff to ulang, pkgbuild notes
Richard Westhaver <ellis@rwest.io>
parents:
587
diff
changeset
|
107 | (org-id-link-to-org-use-id 'create-if-interactive-and-no-custom-id)) |
0552341ac196
refactor org-id stuff to ulang, pkgbuild notes
Richard Westhaver <ellis@rwest.io>
parents:
587
diff
changeset
|
108 | (cond |
0552341ac196
refactor org-id stuff to ulang, pkgbuild notes
Richard Westhaver <ellis@rwest.io>
parents:
587
diff
changeset
|
109 | ((and id (stringp id) (string-match "\\S-" id)) |
0552341ac196
refactor org-id stuff to ulang, pkgbuild notes
Richard Westhaver <ellis@rwest.io>
parents:
587
diff
changeset
|
110 | id) |
0552341ac196
refactor org-id stuff to ulang, pkgbuild notes
Richard Westhaver <ellis@rwest.io>
parents:
587
diff
changeset
|
111 | (create |
0552341ac196
refactor org-id stuff to ulang, pkgbuild notes
Richard Westhaver <ellis@rwest.io>
parents:
587
diff
changeset
|
112 | (setq id (org-id-new prefix)) |
0552341ac196
refactor org-id stuff to ulang, pkgbuild notes
Richard Westhaver <ellis@rwest.io>
parents:
587
diff
changeset
|
113 | (org-entry-put pom "CUSTOM_ID" id) |
0552341ac196
refactor org-id stuff to ulang, pkgbuild notes
Richard Westhaver <ellis@rwest.io>
parents:
587
diff
changeset
|
114 | (org-id-add-location id (buffer-file-name (buffer-base-buffer))) |
0552341ac196
refactor org-id stuff to ulang, pkgbuild notes
Richard Westhaver <ellis@rwest.io>
parents:
587
diff
changeset
|
115 | id))))) |
0552341ac196
refactor org-id stuff to ulang, pkgbuild notes
Richard Westhaver <ellis@rwest.io>
parents:
587
diff
changeset
|
116 | |
0552341ac196
refactor org-id stuff to ulang, pkgbuild notes
Richard Westhaver <ellis@rwest.io>
parents:
587
diff
changeset
|
117 | ;;;###autoload |
0552341ac196
refactor org-id stuff to ulang, pkgbuild notes
Richard Westhaver <ellis@rwest.io>
parents:
587
diff
changeset
|
118 | (defun org-id-add-to-headlines-in-file () |
0552341ac196
refactor org-id stuff to ulang, pkgbuild notes
Richard Westhaver <ellis@rwest.io>
parents:
587
diff
changeset
|
119 | "Add ID properties to all headlines in the |
0552341ac196
refactor org-id stuff to ulang, pkgbuild notes
Richard Westhaver <ellis@rwest.io>
parents:
587
diff
changeset
|
120 | current file which do not already have one." |
0552341ac196
refactor org-id stuff to ulang, pkgbuild notes
Richard Westhaver <ellis@rwest.io>
parents:
587
diff
changeset
|
121 | (interactive) |
0552341ac196
refactor org-id stuff to ulang, pkgbuild notes
Richard Westhaver <ellis@rwest.io>
parents:
587
diff
changeset
|
122 | (org-map-entries (lambda () (org-id-get (point) 'create)))) |
0552341ac196
refactor org-id stuff to ulang, pkgbuild notes
Richard Westhaver <ellis@rwest.io>
parents:
587
diff
changeset
|
123 | |
0552341ac196
refactor org-id stuff to ulang, pkgbuild notes
Richard Westhaver <ellis@rwest.io>
parents:
587
diff
changeset
|
124 | (defun org-custom-id-add-to-headlines-in-file () |
0552341ac196
refactor org-id stuff to ulang, pkgbuild notes
Richard Westhaver <ellis@rwest.io>
parents:
587
diff
changeset
|
125 | "Add CUSTOM_ID properties to all headlines in the |
0552341ac196
refactor org-id stuff to ulang, pkgbuild notes
Richard Westhaver <ellis@rwest.io>
parents:
587
diff
changeset
|
126 | current file which do not already have one." |
0552341ac196
refactor org-id stuff to ulang, pkgbuild notes
Richard Westhaver <ellis@rwest.io>
parents:
587
diff
changeset
|
127 | (interactive) |
0552341ac196
refactor org-id stuff to ulang, pkgbuild notes
Richard Westhaver <ellis@rwest.io>
parents:
587
diff
changeset
|
128 | (org-map-entries (lambda () (org-custom-id-get (point) 'create)))) |
0552341ac196
refactor org-id stuff to ulang, pkgbuild notes
Richard Westhaver <ellis@rwest.io>
parents:
587
diff
changeset
|
129 | |
623 | 130 | (defun org-id-add-to-headlines-in-files (&optional files) |
588
0552341ac196
refactor org-id stuff to ulang, pkgbuild notes
Richard Westhaver <ellis@rwest.io>
parents:
587
diff
changeset
|
131 | (interactive) |
0552341ac196
refactor org-id stuff to ulang, pkgbuild notes
Richard Westhaver <ellis@rwest.io>
parents:
587
diff
changeset
|
132 | (with-temp-buffer |
623 | 133 | (dolist (f (or files org-agenda-files)) |
588
0552341ac196
refactor org-id stuff to ulang, pkgbuild notes
Richard Westhaver <ellis@rwest.io>
parents:
587
diff
changeset
|
134 | (find-file f) |
0552341ac196
refactor org-id stuff to ulang, pkgbuild notes
Richard Westhaver <ellis@rwest.io>
parents:
587
diff
changeset
|
135 | (org-id-add-to-headlines-in-file) |
0552341ac196
refactor org-id stuff to ulang, pkgbuild notes
Richard Westhaver <ellis@rwest.io>
parents:
587
diff
changeset
|
136 | (save-buffer)))) |
0552341ac196
refactor org-id stuff to ulang, pkgbuild notes
Richard Westhaver <ellis@rwest.io>
parents:
587
diff
changeset
|
137 | |
623 | 138 | (defun org-id-add-to-headlines-in-directory (&optional dir) |
139 | (interactive) |
|
140 | (let ((dir (or dir org-directory))) |
|
141 | (org-id-add-to-headlines-in-files |
|
142 | (directory-files-recursively dir "[.]org$")))) |
|
143 | ||
57 | 144 | (message "Initialized ULANG.") |
50
e62a6a0d5997
organ/lexer, ulang support, gui and web stuff
ellis <ellis@rwest.io>
parents:
diff
changeset
|
145 | |
631 | 146 | ;;; Commands |
147 | ||
148 | ;; (org-property-inherit-p "LOCATION") |
|
639 | 149 | |
150 | ;; currently does not support locations with spaces.. need to walk |
|
151 | ;; ancestors ourselves to do so. for now only URIs and pathnames are |
|
152 | ;; supported. |
|
153 | (defun org-get-location (point) |
|
154 | "Get the value of property LOCATION at POINT." |
|
155 | (interactive "d") |
|
156 | (org-with-point-at point |
|
157 | (format "%s" (or (apply 'join-paths (string-split (org-entry-get-with-inheritance "LOCATION") " ")) |
|
158 | (caadar (org-collect-keywords '("LOCATION") nil '("LOCATION"))))))) |
|
159 | ||
160 | (defun org-set-location (value) |
|
161 | "Set the value of property LOCATION. If point is before first heading |
|
162 | instead set or replace the location file keyword." |
|
163 | (interactive (list nil)) |
|
164 | (let ((val (or value (org-read-property-value "LOCATION" nil nil)))) |
|
165 | (if (org-before-first-heading-p) |
|
166 | (save-excursion |
|
167 | (beginning-of-buffer) |
|
168 | (let ((start (point))) |
|
169 | (when (re-search-forward (rx bol "#+LOCATION:" (+ space) (group (* (not space))) eol) nil t) |
|
170 | (setq start (match-beginning 0)) |
|
171 | (goto-char start) |
|
172 | (delete-line)) |
|
173 | (insert "#+LOCATION: " val "\n"))) |
|
174 | (org-set-property "LOCATION" value)))) |
|
175 | ||
631 | 176 | (defun org-follow-location () |
177 | "Open the location specified by the LOCATION property of the org heading |
|
178 | or file at point." |
|
179 | (interactive) |
|
639 | 180 | (let ((loc )) |
631 | 181 | (cond |
182 | ((string-match-p org-link-any-re loc) (org-link-open-from-string loc)) |
|
183 | ;; TODO 2024-08-29: handle other location types (physical, etc) |
|
184 | (t (find-file loc t))))) |
|
185 | ||
639 | 186 | (provide 'ulang) |
50
e62a6a0d5997
organ/lexer, ulang support, gui and web stuff
ellis <ellis@rwest.io>
parents:
diff
changeset
|
187 | ;;; ulang.el ends here |