# HG changeset patch # User Richard Westhaver # Date 1725812673 14400 # Node ID 32375ed43c7422dd9eb4a594f2e1dc1ab85d167e # Parent 6c0e4a44c082a7e31f58dca6cce30002fd8838fe org-set-location diff -r 6c0e4a44c082 -r 32375ed43c74 emacs/lib/ulang.el --- a/emacs/lib/ulang.el Sat Sep 07 22:34:12 2024 -0400 +++ b/emacs/lib/ulang.el Sun Sep 08 12:24:33 2024 -0400 @@ -143,19 +143,45 @@ (message "Initialized ULANG.") -(provide 'ulang) ;;; Commands ;; (org-property-inherit-p "LOCATION") + +;; currently does not support locations with spaces.. need to walk +;; ancestors ourselves to do so. for now only URIs and pathnames are +;; supported. +(defun org-get-location (point) + "Get the value of property LOCATION at POINT." + (interactive "d") + (org-with-point-at point + (format "%s" (or (apply 'join-paths (string-split (org-entry-get-with-inheritance "LOCATION") " ")) + (caadar (org-collect-keywords '("LOCATION") nil '("LOCATION"))))))) + +(defun org-set-location (value) + "Set the value of property LOCATION. If point is before first heading +instead set or replace the location file keyword." + (interactive (list nil)) + (let ((val (or value (org-read-property-value "LOCATION" nil nil)))) + (if (org-before-first-heading-p) + (save-excursion + (beginning-of-buffer) + (let ((start (point))) + (when (re-search-forward (rx bol "#+LOCATION:" (+ space) (group (* (not space))) eol) nil t) + (setq start (match-beginning 0)) + (goto-char start) + (delete-line)) + (insert "#+LOCATION: " val "\n"))) + (org-set-property "LOCATION" value)))) + (defun org-follow-location () "Open the location specified by the LOCATION property of the org heading or file at point." (interactive) - (let ((loc (or (org-entry-get-with-inheritance "LOCATION") - (caadar (org-collect-keywords '("LOCATION") nil '("LOCATION")))))) + (let ((loc )) (cond ((string-match-p org-link-any-re loc) (org-link-open-from-string loc)) ;; TODO 2024-08-29: handle other location types (physical, etc) (t (find-file loc t))))) +(provide 'ulang) ;;; ulang.el ends here