【问题标题】:How to execute a function at start in Emacs如何在 Emacs 中启动时执行函数
【发布时间】:2017-04-15 15:35:32
【问题描述】:

当我在文件管理器中右键单击文件以使用 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.

【问题讨论】:

  • 这是针对特定类型的文件吗?我可能会在适当的主要模式中添加一个钩子。

标签: emacs startup autoexec


【解决方案1】:

尝试将其添加到您的 init.el:

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

但是,这将在您打开的每个文件上运行您的函数。这就是你想要的吗?

【讨论】:

  • 我们可以和--eval一起使用吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-04-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多