Prechádzať zdrojové kódy

Match, update <DATE>

George Jones 3 rokov pred
rodič
commit
d51d756002
1 zmenil súbory, kde vykonal 15 pridanie a 27 odobranie
  1. 15 27
      elisp-public/gmj-update-date.org

+ 15 - 27
elisp-public/gmj-update-date.org

@@ -21,6 +21,9 @@
 #
 #  update date string in first N lines
 
+* Reference
+  See [[file:~/home/public/elisp-public/gmj-set-accounts-property-dates.el::defun gmj-set-accounts-property-defaults (][gmj-set-accounts-proptery-defaults]] for an earlier, related hack.
+
 * DONE Update date in whole buffer
 #+begin_src elisp
 (defun gmj/update-date-buffer ()
@@ -36,8 +39,6 @@
 #+end_src
 
 * DONE Update date in region
-
-  - State "DONE"       from              [2020-12-19 Sat 06:57]
 #+begin_src elisp
 (defun gmj/update-date-region ()
   "Update date stamps in region "
@@ -64,7 +65,6 @@
 
 ;; make sure we have an active region; if not set to current line
 * IN-PROGRESS Update date in first N lines
-  - State "IN-PROGRESS" from "TODO"       [2020-12-19 Sat 07:35]
 #+begin_src elisp
 
 (defun gmj/update-date-first-n-lines ()
@@ -80,39 +80,27 @@
       )))
 #+end_src
 
-* TODO Update date, N-lines around point
-
+** TODO Update date, N-lines around point
 
-* IN-PROGRESS Update date in specified region
-
-  - State "IN-PROGRESS" from              [2020-12-19 Sat 06:57]
+* DONE Update date in specified region
 #+begin_src elisp
+
 (defun gmj/update-date (start end)
   "Update date string in region"
   ;;(interactive)
   (save-restriction
       (narrow-to-region start end)
-      (goto-char start)
+      (setq case-fold-search t)
 
-      ;; Add date to blank line
-      (while (search-forward "date: " nil t)
-        (progn
-          ;;
-          (replace-match "dAtE: FOO" nil t)
-          ;; delete to end of line
-          (let ((eol-pos (line-end-position)))
-            (delete-region (point) eol-pos)
-            )
-
-          )
-        )
-      ;(goto-char (point-min))
-
-      ;; Replace existing date
+      ;; 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))
 
-      ;; (while (search-forward " beta" nil t)
-      ;;   (replace-match " β" nil t))
-      ;(goto-char (point-min))
+      ;; 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))
       )
   )