关于持久化数据的请教。

with-temp-file 的锅

with-temp-file 会创建一个临时 buffer 并进入,这样位于当前 buffer 中的 buffer-local 变量 data 就读不到了,最简单的修改是这样:

(defun ttt-hello ()
  (when (derived-mode-p 'ttt-mode)
    (let ((tmp data))
      (with-temp-file ".ttt"
	(prin1 tmp (current-buffer))))))

(add-hook 'kill-buffer-hook 'ttt-hello)

在 with-temp-file 外面创建一个保存 data 的变量,这样在 with-temp-file 内部就可见了

1 个赞