在emacs里怎么运行python shell?
-
- 帖子: 1038
- 注册时间: 2007-01-10 9:32
在emacs里怎么运行python shell?
在emacs里,python程序有个input输入,emacs里也正常运行了,要我输入一个字母,可是在buffer里没法输入,是只读的,我也不知道怎么在emacs里进入python shell。
-
- 帖子: 750
- 注册时间: 2006-03-19 11:39
Re: 在emacs里怎么运行python shell?
[lisp]
(defun python-shell()
"make a python shell"
(interactive)
(switch-to-buffer (make-comint "python" "python" nil "-i")))
[/lisp]
(defun python-shell()
"make a python shell"
(interactive)
(switch-to-buffer (make-comint "python" "python" nil "-i")))
[/lisp]
-
- 帖子: 1038
- 注册时间: 2007-01-10 9:32
Re: 在emacs里怎么运行python shell?
kardinal 写了:[lisp]
(defun python-shell()
"make a python shell"
(interactive)
(switch-to-buffer (make-comint "python" "python" nil "-i")))
[/lisp]
我把这个写在.emacs里也没有用啊 ,这东西到底怎么玩?
-
- 帖子: 1038
- 注册时间: 2007-01-10 9:32
Re: 在emacs里怎么运行python shell?
代码: 全选
(defun python-shell()
"make a python shell"
(interactive)
(switch-to-buffer (make-comint "python" "python" nil "-i")))
(global-linum-mode t)
上面是我的配置文件,就这么几行,反复检查了几遍,都没问题。
-
- 帖子: 750
- 注册时间: 2006-03-19 11:39
Re: 在emacs里怎么运行python shell?

一般情况下是 M-x python-shell
或者在配置文件里通过 (python-shell) 调用
例如 (global-set-key "C-xC-x" 'python-shell) 用 C-x C-x调用
上面这句我不保证是正确的,因为从来不用 global-set-key 绑定按键

-
- 帖子: 750
- 注册时间: 2006-03-19 11:39
Re: 在emacs里怎么运行python shell?
可以一次性定义许多这样的函数
[lisp]
(defun concat-symbol (&rest lst)
(intern (apply 'concat (mapcar (lambda(x)(if (symbolp x) (symbol-name x) x)) lst))))
(defmacro x-shell (prog)
`(defun ,(concat-symbol prog '-shell)()
,(format "make a %s shell" prog)
(interactive)
(switch-to-buffer (make-comint ,(symbol-name prog) ,(symbol-name prog) nil "-i"))))
(mapcar (lambda(x)(eval `(x-shell ,x)))
'(python lua ruby))
[/lisp]
[lisp]
(defun concat-symbol (&rest lst)
(intern (apply 'concat (mapcar (lambda(x)(if (symbolp x) (symbol-name x) x)) lst))))
(defmacro x-shell (prog)
`(defun ,(concat-symbol prog '-shell)()
,(format "make a %s shell" prog)
(interactive)
(switch-to-buffer (make-comint ,(symbol-name prog) ,(symbol-name prog) nil "-i"))))
(mapcar (lambda(x)(eval `(x-shell ,x)))
'(python lua ruby))
[/lisp]
-
- 帖子: 750
- 注册时间: 2006-03-19 11:39
Re: 在emacs里怎么运行python shell?
定义成宏用 mapcar 调用太麻烦了
[lisp]
(defun x-shell (prog)
(eval
`(defun ,(concat-symbol prog '-shell)()
,(format "make a %s shell" prog)
(interactive)
(switch-to-buffer (make-comint ,(symbol-name prog) ,(symbol-name prog) nil "-i")))))
(mapcar 'x-shell '(python ruby lua))
[/lisp]
[lisp]
(defun x-shell (prog)
(eval
`(defun ,(concat-symbol prog '-shell)()
,(format "make a %s shell" prog)
(interactive)
(switch-to-buffer (make-comint ,(symbol-name prog) ,(symbol-name prog) nil "-i")))))
(mapcar 'x-shell '(python ruby lua))
[/lisp]
-
- 帖子: 1038
- 注册时间: 2007-01-10 9:32
Re: 在emacs里怎么运行python shell?
我在运行前确实是调用了python-shell的minor模式了,但是它还是往buffer输出,那个是只读区域。看很很多资料。
楼上的这段代码考在配置了有错误,不过还是谢谢。我用的C-c C-z调用的,也用Meta-x python-shell调用了。
楼上的这段代码考在配置了有错误,不过还是谢谢。我用的C-c C-z调用的,也用Meta-x python-shell调用了。
-
- 帖子: 750
- 注册时间: 2006-03-19 11:39
Re: 在emacs里怎么运行python shell?

我觉得错误的可能性不是特别大,因为我给那行代码只是最简单的调用,并且实在是无法更进一步的简单了
你第一个图是编译输出窗口,这个不能读取标准输入是必须的
而执行当前文件和运行 python shell 完全是两码事,在 python shell 里运行代码的方式你可以看看我的图
但是你第二个图是用的扩展?
…… python 真是开源语言界的微软啊
-
- 帖子: 1038
- 注册时间: 2007-01-10 9:32
Re: 在emacs里怎么运行python shell?
楼上把配置发给我,不知道你还用了什么插件。
我的就是源里安装的,没有安装任何插件,我另外安装了python checker,不知道是不是和这个有关?
你给的是哪段,第一段还是第二段,我只用了第二段(有错误的那段)
晚上我把我的配置文件发上来,你帮我看看,我学emacs才几天。
我的就是源里安装的,没有安装任何插件,我另外安装了python checker,不知道是不是和这个有关?
你给的是哪段,第一段还是第二段,我只用了第二段(有错误的那段)
晚上我把我的配置文件发上来,你帮我看看,我学emacs才几天。
-
- 帖子: 750
- 注册时间: 2006-03-19 11:39
Re: 在emacs里怎么运行python shell?
https://github.com/ran9er/init.emacs/tarball/master
在home目录解压,然后把里面的 bootstrap.el 文件拷贝为 ~/.emacs
或者在 .emacs 里面添加 (load "~/xxx-init.emacs/bootstrap")
见https://github.com/ran9er/init.emacs/co ... 28157a28c6
在home目录解压,然后把里面的 bootstrap.el 文件拷贝为 ~/.emacs
或者在 .emacs 里面添加 (load "~/xxx-init.emacs/bootstrap")
见https://github.com/ran9er/init.emacs/co ... 28157a28c6
- Fermat618
- 帖子: 728
- 注册时间: 2008-12-28 16:01
Re: 在emacs里怎么运行python shell?
我这里默认M-x run-python 就起作用,还很多run开头的都能起作用。kardinal 写了:[lisp]
(defun python-shell()
"make a python shell"
(interactive)
(switch-to-buffer (make-comint "python" "python" nil "-i")))
[/lisp]
爱因斯坦会弹钢琴
爱因斯坦会拉小提琴
爱因斯坦会骑自行车
爱因斯坦会拉小提琴
爱因斯坦会骑自行车
-
- 帖子: 750
- 注册时间: 2006-03-19 11:39
Re: 在emacs里怎么运行python shell?
很多语言模式的扩展中都带有 run-xxx 的命令,但是这得靠扩展作者的自觉,人家就是不提供这个命令你也拿人家没办法
而这些命令基本都是用 comint-mode 扩展的,加了些初始化配置什么的,自己弄一样的
而这些命令基本都是用 comint-mode 扩展的,加了些初始化配置什么的,自己弄一样的
- Fermat618
- 帖子: 728
- 注册时间: 2008-12-28 16:01
Re: 在emacs里怎么运行python shell?
看介绍lisp的时候,有一句印象深刻,“用lisp的总喜欢自己造轮子,总觉得自己的轮子比别人的圆”kardinal 写了:很多语言模式的扩展中都带有 run-xxx 的命令,但是这得靠扩展作者的自觉,人家就是不提供这个命令你也拿人家没办法
而这些命令基本都是用 comint-mode 扩展的,加了些初始化配置什么的,自己弄一样的
爱因斯坦会弹钢琴
爱因斯坦会拉小提琴
爱因斯坦会骑自行车
爱因斯坦会拉小提琴
爱因斯坦会骑自行车
-
- 帖子: 750
- 注册时间: 2006-03-19 11:39
Re: 在emacs里怎么运行python shell?

当然 lisp 也很适合干这种事,这才是它的强大之处