emacs lisp,如何获取缓冲区主要模式?
我尝试搜索谷歌并查看手册,但仍然找不到如何获取缓冲区对象的主要模式。你能帮我举个例子或参考吗?感谢
我能找到的唯一解决方案是在更改缓冲区然后更改回原始缓冲区后查询主要模式。有更好的方法吗?
I have tried to search Google and look in the manual, but still cannot find how to get major mode of a buffer object. Can you help me with an example or a reference. Thanks
only solution I could find was to query major-mode after changing the buffer and then changing back to original buffer. Is there a better way to do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
这有问题吗?
with-current-buffer
将在返回时恢复您的缓冲区。Is there a problem with that?
with-current-buffer
will restore your buffer when it returns.对于当前缓冲区:
For current buffer:
一个简单的方法是使用 buffer-local-value 函数,因为major-mode 是一个缓冲区局部变量:
A simple way to do this is to use the
buffer-local-value
function sincemajor-mode
is a buffer-local variable:只是从以前的答案扩展 - 不带参数调用来获取当前缓冲区的模式:
例如在 *scratch* 缓冲区中:
Just extending from previous answers - call with no arguments to get the current buffer's mode:
E.g. in *scratch* buffer:
好吧,describe-mode 采用一个可选的缓冲区参数,但它显示了帮助...而且我不太确定它返回什么...
但这是我在简短搜索中可以找到的最好的...抱歉...
Well, describe-mode takes an optional buffer argument, but that displays the help... and I'm not exactly sure what it returns...
But that's the best I could find in a brief search... sorry...
简单评价一下:
Simply evaluate this:
另一种方法是,除了直接读取
major-mode
变量之外,还可以直接读取mode-name
变量。Another way, apart from directly readind the
major-mode
variable would be by directly readind themode-name
variable.