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).
funcall? I really recommend reading the documentation for things like this, since it's included with emacs and would have easily answered this question. Guessing how a language works without trying to understand it first is unlikely to give you much success!internconverts a string to an atom. In Emacs, the value ofmajor-modeis an atom an thus you should not useintern. Btw. This is exactly as @phils specified in his second example in his answer.internreturns a symbol. An atom is any object which is not a cons cell, and therefore a string is an atom (which you can confirm with the(atom)predicate function).