emacs - Emacs 中普通缓冲区和空间前缀缓冲区的区别?

标签 emacs elisp

通过空格前缀缓冲区,我的意思是名称以空格开头的缓冲区。不确定此类缓冲区的官方术语是什么。

我认为空间前缀缓冲区的唯一区别是对它们禁用了撤消,但似乎还有其他差异导致 htmlize 包对空间前缀缓冲区的 react 不同。

(require 'htmlize)

;; function to write stuff on current buffer and call htmlize-region
(defun my-test-htmlize ()
  (insert "1234567")
  (emacs-lisp-mode)
  ;; (put-text-property 1 2 'font-lock-face "bold")
  (put-text-property 3 4 'font-lock-face 'bold)
  (with-current-buffer (htmlize-region (point-min)
                                       (point-max))
    (buffer-string)))

;; function that makes a (failed) attempt to make current buffer behave like a normal buffer
(defun my-make-buffer-normal ()
  (buffer-enable-undo))

;; like with-temp-buffer, except it uses a buffer that is not a space prefix buffer.
(defmacro my-with-temp-buffer-with-no-space-prefix (&rest body)
  (declare (indent 0) (debug t))
  (let ((temp-buffer (make-symbol "temp-buffer")))
    `(let ((,temp-buffer (generate-new-buffer "*tempwd2kemgv*")))
       (with-current-buffer ,temp-buffer
         (unwind-protect
             (progn ,@body)
           (and (buffer-name ,temp-buffer)
                (kill-buffer ,temp-buffer)))))))

;; In a normal buffer, bold face is htmlized.
(my-with-temp-buffer-with-no-space-prefix
  (my-test-htmlize))

;; In a space prefix buffer, bold face is not htmlized.
(with-temp-buffer
  (my-test-htmlize))

;; Bold face is still not htmlized.
(with-temp-buffer
  (my-make-buffer-normal)
  (my-test-htmlize))

最佳答案

前导空格表示临时或无趣的缓冲区。这些没有撤消历史,许多命令将这些缓冲区放置得不那么显眼,甚至完全忽略它们。见 Emacs Lisp Reference, Buffer Names :

Buffers that are ephemeral and generally uninteresting to the user have names starting with a space, so that the list-buffers and buffer-menu commands don't mention them (but if such a buffer visits a file, it is mentioned). A name starting with space also initially disables recording undo information; see Undo.



内置命令没有进一步的区别,但任何命令都可以以特殊方式自由处理这些缓冲区。您可能需要查阅 htmlize 来源以确定不同行为的原因。

关于emacs - Emacs 中普通缓冲区和空间前缀缓冲区的区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18418079/

相关文章:

emacs - 使用空间而不是控制来避免emacs小指?

emacs - 如何使用 ielm 在 Emacs lisp 中打印字符串?

Emacs dired - 使用预定义变量

emacs - 在 emacs lisp 中使用侧滑手势

emacs - 类 Vim */# - Emacs 中的(下一个/上一个单词)?

macos - 如何默认使用 Emacs 切换全屏?

emacs - 将缓冲区中的当前行作为 elisp 中的字符串

Emacs 次模式编程 : cancel toggle-off procedure?

Emacs 完成点函数

emacs - 如何获取Package安装的插件版本?