如何在Emacs中启动时执行一个函数

时间:2017-04-15 15:35:33

标签: emacs startup autoexec

当我右键单击文件管理器中的文件以使用Emacs打开文档时,我想开始执行以下功能(来自Replace one space by two after sentences in Emacs)。

(defun space12 ()
  (interactive)
  (save-excursion
    (goto-char (point-min))
    (while (re-search-forward "\\. \\([^ ]\\)" nil t)
      (replace-match ".  \\1" t))))

这会将". "转换为". ",而不会增加现有两个空格出现的空格。

如何做到这一点。我想添加(space12)到init.el但它似乎在加载文档之前加载。

示例输入:

This is for test. This is second line with only one space at start.  This is third line which already has 2 spaces before it. End of document.

1 个答案:

答案 0 :(得分:1)

尝试将此添加到init.el:

(add-hook 'find-file-hook 'space12)

但是,这会在您打开的每个文件上运行您的功能。这就是你想要的吗?