简体   繁体   English

Emacs:如何设置存储在变量中的主模式?

[英]Emacs: how do I set a major-mode stored in a variable?

Suppose I have a variable newName which is bearing some mode name, eg "python-mode" . 假设我有一个带有某些模式名称的变量newName,例如"python-mode" How do I make current buffer of the mode specified by newName? 如何使newName指定的模式的当前缓冲区?

(progn
  (let (newName)
    (setq newName "python-mode")
    (newName) ;; doesn't work! It doesn't set current buffer's mode to be a python mode.
  )
)

This also doesn't work: 这也行不通:

(set-variable 'major-mode "python-mode")

This question is fundamental - since it is equal to "is it really possible to treat data as code in lisp?" 这个问题是根本的-因为它等于“真的有可能将数据当作Lisp中的代码来对待吗?”

Edit 编辑

@phils @phils

Your solution doesn't work for me. 您的解决方案对我不起作用。 I copy a buffer - and I want the new one to have the same mode as the old one. 我复制一个缓冲区-我希望新缓冲区具有与旧缓冲区相同的模式。 So I store the mode of the original buffer in the variable. 因此,我将原始缓冲区的模式存储在变量中。 Then try to apply Your solution. 然后尝试应用您的解决方案。 It gives error (it's the essence - I omit here the buffer-copying stuff): 它给出了错误(这是本质-我在这里省略了缓冲区复制的内容):

(let (sameMode)
  (setq sameMode major-mode)
  (funcall (intern sameMode))
)

sameMode stores here mode in the form of "python-mode" (example for python-mode). sameMode在此处以“ python-mode”的形式存储模式(例如python-mode的示例)。

(let ((mode "python-mode"))
  (funcall (intern mode)))

or 要么

(let ((mode 'python-mode))
  (funcall mode))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM