2010-05-20 29 views
0

我想的更改特定會話的defconst值的最佳方法?

(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.") 

值更改爲

'("<%Y-%m-%d %a>" . "<%H:%M>") 

並非總是如此(emacs的),但對於具體的組織模式會話,即使明知defconst值是不是真的意味着是改變。我想知道是否有一個好的方法來做到這一點?

謝謝...

編輯:我想我的主要目標是能夠能夠插入一個時間戳只包含小時和分鐘,這可能同樣被defadvice的組織來完成時間戳,還是其他一些手段?

回答

2

您可以使用建議來解決此問題。

(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 

或者,您可以設置控制行爲的變量:

(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)) 
+1

因此,採取動態範圍的優勢......我明白了。 – hatmatrix 2010-10-11 00:36:14

+0

對於OSX上的Emacs Trunk版本24.3.50(9.0),我一直無法使這些解決方案中的任何一個工作 - 沒有任何反應。在激活或關閉組織時間戳時,當前緩衝區中的時間戳組織文件應該自動更新時間戳格式嗎? – lawlist 2013-06-29 20:25:29

相關問題