开发者

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

Suppose I have a variable newName which is bearing some mode name, e.g. "python-mode". How do I make current buffer of the mode specified by 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?"

Edit

@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).


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

or

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜