Selaa lähdekoodia

update-date functions, initial versions.

George Jones 3 vuotta sitten
vanhempi
commit
46a267b563
1 muutettua tiedostoa jossa 101 lisäystä ja 0 poistoa
  1. 101 0
      elisp-public/gmj-update-date.org

+ 101 - 0
elisp-public/gmj-update-date.org

@@ -0,0 +1,101 @@
+ #+PROPERTY: header-args :results silent
+
+# These function update date strings in a buffer.
+#
+# Dates are asumed to be at the end of a line and have the format:
+#
+#   .*date:[ ]*
+#
+# or
+#
+#   .*date: <.*>
+#
+#
+
+
+# hook to update date strings on write
+#
+#  - First N lines
+#
+#  - N lines around point
+#
+#  update date string in first N lines
+
+* DONE Update date in whole buffer
+  - State "DONE"       from              [2020-12-19 Sat 06:57]
+#+begin_src elisp
+(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)
+      )
+    )
+  )
+#+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 "
+  (interactive)
+  (save-excursion
+    (let (pos1 pos2)
+      (progn
+        (if (use-region-p)
+            (progn
+                                        ;(message "use-region-p is t")
+              (setq p1 (region-beginning) p2 (region-end))
+              )
+          (progn
+                                        ;(message "use-region-p is nil")
+            (setq p1 (line-beginning-position)  p2 (line-end-position)))
+          )
+
+        (gmj/update-date p1 p2)
+        )
+      )
+    )
+  )
+#+end_src
+
+;; update date string for N lines around point
+
+;; make sure we have an active region; if not set to current line
+* TODO Update date in first N lines
+* IN-PROGRESS Update date in specified region
+
+  - State "IN-PROGRESS" from              [2020-12-19 Sat 06:57]
+#+begin_src elisp
+(defun gmj/update-date (start end)
+  "Update date string in region"
+  (save-restriction
+      (narrow-to-region start end)
+      (goto-char (point-min))
+
+      ;; 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
+
+      ;; (while (search-forward " beta" nil t)
+      ;;   (replace-match " β" nil t))
+      (goto-char (point-min))
+      )
+  )
+#+end_src