我可以使用Emacs中的哪些命令将当前日期和时间插入文件的文本缓冲区?
(例如,记事本中的等价物只是按下F5,这是记事本唯一有用的功能!)
C-u M-! date
放入.emacs文件:
;; ==================== ;; insert date and time (defvar current-date-time-format "%a %b %d %H:%M:%S %Z %Y" "Format of date to insert with `insert-current-date-time' func See help of `format-time-string' for possible replacements") (defvar current-time-format "%a %H:%M:%S" "Format of date to insert with `insert-current-time' func. Note the weekly scope of the command's precision.") (defun insert-current-date-time () "insert the current date and time into current buffer. Uses `current-date-time-format' for the formatting the date/time." (interactive) (insert "==========\n") ; (insert (let () (comment-start))) (insert (format-time-string current-date-time-format (current-time))) (insert "\n") ) (defun insert-current-time () "insert the current time (1-week scope) into the current buffer." (interactive) (insert (format-time-string current-time-format (current-time))) (insert "\n") ) (global-set-key "\C-c\C-d" 'insert-current-date-time) (global-set-key "\C-c\C-t" 'insert-current-time)
参考
我用过这些简短的片段:
(defun now () "Insert string for the current time formatted like '2:34 PM'." (interactive) ; permit invocation in minibuffer (insert (format-time-string "%D %-I:%M %p"))) (defun today () "Insert string for today's date nicely formatted in American style, e.g. Sunday, September 17, 2000." (interactive) ; permit invocation in minibuffer (insert (format-time-string "%A, %B %e, %Y")))
他们最初来自journal.el
对于插入日期:
M-x org-time-stamp
对于插入日期时间:
C-u M-x org-time-stamp
您可以绑定此命令的全局键.
org-mode
该方法非常用户友好,您可以从日历中选择任何日期.
您可以安装yasnippet,它可以让您输入"time"和tab键,并且还可以执行更多操作.它只是current-time-string
在幕后调用,因此您可以使用控制格式format-time-string
.
这是我刚才写的一个包,它可以满足您的要求.
http://github.com/rmm5t/insert-time.el/tree/master/insert-time.el
(require 'insert-time) (define-key global-map [(control c)(d)] 'insert-date-time) (define-key global-map [(control c)(control v)(d)] 'insert-personal-time-stamp)