gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 21:37:55 24 4
gpt4 key购买 nike

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

我认为空间前缀缓冲区的唯一区别是对它们禁用了撤消,但似乎还有其他差异导致 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com