-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
cmrfrd
committed
Feb 22, 2022
1 parent
c02dde2
commit 03af9e1
Showing
1 changed file
with
40 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,50 @@ | ||
;;-------------------------- | ||
;; Handling file properties for ‘CREATED’ & ‘LAST_MODIFIED’ | ||
;;-------------------------- | ||
;;-------------------------- | ||
;; Handling file properties for ‘CREATED’ & ‘LAST_MODIFIED’ | ||
;;-------------------------- | ||
|
||
(defun zp/org-find-time-file-property (property &optional anywhere) | ||
"Return the position of the time file PROPERTY if it exists. | ||
(defun zp/org-find-time-file-property (property &optional anywhere) | ||
"Return the position of the time file PROPERTY if it exists. | ||
When ANYWHERE is non-nil, search beyond the preamble." | ||
(save-excursion | ||
(goto-char (point-min)) | ||
(let ((first-heading | ||
(save-excursion | ||
(re-search-forward org-outline-regexp-bol nil t)))) | ||
(when (re-search-forward (format "^#\\+%s:" property) | ||
(if anywhere nil first-heading) | ||
t) | ||
(point))))) | ||
(save-excursion | ||
(goto-char (point-min)) | ||
(let ((first-heading | ||
(save-excursion | ||
(re-search-forward org-outline-regexp-bol nil t)))) | ||
(when (re-search-forward (format "^#\\+%s:" property) | ||
(if anywhere nil first-heading) | ||
t) | ||
(point))))) | ||
|
||
(defun zp/org-has-time-file-property-p (property &optional anywhere) | ||
"Return the position of time file PROPERTY if it is defined. | ||
(defun zp/org-has-time-file-property-p (property &optional anywhere) | ||
"Return the position of time file PROPERTY if it is defined. | ||
As a special case, return -1 if the time file PROPERTY exists but | ||
is not defined." | ||
(when-let ((pos (zp/org-find-time-file-property property anywhere))) | ||
(save-excursion | ||
(goto-char pos) | ||
(if (and (looking-at-p " ") | ||
(progn (forward-char) | ||
(org-at-timestamp-p 'lax))) | ||
pos | ||
-1)))) | ||
(when-let ((pos (zp/org-find-time-file-property property anywhere))) | ||
(save-excursion | ||
(goto-char pos) | ||
(if (and (looking-at-p " ") | ||
(progn (forward-char) | ||
(org-at-timestamp-p 'lax))) | ||
pos | ||
-1)))) | ||
|
||
(defun zp/org-set-time-file-property (property &optional anywhere pos) | ||
"Set the time file PROPERTY in the preamble. | ||
(defun zp/org-set-time-file-property (property &optional anywhere pos) | ||
"Set the time file PROPERTY in the preamble. | ||
When ANYWHERE is non-nil, search beyond the preamble. | ||
If the position of the file PROPERTY has already been computed, | ||
it can be passed in POS." | ||
(when-let ((pos (or pos | ||
(zp/org-find-time-file-property property)))) | ||
(save-excursion | ||
(goto-char pos) | ||
(if (looking-at-p " ") | ||
(forward-char) | ||
(insert " ")) | ||
(delete-region (point) (line-end-position)) | ||
(let* ((now (format-time-string "[%Y-%m-%d %a %H:%M]"))) | ||
(insert now))))) | ||
(when-let ((pos (or pos | ||
(zp/org-find-time-file-property property)))) | ||
(save-excursion | ||
(goto-char pos) | ||
(if (looking-at-p " ") | ||
(forward-char) | ||
(insert " ")) | ||
(delete-region (point) (line-end-position)) | ||
(let* ((now (format-time-string "[%Y-%m-%d %a %H:%M]"))) | ||
(insert now))))) | ||
|
||
(defun zp/org-set-last-modified () | ||
"Update the LAST_MODIFIED file property in the preamble." | ||
(when (derived-mode-p 'org-mode) | ||
(zp/org-set-time-file-property "LAST_MODIFIED"))) | ||
(defun zp/org-set-last-modified () | ||
"Update the LAST_MODIFIED file property in the preamble." | ||
(when (derived-mode-p 'org-mode) | ||
(zp/org-set-time-file-property "LAST_MODIFIED"))) |