我正在学习如何在Emacs中使用Perl.我以前用R-Studio运行R.
如何在不离开Emacs的情况下执行命令?
示例:在R-studio中输入
print("hello world")
然后按Ctrl Enter键,R-studio执行命令并输出“hello world”.
如何在Emacs中为Perl命令执行相同操作?
我通常键入Ctrl X Ctrl F test.pl
print "hello world";
然后我不知道如何为Emacs执行命令.
解决方法
对于所有类型的解释语言,我使用
isend-mode,它允许将缓冲区的一部分发送到另一个缓冲区中的终端.
以下是如何使用它(安装后):
>打开一个ansi-term缓冲区:
M-xansi-termRET /斌/ bashRET
并在里面运行一个交互式perl会话:
perl -d -e 42RET
或者,安装term-run.el并在术语缓冲区中直接启动交互式perl会话:
M-xterm-run-shell-commandRETperl -d -e 42RET
>使用要执行的代码打开缓冲区,并将其与解释器缓冲区关联:
M-xisendRET * ANSI长期* RET
>在perl缓冲区中命中C-RET,将当前行发送到ansi-term缓冲区中的解释器.如果某个区域处于活动状态,则将发送跨越该区域的所有线路.
下面是一个建议的设置,允许更好地利用perl调试器特定的命令.通过以下自定义,x将被添加到所有指令之前(以便您看到结果),但打印命令除外.
(defun isend--perl (buf-name) "Prepend 'x ' to normal perl instructions. Leave 'print' instructions untouched." (with-current-buffer buf-name (goto-char (point-min)) (unless (looking-at "[[:space:]]*print") (insert "x "))) (insert-buffer-substring buf-name)) (defun isend-default-perl-setup () (when (eq major-mode 'perl-mode) (set (make-local-variable 'isend-send-line-function) #'isend--perl))) (add-hook 'isend-mode-hook #'isend-default-perl-setup)