对于Emacs,如何将视图损失收集到外部文件中? [英] For Emacs, how to store what view-lossage collects into an external file?

查看:142
本文介绍了对于Emacs,如何将视图损失收集到外部文件中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于Emacs,如何将 view-lossage 收集到外部文件中?理想情况下,我想将这些按键数据逐个地自动存储到外部日志文件中,这意味着默认情况下Emacs启动时就完成了。

For Emacs, how do I store what view-lossage collects into an external file? Ideally I'd like to store these keystroke data into an external log file incrementally and automatically, meaning it is done so by default when Emacs is started.

推荐答案

至少在Emacs 24中(我现在不能检查以前的版本), view-lossage 状态:

In Emacs 24 at least (I can't check a prior version right now), the docstring for view-lossage states:


显示最后300个输入按键。

Display last 300 input keystrokes.

要将所有输入记录在文件中,请使用`open-dribble-file'。

To record all your input on a file, use `open-dribble-file'.

kbd> Ch f open-dribble-file RET 告诉我:

And C-hf open-dribble-file RET tells me:


open-dribble-file是一个C源
代码中的交互式内置函数。

open-dribble-file is an interactive built-in function in `C source code'.

(open-dribble-file FILE)

(open-dribble-file FILE)

开始将所有键盘字符写入名为FILE的运球文件。
如果FILE为零,请关闭任何打开的运球档案。
当Emacs退出时,该文件将被关闭。

Start writing all keyboard characters to a dribble file called FILE. If FILE is nil, close any open dribble file. The file will be closed when Emacs exits.

所以只需将以下内容添加到.emacs文件中: / p>

So simply add something like the following to your .emacs file:

(open-dribble-file (expand-file-name "~/.emacs.d/lossage.txt"))

实际上,如果这个文件已经存在,那么你将需要来处理这个问题。

Experimentally this clobbers the file if it already exists, so you'll need to deal with that.

这是一种方法。它通过使用 make-temp-name 来生成运行文件的半随机文件名,从而占用多个Emacs会话,然后将其内容附加到主损失日志文件当Emacs存在。 (如果Emacs崩溃,它将留下临时文件供您手动处理。)

Here's one approach. It accounts for multiple Emacs sessions by using make-temp-name to generate a semi-random filename for the dribble file, and then appends the contents of that to a primary lossage log file when Emacs exists. (If Emacs crashes, it would leave behind the temp file for you to deal with manually.)

(defmacro my-persistent-dribble-file (file)
  "Append the dribble-file for this session to persistent lossage log FILE."
  `(let* ((persistent-file (expand-file-name ,file))
          (temporary-file (make-temp-name (concat persistent-file "-")))
          (persistent-arg (shell-quote-argument persistent-file))
          (temporary-arg (shell-quote-argument temporary-file))
          (append-dribble-command (format
                                   "cat %s >>%s && rm %s"
                                   temporary-arg persistent-arg temporary-arg)))
     (open-dribble-file temporary-file)
     (eval `(add-hook 'kill-emacs-hook
                      (lambda () (shell-command ,append-dribble-command))))))

(my-persistent-dribble-file "~/.emacs.d/lossage")

这篇关于对于Emacs,如何将视图损失收集到外部文件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆