Both Python 2 and 3 in Emacs

后端 未结 5 997
不知归路
不知归路 2020-12-14 02:56

I have been using Emacs to write Python 2 code. Now I have both Python 2.6 and 3.0 installed on my system, and I need to write Python 3 code as well.

Here is how the

5条回答
  •  不思量自难忘°
    2020-12-14 03:35

    The answer is yes. If you can distinguish Python 2 from Python 3, then it is a Simple Matter Of Programming to get emacs to do what you want.

    (define run-python (&optional buffer)
        (with-current-buffer (or buffer (current-buffer))
            (if (is-python3-p)
                  (run-python3)
                (run-python2))))
    
    (define-key python-mode-map (kbd "C-c C-c") #'run-python)
    

    All that's left to do is implement is-python3-p and run-python3 (etc.)

提交回复
热议问题