在 Emacs 中自动打开丰富模式并使段落之间的换行变得困难

Automatically turn on enriched mode and make newlines between paragraphs hard in Emacs

我想在 Emacs 中默认启用丰富模式,这样我的 *scratch* 缓冲区将始终以该模式打开。我的 *scratch* 跨会话保持不变 (http://dorophone.blogspot.com/2011/11/how-to-make-emacs-scratch-buffer.html)。

我将 (enriched-mode) 添加到我的 .emacs 文件中,但随后每次启动时我都需要回答以下问题: Make newlines between paragraphs hard? (y or n)。我尝试在 (enriched-mode) 之前或之后添加 (use-hard-newlines),将 'yes1 和其他命令添加到两个命令中,但它不起作用。 C-h f enriched-mode 显示没有答案。

几点可能有帮助:

  1. enriched-modeuse-hard-newlines都不是全局次模式;它们都是当前缓冲区的本地。因此,以您正在执行的方式在您的 init 文件中打开它们只是为读取您的 init 文件时当前的任何缓冲区打开它们。

    您需要让它们以您想要的任何模式(也许是所有模式)自动打开。缓冲区 *scratch*lisp-interaction-mode 中。但是,通常,丰富的文本用于 text-mode 及其派生词(通常不用于使用字体锁定突出显示的模式)。

  2. 您需要使用(use-hard-newlines 1 'always)always 阻止提示并始终替换换行符。

我今天做到了。首先,自动保存的暂存文件的加载是由 shell 的 cat 函数完成的,将被 insert-file 替换。然后必须将 (enriched-mode) 添加到加载脚本中。一旦草稿被编辑为富文本(M-x enriched-mode 并回答硬线提示),它将在没有提示的情况下以丰富模式打开。

这是我的函数:

(defun load-persistent-scratch ()
  "Load the contents of PERSISTENT-SCRATCH-FILENAME into the
  scratch buffer, clearing its contents first."
  (if (file-exists-p persistent-scratch-filename)
      (with-current-buffer (get-buffer "*scratch*")
        (delete-region (point-min) (point-max))
        (insert-file persistent-scratch-filename)))
  (enriched-mode))