changelog shortlog graph tags branches changeset files file revisions raw help

Mercurial > core / annotate emacs/lib/ulang.el

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
Richard Westhaver <ellis@rwest.io>
parents: 586
diff changeset
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
a304c9713a51 init graph.el
Richard Westhaver <ellis@rwest.io>
parents: 619
diff changeset
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
be036d2eefea emacs updates
ellis <ellis@rwest.io>
parents: 52
diff changeset
27
 (require 'org)
59
ce1a5c531abf el cleanup
ellis <ellis@rwest.io>
parents: 57
diff changeset
28
 (require 'ox)
623
a304c9713a51 init graph.el
Richard Westhaver <ellis@rwest.io>
parents: 619
diff changeset
29
 
a304c9713a51 init graph.el
Richard Westhaver <ellis@rwest.io>
parents: 619
diff changeset
30
 (defgroup ulang nil
a304c9713a51 init graph.el
Richard Westhaver <ellis@rwest.io>
parents: 619
diff changeset
31
   "CC Universal Language.")
a304c9713a51 init graph.el
Richard Westhaver <ellis@rwest.io>
parents: 619
diff changeset
32
 
a304c9713a51 init graph.el
Richard Westhaver <ellis@rwest.io>
parents: 619
diff changeset
33
 (defvar ulang-link-history nil)
a304c9713a51 init graph.el
Richard Westhaver <ellis@rwest.io>
parents: 619
diff changeset
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
0b82a2893d26 inbox compaction
Richard Westhaver <ellis@rwest.io>
parents: 630
diff changeset
36
 ;; see org-special-properties
0b82a2893d26 inbox compaction
Richard Westhaver <ellis@rwest.io>
parents: 630
diff changeset
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
a304c9713a51 init graph.el
Richard Westhaver <ellis@rwest.io>
parents: 619
diff changeset
41
 (defun dblock-insert-links (regexp)
57
be036d2eefea emacs updates
ellis <ellis@rwest.io>
parents: 52
diff changeset
42
   "Create dblock to insert links matching REGEXP."
631
0b82a2893d26 inbox compaction
Richard Westhaver <ellis@rwest.io>
parents: 630
diff changeset
43
   (interactive (list (read-regexp "Insert links matching: " nil ulang-link-history)))
57
be036d2eefea emacs updates
ellis <ellis@rwest.io>
parents: 52
diff changeset
44
   (org-create-dblock (list :name "links"
be036d2eefea emacs updates
ellis <ellis@rwest.io>
parents: 52
diff changeset
45
                            :regexp regexp
be036d2eefea emacs updates
ellis <ellis@rwest.io>
parents: 52
diff changeset
46
                            :id-only nil))
be036d2eefea emacs updates
ellis <ellis@rwest.io>
parents: 52
diff changeset
47
   (org-update-dblock))
be036d2eefea emacs updates
ellis <ellis@rwest.io>
parents: 52
diff changeset
48
 
623
a304c9713a51 init graph.el
Richard Westhaver <ellis@rwest.io>
parents: 619
diff changeset
49
 (org-dynamic-block-define "links" 'dblock-insert-links)
57
be036d2eefea emacs updates
ellis <ellis@rwest.io>
parents: 52
diff changeset
50
 
638
6c0e4a44c082 dblocks
Richard Westhaver <ellis@rwest.io>
parents: 631
diff changeset
51
 ;; (org-export-translate-to-lang (list '("Table of Contents" "Index")) "ulang")
623
a304c9713a51 init graph.el
Richard Westhaver <ellis@rwest.io>
parents: 619
diff changeset
52
 ;; (setq org-export-global-macros nil)
57
be036d2eefea emacs updates
ellis <ellis@rwest.io>
parents: 52
diff changeset
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
Richard Westhaver <ellis@rwest.io>
parents: 586
diff changeset
57
 (setq org-todo-keywords
626
cc13027df6fa ulang and cli updates
Richard Westhaver <ellis@rwest.io>
parents: 623
diff changeset
58
       '((sequence "TBD(0!)" "TODO(t!)" "NEXT(n!)" "WIP(i!)" "|" "DONE(d!)")
cc13027df6fa ulang and cli updates
Richard Westhaver <ellis@rwest.io>
parents: 623
diff changeset
59
         (sequence "HOLD(H@/!)" "WIP(!)" "|")
cc13027df6fa ulang and cli updates
Richard Westhaver <ellis@rwest.io>
parents: 623
diff changeset
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
35a579313b80 init ini and vc work
Richard Westhaver <ellis@rwest.io>
parents: 618
diff changeset
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
cc13027df6fa ulang and cli updates
Richard Westhaver <ellis@rwest.io>
parents: 623
diff changeset
64
         (type "FIND(q!)" "READ(r@!)" "WATCH(A@!)" "HACK(h!)"
cc13027df6fa ulang and cli updates
Richard Westhaver <ellis@rwest.io>
parents: 623
diff changeset
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
46e9425cf3c2 howd that get there
Richard Westhaver <ellis@rwest.io>
parents: 588
diff changeset
67
         (type "PROJECT(p!)" "PRODUCT(P!)" "SPRINT(S!)" "RELEASE(R!)" "|")
626
cc13027df6fa ulang and cli updates
Richard Westhaver <ellis@rwest.io>
parents: 623
diff changeset
68
         (sequence "|" "DONE(d!)" "NOPE(x@!)")))
587
Richard Westhaver <ellis@rwest.io>
parents: 586
diff changeset
69
 
Richard Westhaver <ellis@rwest.io>
parents: 586
diff changeset
70
 (setq org-todo-keyword-faces
Richard Westhaver <ellis@rwest.io>
parents: 586
diff changeset
71
       '(("PROJECT" . (:foreground "lightseagreen" :weight bold))
596
46e9425cf3c2 howd that get there
Richard Westhaver <ellis@rwest.io>
parents: 588
diff changeset
72
         ("PRODUCT" . (:foreground "olivedrab" :weight bold))
46e9425cf3c2 howd that get there
Richard Westhaver <ellis@rwest.io>
parents: 588
diff changeset
73
         ("RELEASE" . (:foreground "maroon3" :weight bold))
46e9425cf3c2 howd that get there
Richard Westhaver <ellis@rwest.io>
parents: 588
diff changeset
74
         ("RESEARCH" . (:foreground "maroon2" :weight bold))
46e9425cf3c2 howd that get there
Richard Westhaver <ellis@rwest.io>
parents: 588
diff changeset
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
46e9425cf3c2 howd that get there
Richard Westhaver <ellis@rwest.io>
parents: 588
diff changeset
77
         ("CODE" . (:foreground "bisque" :weight bold :background "midnightblue"))
46e9425cf3c2 howd that get there
Richard Westhaver <ellis@rwest.io>
parents: 588
diff changeset
78
         ("HOLD" . (:foreground "red1" :weight bold :background "yellow1"))
46e9425cf3c2 howd that get there
Richard Westhaver <ellis@rwest.io>
parents: 588
diff changeset
79
         ("WAIT" . (:foreground "red4" :weight bold :background "yellow1"))
46e9425cf3c2 howd that get there
Richard Westhaver <ellis@rwest.io>
parents: 588
diff changeset
80
         ("WIP" . (:foreground "darkorchid2" :weight bold))
46e9425cf3c2 howd that get there
Richard Westhaver <ellis@rwest.io>
parents: 588
diff changeset
81
         ("NOPE" . (:foreground "hotpink" :weight bold :background "darkgreen"))))
587
Richard Westhaver <ellis@rwest.io>
parents: 586
diff changeset
82
 
604
74a55d5decce emacs org libraries and upgrades
Richard Westhaver <ellis@rwest.io>
parents: 596
diff changeset
83
 ;; link abbrevs
57
be036d2eefea emacs updates
ellis <ellis@rwest.io>
parents: 52
diff changeset
84
 (setq org-link-abbrev-alist
be036d2eefea emacs updates
ellis <ellis@rwest.io>
parents: 52
diff changeset
85
       '(("vc" . "https://vc.compiler.company/%s")
be036d2eefea emacs updates
ellis <ellis@rwest.io>
parents: 52
diff changeset
86
         ("comp" . "https://compiler.company/%s")
be036d2eefea emacs updates
ellis <ellis@rwest.io>
parents: 52
diff changeset
87
 	("cdn" . "https://cdn.compiler.company/%s")
be036d2eefea emacs updates
ellis <ellis@rwest.io>
parents: 52
diff changeset
88
         ("packy" . "https://packy.compiler.company/%s")
596
46e9425cf3c2 howd that get there
Richard Westhaver <ellis@rwest.io>
parents: 588
diff changeset
89
         ("yt" . "https://youtube.com/watch?v=%s")
46e9425cf3c2 howd that get there
Richard Westhaver <ellis@rwest.io>
parents: 588
diff changeset
90
         ("wikipedia" . "https://en.wikipedia.org/wiki/%s")
46e9425cf3c2 howd that get there
Richard Westhaver <ellis@rwest.io>
parents: 588
diff changeset
91
         ("reddit" . "https://reddit.com/%s")
46e9425cf3c2 howd that get there
Richard Westhaver <ellis@rwest.io>
parents: 588
diff changeset
92
         ("hn" . "https://news.ycombinator.com/%s")
46e9425cf3c2 howd that get there
Richard Westhaver <ellis@rwest.io>
parents: 588
diff changeset
93
         ("so" . "https://stackoverflow.com/%s")))
57
be036d2eefea emacs updates
ellis <ellis@rwest.io>
parents: 52
diff changeset
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
a304c9713a51 init graph.el
Richard Westhaver <ellis@rwest.io>
parents: 619
diff changeset
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
a304c9713a51 init graph.el
Richard Westhaver <ellis@rwest.io>
parents: 619
diff changeset
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
a304c9713a51 init graph.el
Richard Westhaver <ellis@rwest.io>
parents: 619
diff changeset
138
 (defun org-id-add-to-headlines-in-directory (&optional dir)
a304c9713a51 init graph.el
Richard Westhaver <ellis@rwest.io>
parents: 619
diff changeset
139
   (interactive)
a304c9713a51 init graph.el
Richard Westhaver <ellis@rwest.io>
parents: 619
diff changeset
140
   (let ((dir (or dir org-directory)))
a304c9713a51 init graph.el
Richard Westhaver <ellis@rwest.io>
parents: 619
diff changeset
141
     (org-id-add-to-headlines-in-files
a304c9713a51 init graph.el
Richard Westhaver <ellis@rwest.io>
parents: 619
diff changeset
142
      (directory-files-recursively dir "[.]org$"))))
a304c9713a51 init graph.el
Richard Westhaver <ellis@rwest.io>
parents: 619
diff changeset
143
 
57
be036d2eefea emacs updates
ellis <ellis@rwest.io>
parents: 52
diff changeset
144
 (message "Initialized ULANG.")
50
e62a6a0d5997 organ/lexer, ulang support, gui and web stuff
ellis <ellis@rwest.io>
parents:
diff changeset
145
 
631
0b82a2893d26 inbox compaction
Richard Westhaver <ellis@rwest.io>
parents: 630
diff changeset
146
 ;;; Commands
0b82a2893d26 inbox compaction
Richard Westhaver <ellis@rwest.io>
parents: 630
diff changeset
147
 
0b82a2893d26 inbox compaction
Richard Westhaver <ellis@rwest.io>
parents: 630
diff changeset
148
 ;; (org-property-inherit-p "LOCATION")
639
32375ed43c74 org-set-location
Richard Westhaver <ellis@rwest.io>
parents: 638
diff changeset
149
 
32375ed43c74 org-set-location
Richard Westhaver <ellis@rwest.io>
parents: 638
diff changeset
150
 ;; currently does not support locations with spaces.. need to walk
32375ed43c74 org-set-location
Richard Westhaver <ellis@rwest.io>
parents: 638
diff changeset
151
 ;; ancestors ourselves to do so. for now only URIs and pathnames are
32375ed43c74 org-set-location
Richard Westhaver <ellis@rwest.io>
parents: 638
diff changeset
152
 ;; supported.
32375ed43c74 org-set-location
Richard Westhaver <ellis@rwest.io>
parents: 638
diff changeset
153
 (defun org-get-location (point)
32375ed43c74 org-set-location
Richard Westhaver <ellis@rwest.io>
parents: 638
diff changeset
154
   "Get the value of property LOCATION at POINT."
32375ed43c74 org-set-location
Richard Westhaver <ellis@rwest.io>
parents: 638
diff changeset
155
   (interactive "d")
32375ed43c74 org-set-location
Richard Westhaver <ellis@rwest.io>
parents: 638
diff changeset
156
   (org-with-point-at point
32375ed43c74 org-set-location
Richard Westhaver <ellis@rwest.io>
parents: 638
diff changeset
157
     (format "%s" (or (apply 'join-paths (string-split (org-entry-get-with-inheritance "LOCATION") " "))
32375ed43c74 org-set-location
Richard Westhaver <ellis@rwest.io>
parents: 638
diff changeset
158
                      (caadar (org-collect-keywords '("LOCATION") nil '("LOCATION")))))))
32375ed43c74 org-set-location
Richard Westhaver <ellis@rwest.io>
parents: 638
diff changeset
159
 
32375ed43c74 org-set-location
Richard Westhaver <ellis@rwest.io>
parents: 638
diff changeset
160
 (defun org-set-location (value)
32375ed43c74 org-set-location
Richard Westhaver <ellis@rwest.io>
parents: 638
diff changeset
161
   "Set the value of property LOCATION. If point is before first heading
32375ed43c74 org-set-location
Richard Westhaver <ellis@rwest.io>
parents: 638
diff changeset
162
 instead set or replace the location file keyword."
32375ed43c74 org-set-location
Richard Westhaver <ellis@rwest.io>
parents: 638
diff changeset
163
   (interactive (list nil))
32375ed43c74 org-set-location
Richard Westhaver <ellis@rwest.io>
parents: 638
diff changeset
164
   (let ((val (or value (org-read-property-value "LOCATION" nil nil))))
32375ed43c74 org-set-location
Richard Westhaver <ellis@rwest.io>
parents: 638
diff changeset
165
     (if (org-before-first-heading-p)
32375ed43c74 org-set-location
Richard Westhaver <ellis@rwest.io>
parents: 638
diff changeset
166
         (save-excursion
32375ed43c74 org-set-location
Richard Westhaver <ellis@rwest.io>
parents: 638
diff changeset
167
           (beginning-of-buffer)
32375ed43c74 org-set-location
Richard Westhaver <ellis@rwest.io>
parents: 638
diff changeset
168
           (let ((start (point)))
32375ed43c74 org-set-location
Richard Westhaver <ellis@rwest.io>
parents: 638
diff changeset
169
             (when (re-search-forward (rx bol "#+LOCATION:" (+ space) (group (* (not space))) eol) nil t)
32375ed43c74 org-set-location
Richard Westhaver <ellis@rwest.io>
parents: 638
diff changeset
170
               (setq start (match-beginning 0))
32375ed43c74 org-set-location
Richard Westhaver <ellis@rwest.io>
parents: 638
diff changeset
171
               (goto-char start)
32375ed43c74 org-set-location
Richard Westhaver <ellis@rwest.io>
parents: 638
diff changeset
172
               (delete-line))
32375ed43c74 org-set-location
Richard Westhaver <ellis@rwest.io>
parents: 638
diff changeset
173
             (insert "#+LOCATION: " val "\n")))
32375ed43c74 org-set-location
Richard Westhaver <ellis@rwest.io>
parents: 638
diff changeset
174
       (org-set-property "LOCATION" value))))
32375ed43c74 org-set-location
Richard Westhaver <ellis@rwest.io>
parents: 638
diff changeset
175
 
631
0b82a2893d26 inbox compaction
Richard Westhaver <ellis@rwest.io>
parents: 630
diff changeset
176
 (defun org-follow-location ()
0b82a2893d26 inbox compaction
Richard Westhaver <ellis@rwest.io>
parents: 630
diff changeset
177
   "Open the location specified by the LOCATION property of the org heading
0b82a2893d26 inbox compaction
Richard Westhaver <ellis@rwest.io>
parents: 630
diff changeset
178
 or file at point."
0b82a2893d26 inbox compaction
Richard Westhaver <ellis@rwest.io>
parents: 630
diff changeset
179
   (interactive)
639
32375ed43c74 org-set-location
Richard Westhaver <ellis@rwest.io>
parents: 638
diff changeset
180
   (let ((loc ))
631
0b82a2893d26 inbox compaction
Richard Westhaver <ellis@rwest.io>
parents: 630
diff changeset
181
     (cond
0b82a2893d26 inbox compaction
Richard Westhaver <ellis@rwest.io>
parents: 630
diff changeset
182
      ((string-match-p org-link-any-re loc) (org-link-open-from-string loc))
0b82a2893d26 inbox compaction
Richard Westhaver <ellis@rwest.io>
parents: 630
diff changeset
183
      ;; TODO 2024-08-29: handle other location types (physical, etc)
0b82a2893d26 inbox compaction
Richard Westhaver <ellis@rwest.io>
parents: 630
diff changeset
184
      (t (find-file loc t)))))
0b82a2893d26 inbox compaction
Richard Westhaver <ellis@rwest.io>
parents: 630
diff changeset
185
 
639
32375ed43c74 org-set-location
Richard Westhaver <ellis@rwest.io>
parents: 638
diff changeset
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