如何获得缓冲区主要模式

如何获得缓冲区主要模式

本文介绍了emacs lisp,如何获得缓冲区主要模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在 Google 上搜索并查看手册,但仍然找不到如何获取缓冲区对象的主要模式.你能帮我举个例子或参考.谢谢

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?

推荐答案

有什么问题吗?

(defun buffer-mode (buffer-or-string)
  "Returns the major mode associated with a buffer."
  (with-current-buffer buffer-or-string
     major-mode))

with-current-buffer 将在返回时恢复缓冲区.

with-current-buffer will restore your buffer when it returns.

这篇关于emacs lisp,如何获得缓冲区主要模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 11:39