[英]How can I limit the size of a buffer in Emacs?
Is there any way that I can limit the size of a buffer in Emacs? 有什么办法可以限制Emacs中缓冲区的大小吗? have checked this question already: Can I limit the length of the compilation buffer in Emacs?
已经检查过这个问题: 我可以限制Emacs中编译缓冲区的长度吗? but it's not what I want.
但这不是我想要的。 I want to restrict the size of a buffer that the user is working on and so he can't put more than the pre-defined size.
我想限制用户正在处理的缓冲区的大小,因此他不能放置超过预定义的大小。
An example for message-mode
(to put a buffer in this mode type Mx message-mode
) message-mode
的示例(将缓冲区置于此模式类型Mx 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)))))
Note that user still can yank
more characters. 请注意,用户仍然可以
yank
更多字符。 Another option is to remap save-buffer
. 另一种选择是重新映射
save-buffer
。
I cannot see any way to access this directly, what you can do is this: hook pre-command-hook
if the command is an self-insert-command
you can check if buffer-size
is bellow the length you want. 我看不到任何直接访问它的方法,你可以这样做:hook
pre-command-hook
如果命令是一个self-insert-command
你可以检查buffer-size
是否低于你想要的长度。 Alternatively you can hook post-self-insert-hook
to check if the hit the size limit, undo it and print a message. 或者,您可以挂钩
post-self-insert-hook
以检查是否达到大小限制,撤消它并打印消息。 For all this you will need to write a minor-mode
that is active in your buffer. 为此,您需要编写一个在缓冲区中处于活动状态的
minor-mode
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.