See gmj-set-accounts-proptery-defaults for an earlier, related hack.
(defun gmj/update-date-buffer () "Update date stamps in whole buffer " (interactive) (save-excursion (let ((p1 (point-min)) (p2 (point-max))) (gmj/update-date p1 p2) ) ) )
(defun gmj/update-date-region () "Update date stamps in region " (interactive) (save-excursion (let (pos1 pos2) (progn (if (use-region-p) (progn (setq p1 (region-beginning) p2 (region-end)) ) (progn (setq p1 (line-beginning-position) p2 (line-end-position))) ) (gmj/update-date p1 p2) ) ) ) )
(defun gmj/update-date-first-n-lines (linesArg) "Update date stamps first N lines, default 8" (interactive "p") (save-excursion (let (p1 p2 lines) (if (= linesArg 1) (setq lines 8) (setq lines linesArg)) (setq p1 (point-min)) (goto-char (point-min)) (forward-line lines) (setq p2 (point)) (gmj/update-date p1 p2) )))
(defun gmj/update-date-current-block () "Update date string in current-block" (interactive) (save-excursion (xah-select-block) (gmj/update-date-region) ) )
(defun gmj/update-date (start end) "Update date string in region" ;;(interactive) (save-restriction (narrow-to-region start end) (setq case-fold-search t) ;; Find "DATE:[ ]$", replace with "DATE: <todays-date-and-time>" (goto-char start) (while (search-forward-regexp "date:[[:space:]]*$" nil t) (replace-match (concat "date: " (format-time-string "<%Y-%m-%d %a %H:%M:%S>")) nil t)) ;; Find "DATE:[ ]<.*>$", replace with "DATE: <todays-date-and-time>" (goto-char start) (while (search-forward-regexp "date:[[:space:]]*<.*>$" nil t) (replace-match (concat "date: " (format-time-string "<%Y-%m-%d %a %H:%M:%S>")) nil t)) ) )
(remove-hook 'before-save-hook 'gmj-update-date-save-hook) (defun gmj-update-date-save-hook () "On save, update 'date: lines at start of file and in current block" (interactive) (progn (gmj/update-date-current-block) (gmj/update-date-first-n-lines 10) ) ) (add-hook 'before-save-hook 'gmj-update-date-save-hook)
;; (when (string= (file-name-nondirectory (buffer-file-name)) "accounts.org.gpg") ;; (gmj-set-accounts-property-defaults)))
;(add-hook 'find-file-hook 'accounts.org_file_hook)