From: Xah <xahlee@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: How do you run your scripts efficiently?
Date: Tue, 16 Sep 2008 13:18:33 -0700 (PDT) [thread overview]
Message-ID: <419a0bc1-0df2-4d5e-9102-22798e574bd9@1g2000pre.googlegroups.com> (raw)
In-Reply-To: mailman.19322.1221540524.18990.help-gnu-emacs@gnu.org
On Sep 14, 8:13 am, "Ben Aurel" <ben.au...@gmail.com> wrote:
> hi
> I work mostly in vim, although I'm not a very advanced vim user. The
> problem is I can't find a simple way to easily run a perl script and
> capture its output.
>
> I've tried different things but I'm still *very* unsatisfied with the
> implementation of the following basic workflow:
>
> 1. Edit a perl script in the editor
> 2. Press one key (eg. F5) to save and run the script
> 3. Print the output to a window below the editor window
> 4. Possibility to easily switch to the output window and scroll
> through the messages
> 5. Possibility to easily switch back to the editor window
>
> Currently I work with a GNU screen/vim combo.
>
> ________________
> | term1: vim |
> |~
> |~
> |________________
> | term2
> | jdoe:%
> |________________
>
> But there is always a lot of typing involved. For example to
> accomplish step 2. in the workflow above:
>
> - ESC, :w (to save the script in vim in term1)
> - CTRL-Z, tab (to switch to term2)
> - type "./myscript.pl" (to run the script in term2)
>
> I think it's far from ideal... Can this easier be done with emacs? How
> is your workflow?
>
> thanks
> ben
I think this is becoming a FAQ... i've seen this asked several times
here now.
I had the same problem. Here's a simple elisp to solve it:
(defun run-current-file ()
"Execute or compile the current file.
For example, if the current buffer is the file x.pl,
then it'll call “perl x.pl” in a shell.
The file can be php, perl, python, bash, java.
File suffix is used to determine what program to run."
(interactive)
(let (ext-map file-name file-ext prog-name cmd-str)
; get the file name
; get the program name
; run it
(setq ext-map
'(
("php" . "php")
("pl" . "perl")
("py" . "python")
("sh" . "bash")
("java" . "javac")
)
)
(setq file-name (buffer-file-name))
(setq file-ext (file-name-extension file-name))
(setq prog-name (cdr (assoc file-ext ext-map)))
(setq cmd-str (concat prog-name " " file-name))
(shell-command cmd-str)))
(global-set-key (kbd "<f7>") 'run-current-file)
For detailed explanation, see:
http://xahlee.org/emacs/elisp_run_current_file.html
Xah
∑ http://xahlee.org/
☄
next prev parent reply other threads:[~2008-09-16 20:18 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <mailman.19322.1221540524.18990.help-gnu-emacs@gnu.org>
2008-09-16 13:50 ` How do you run your scripts efficiently? Dan Espen
2008-09-16 16:24 ` harven
2008-09-16 20:18 ` Xah [this message]
2008-09-14 15:13 Ben Aurel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=419a0bc1-0df2-4d5e-9102-22798e574bd9@1g2000pre.googlegroups.com \
--to=xahlee@gmail.com \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).