我正在尝试做的与所做的非常相似,make-local-variable
只是我不希望为每个创建的缓冲区声明变量(仅适用于属于特定模式的缓冲区)。这主要是性能问题,创建的对象可能很大。更重要的是,我需要一个函数(get-buffer-property buffer property-name)
来确定特定缓冲区的状态。
从本质上讲,我追求的是类似的东西,get-buffer-proccess
除了我需要一个过程以外的东西。
在主要模式的声明中创建此类对象并在此类缓冲区被杀死时在挂钩中销毁它们是否有意义,或者有更好的方法吗?
这是我到目前为止所拥有的:
(defun haxe-get-buffer-property (buffer property)
"Pops to BUFFER, reads the value of the PROPERTY and returns it."
(let ((result
(save-excursion
(pop-to-buffer buffer)
(symbol-value property))))
result))
(defmacro haxe-buffer-property (buffer property)
`(haxe-get-buffer-property ,buffer ',property))
(defmacro deflocal (var &rest body)
(let ((symb var)
(val (car body))
(doc (cadr body)))
`(progn
(defvar ,symb nil ,doc)
(unless ,symb (setq ,symb ,val))
(make-local-variable ',symb))))
但我不喜欢我必须访问缓冲区,因为我不确定副作用。
编辑:更多信息。
发生的事情是这样的,有多个缓冲区可以与网络连接过程进行交互。该进程可以由缓冲区组共享(重要的是缓冲区共享该进程),但也可能同时存在多个缓冲区,这些缓冲区具有相互分配的不同进程。除了进程本身,还有很多关于进程状态的信息要存储(接收了多少数据,发送了什么,错误等)。同样,这些数据必须由缓冲区组共享。
编辑2:
这就是上面代码的结果,以防万一有人需要它。
(defmacro deflocal (var &rest body)
(let ((symb var)
(val (car body))
(doc (cadr body)))
`(progn
(set (make-local-variable ',symb) ,val)
(put ',symb 'variable-documentation ,doc))))
(defun haxe-get-buffer-property (buffer property)
"Pops to BUFFER, reads the value of the PROPERTY and returns it."
(let ((result
(with-current-buffer buffer
(symbol-value property))))
result))
(defun haxe-set-buffer-property (buffer &rest proplist)
"Pops to BUFFER and sets properties in parallel, similar to `pset'."
(let ((result
(with-current-buffer buffer
(loop for (property value) on proplist by #'cddr
do (set property value)
finally (return value)))))
result))
(defmacro haxe-buffer-pset-property (buffer &rest proplist)
`(haxe-set-buffer-property
,buffer
,@(loop for (key value) on proplist by #'cddr
nconc (list (list 'quote key) value))))
(defalias 'haxe-pbset #'haxe-buffer-pset-property)
(defmacro haxe-buffer-setf-property (buffer &rest proplist)
`(with-current-buffer ,buffer
,@(list (append '(setf) proplist))))
(defalias 'haxe-pbsetf #'haxe-buffer-setf-property)