有没有办法在Emacs中限制缓冲区的大小?我已经查看了这个问题:Can I limit the length of the compilation buffer in Emacs?,但不是我想要的。我想限制用户正在使用的缓冲区的大小,这样他就不能超过预定义的大小。
有没有办法在Emacs中限制缓冲区的大小?我已经查看了这个问题:Can I limit the length of the compilation buffer in Emacs?,但不是我想要的。我想限制用户正在使用的缓冲区的大小,这样他就不能超过预定义的大小。
message-mode
的一个示例(将缓冲区置于此模式下,请键入M-x message-mode
)
(define-key message-mode-map [remap self-insert-command]
'(lambda ()
(interactive)
(let ((limit-buffer-size 30))
(message "buffer-size is %i of %i" (buffer-size) limit-buffer-size)
(if (< (buffer-size) limit-buffer-size)
(call-interactively 'self-insert-command)
(message "Maximum bufer size is %i characters" limit-buffer-size)))))
yank
更多字符。另一个选项是重新映射save-buffer
。我看不到直接访问的任何方法,你可以这样做:如果命令是self-insert-command
,则钩住pre-command-hook
,您可以检查buffer-size
是否低于所需长度。或者,您可以钩住post-self-insert-hook
以检查是否达到大小限制,撤消它并打印一条消息。为此,您需要编写一个在您的缓冲区中处于活动状态的minor-mode
。