[英]Programmatically setting major mode of buffer with emacs lisp
I wish to programmatically set the major mode of a buffer. 我希望以编程方式设置缓冲区的主要模式。 I have dug into the documentation, and the function
set-buffer-major-mode
only takes a buffer object. 我已经深入研究了文档,而函数
set-buffer-major-mode
只接受了一个缓冲对象。 I am essentially looking for a function that takes a buffer object and a mode name. 我本质上是在寻找一个带缓冲区对象和模式名称的函数。
Alternatively, I also tried using auto-mode-alist
by forcing the buffer to have a file extension but that did not work even when I called the set-buffer-major-mode
function. 或者,我也尝试使用
auto-mode-alist
强制缓冲区具有文件扩展名,但即使我调用set-buffer-major-mode
函数也不起作用。
Thanks for all the help! 感谢您的帮助!
The basics are that if you want to switch to my
mode, all you have to do is to call my-mode
, for example: 基本的是,如果你想切换到
my
模式,你所要做的就是调用my-mode
,例如:
(with-current-buffer buffer
(my-mode))
If you have a buffer and a variable bound to the major mode, you could use the following: 如果您有一个缓冲区和一个绑定到主模式的变量,您可以使用以下内容:
(with-current-buffer buffer
(funcall the-mode-i-want))
Again, if you have a variable bound to a string, you have to convert it to a symbol using intern
: 同样,如果您有一个绑定到字符串的变量,则必须使用
intern
将其转换为符号:
(with-current-buffer buffer
(funcall (intern the-name-of-the-mode-i-want)))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.