Skip to content

Commit

Permalink
Restore org timestamp hook
Browse files Browse the repository at this point in the history
  • Loading branch information
sangwoo-joh committed Jan 12, 2023
1 parent 858b786 commit 6c242e0
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions config.el
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,33 @@
(interactive)
(remove-hook 'before-save-hook #'kernel/md/save-with-timestamp 'local))

(defun kernel/org/save-with-timestamp ()
"Save org file with timestamp."
(interactive)
(save-excursion
(goto-char (point-min))
(let* ((section-last-update-key-re "^#\\+last_update[ ]*:[ ]*")
(section-last-update-key "#+last_update: "))
(if (re-search-forward section-last-update-key-re nil t)
(kill-line)
;; else
(message "No last_update key found.")
;; insert last_update into the first line
(goto-char (point-min))
(electric-newline-and-maybe-indent)
(forward-line -1)
(insert section-last-update-key))
(kernel/timestamp))))

(defun kernel/org/add-save-with-timestamp-hook ()
"Add org timestamp hook."
(interactive)
(add-hook 'before-save-hook #'kernel/org/save-with-timestamp nil 'local))

(defun kernel/org/delete-save-with-timestamp-hook ()
"Delete org timestamp hook."
(interactive)
(remove-hook 'before-save-hook #'kernel/org/save-with-timestamp 'local))

;;
;; kernel key maps
Expand Down Expand Up @@ -318,6 +345,7 @@
;;
(add-hook! 'prog-mode-hook #'copilot-mode)
(add-hook! 'markdown-mode-hook #'kernel/md/add-save-with-timestamp-hook)
(add-hook! 'org-mode-hook #'kernel/org/add-save-with-timestamp-hook)

(after! python
(setq pipenv-projectile-after-switch-function
Expand Down

0 comments on commit 6c242e0

Please sign in to comment.