运行emacs

问题描述 投票:0回答:4
无论如何,我目前正在研究一个需要用户输入的Python脚本(CMD.CMD的子类)。 在vim中,如果我想尝试一下,我可以简单地做

:!python %

,然后可以与脚本进行交互,直到它退出为止。 在Emacs中,我尝试了

M-! python script.py

,这确实可以在单独的缓冲区中运行脚本,但是随后返回似乎并没有将其发送回脚本,而是被Emacs Buffer抓住。  我还试图查看Python-Mode的
C-c C-c
,但这在某个临时目录中运行脚本,而我只想在
(pwd)
中运行它。

,有什么规范的方式吗?
	

我不知道

caronical

,但是如果我需要与脚本进行互动,我会做
python emacs
4个回答
4
投票
-

xshellret并从那里运行脚本。 也有更严重的终端仿真,而不仅仅是外壳的东西。


我喜欢使用emacs“ compile”命令来测试/运行我的python脚本。  terminal-emulator -

M

CompileX将拔出默认的“ make -k”,但是如果您删除它并将其放入脚本的命令行(包括选项),则随后的“ compiles”将自动提供新的“编译”命令。脚本的所有输出都将出现在编译缓冲区中。 (与外壳相反,每次调用它时都会提供一个不错的干净缓冲区。适用于搜索等。如果您忘记在运行前忘记保存脚本,则编译会询问您是否想保存文件。)在编译缓冲区中启用交互,只需将commile commile compile peartix带有RET(commile commile commile commile commile compile ins in in compile in in in compile in in in compile in incile in in compile n in In

M-x compile
)。 重新启动Emacs时,您将失去命令行。但是,您可以通过将python脚本的底部放置在python脚本的底部(实际上是python评论)来设置持有脚本的缓冲区的编译命令:


4
投票

对于具有复杂调用的脚本,这很方便。 注意:Python评论字符“#”保护它免受Python解释器的影响,而Emacs知道要设置这些变量,因为它在每个文件打开时都查看每个文件的底部。 我希望能够像编译命令一起编译C代码时能够以我的python脚本中的“编译错误”跳跃,但是我太懒了,无法创建Emacs正则表达式以使这项工作。也许这将使堆栈溢出成为另一个好问题!


    

i当前使用这些挂钩来定义我的汇编命令:
comint-mode
与此lambda设置以交互式调用编译函数:
 # Trigger emacs to run this script using the "compile" command
 # ;;; Local Variables: ***
 # ;;; compile-command: "my_cool_script.py --complicated_option some_filename.txt" ***
 # ;;; end: ***

一个按钮可以统治它们!

如果您按

F4

(在我的情况下,可以在lambda中设置键的键),则将在C ++或C模式下打开一个文件,并以Python或Perl模式(交互式)

运行python或Perl模式的文件。


3
投票
我认为

(defun convert-filename-to-executable (file) (if (eq system-type 'windows-nt) (concat (file-name-sans-extension file) ".exe") ;; linux (concat "./" (file-name-sans-extension file)))) (add-hook 'c++-mode-hook (lambda () (unless (file-exists-p "Makefile") (set (make-local-variable 'compile-command) (let* ((file (file-name-nondirectory buffer- file-name)) (executable (convert-filename-to-executable file))) (concat "g++ -g -Wall -o " (file-name-sans-extension file) " " file " && " executable)))))) (add-hook 'c-mode-hook (lambda () (unless (file-exists-p "Makefile") (set (make-local-variable 'compile-command) (let* ((file (file-name-nondirectory buffer-file-name)) (executable (convert-filename-to-executable file))) (concat "gcc -g -ansi -Wall -Wpedantic -Wextra -Wc++-compat -Wconversion -o " (file-name-sans-extension file) " " file " && " executable)))))) (add-hook 'python-mode-hook (lambda () (set (make-local-variable 'compile-command) (concat "python " buffer-file-name)))) (add-hook 'perl-mode-hook (lambda () (set (make-local-variable 'compile-command) (concat "python " buffer-file-name))))

是对码头的最忠实的仿真。 但是我看不到将参数传递给该过程的方法。 当然,您只需从
(global-set-key (kbd "<f4>") (lambda () (interactive) (setq current-prefix-arg '(4)) (call-interactively 'compile)))
缓冲区内的外壳启动它。

但我认为最好的办法是不使用

global-set-key
,而是使用“正确”的新功能,即通过将路径发送到当前文件而不是制作临时文件。  当然,您必须首先保存当前文件,但以下内容至少应该使您进入正确的轨道。

ansi-term

检查了,这使您可以进行互动。 要获取标签,您有一些选择。

C-qtab

将始终给您一个字面的标签


1
投票
ansi-term

中的字面标签。

python-send-buffer

我确定还有其他我想不到的

    

如果您使用C-C-C-C,则创建了缓冲区(寻找下侧python)。尝试更改为该缓冲区*,每次击中C-C C-C时,结果都在此显示,您需要查看该缓冲区以获得结果。使用C-X 2,以便同时看到两个缓冲区。 
还可以尝试C-C C-Z(切换到外壳)。

*我使用Ibuffer来管理缓冲区,非常好。 (顺便说一句,这个

http://tuhdo.github.io/index.html

是一个学习一些emacs的地方)
  • Edit:您是否尝试过C-C C-P? the Ent的另一个选项:
  • 使用
  • (defun python-send-file () (interactive) (save-buffer) (python-send-string (concat "execfile('" (buffer-file-name) "')"))) ;; This overwrites the `python-send-buffer' binding so you may want to pick another key (eval-after-load "python" (define-key python-mode-map "\C-c\C-c" 'python-send-file))

    与fgallina的python.el

     -PWD合作很好地工作 -  PWD将是缓冲区文件的位置。
        

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.