best way to change defconst value for a particular session? (emacs)
I want to change the value of
(defconst org-time-stamp-formats '("<%Y-%m-%d %a>" . "<%Y-%m-%d %a %H:%M>")
"Formats for `format-time-string' which are used for time stamps.
It is not recommended to change this constant.")
to
'("<%Y-%m-%d %a>" . "<%H:%M>")
开发者_StackOverflow社区
Not always, but for particular org-mode sessions, even while knowing that defconst values are not really meant to be changed. I wonder if there's a good way to do this?
Thanks...
Edit: I guess my main goal is to be able to be able to insert a time-stamp which contains hours and minutes only, which could similarly be accomplished by defadvice on org-time-stamp, or some other means?
You can use advice to solve this problem.
(defadvice org-time-stamp (around org-time-stamp-new-format activate)
"change the org time-stamp when desired"
(let ((org-time-stamp-formats '("<%Y-%m-%d %a>" . "<%H:%M>")))
ad-do-it))
;; control whether it is active via
;; M-x ad-activate org-time-stamp
;; M-x ad-deactivate org-time-stamp
Or, you can set a variable that controls the behavior:
(defvar use-new-org-timestamp t)
(defadvice org-time-stamp (around org-time-stamp-new-format activate)
"change the org time-stamp when desired"
(let ((org-time-stamp-formats (if use-new-org-timestamp
'("<%Y-%m-%d %a>" . "<%H:%M>")
org-time-stamp-formats)))
ad-do-it))
精彩评论