通過空間前綴緩衝區,我指的是名稱以空格開頭的緩衝區。不知道這種緩衝區的官方術語是什麼。Emacs中的正常緩衝區和空間前綴緩衝區之間的區別?
我認爲空間前綴緩衝區的唯一區別是撤消在它們上被禁用,但似乎還有其他差異導致包htmlize
對空間前綴緩衝區的反應不同。
(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))