0

我正在寻找一种最简洁的方法来使用与语言无关的键绑定,该键绑定将插入我的姓名首字母+格式化的时间戳,例如:

--<my initials> (28 Oct 2013 11:38:20 AM)

放入 Emacs 缓冲区,以便我可以初始化我的评论。我知道我可以创建一个函数并创建一个键绑定来调用它,但我觉得 Emacs 可能有一种事实上的方式来做这样的事情,大概是通过使用宏。

4

2 回答 2

1

F3(开始录制宏)

--AA C-u M-! date C-e(插入文本,插入date命令的输出)

F4(停止录制宏)

C-x C-k n my-initial-timestamp(命名宏)

C-x C-k b ...(将宏绑定到适当的组合键)

最后,打开~/.emacs并键入C-u M-x insert-kbd-macro RET my-initial-timestamp,这将插入 Lisp 代码以重新创建宏并在启动时将其绑定到相同的键。

于 2013-10-28T16:57:11.907 回答
0

Emacs does not have such a function, AFAIK. There is function time-stamp, which updates time-stamp templates in a buffer, but that is not what you want here.

This command gives you what you requested. Other time/date formats are available - see format-time-string. You can also use functions such as user-full-name and user-login-name, if you want your name instead of your initials. Here, I've just hard-coded your initials, NF. This should work for any buffer where a comment syntax is defined (comment-start).

(defun my-timestamp-comment ()
  (interactive)
  (insert (format "%s NF (%s)" comment-start
                  (format-time-string "%b %e %Y %r" (current-time)))))
于 2014-07-19T21:32:09.487 回答