* How do you run your scripts efficiently?
@ 2008-09-14 15:13 Ben Aurel
0 siblings, 0 replies; 4+ messages in thread
From: Ben Aurel @ 2008-09-14 15:13 UTC (permalink / raw)
To: help-gnu-emacs
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
^ permalink raw reply [flat|nested] 4+ messages in thread
[parent not found: <mailman.19322.1221540524.18990.help-gnu-emacs@gnu.org>]
* Re: How do you run your scripts efficiently?
[not found] <mailman.19322.1221540524.18990.help-gnu-emacs@gnu.org>
@ 2008-09-16 13:50 ` Dan Espen
2008-09-16 16:24 ` harven
2008-09-16 20:18 ` Xah
1 sibling, 1 reply; 4+ messages in thread
From: Dan Espen @ 2008-09-16 13:50 UTC (permalink / raw)
To: help-gnu-emacs
"Ben Aurel" <ben.aurel@gmail.com> writes:
> 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
Run the Perl script under M-x compile
compile will offer to save the file if it's not already saved.
I bind compile to F1:
(define-key global-map [(f1)] 'compile)
Compile wants to use "make".
If you don't want to use a makefile
put this at the bottom of the perl-file:
# Local Variables:
# compile-command: "./perl-script"
# End:
To switch to the other window, use M-x other-window,
I do this enough that I bind it to F10:
(define-key global-map [(f10)] 'other-window)
I think that covers all 5 issues above.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: How do you run your scripts efficiently?
2008-09-16 13:50 ` Dan Espen
@ 2008-09-16 16:24 ` harven
0 siblings, 0 replies; 4+ messages in thread
From: harven @ 2008-09-16 16:24 UTC (permalink / raw)
To: help-gnu-emacs
On Sep 16, 3:50 pm, Dan Espen <dan...@MORE.mk.SPAMtelcordia.com>
wrote:
> "Ben Aurel" <ben.au...@gmail.com> writes:
> > 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
>
> Run the Perl script under M-x compile
> compile will offer to save the file if it's not already saved.
>
> I bind compile to F1:
>
> (define-key global-map [(f1)] 'compile)
>
> Compile wants to use "make".
> If you don't want to use a makefile
> put this at the bottom of the perl-file:
>
> # Local Variables:
> # compile-command: "./perl-script"
> # End:
>
> To switch to the other window, use M-x other-window,
> I do this enough that I bind it to F10:
>
> (define-key global-map [(f10)] 'other-window)
>
> I think that covers all 5 issues above.
I think M-x compile print the result of the compilation process in
another window. As far as I understand, the OP wants the actual output
of the script to be displayed in another window. This can be done by
putting the following in the initfile.
(global-set-key (kbd "<f5>") (lambda ()
(interactive)
(save-buffer)
(shell-command (buffer-file-name))))
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: How do you run your scripts efficiently?
[not found] <mailman.19322.1221540524.18990.help-gnu-emacs@gnu.org>
2008-09-16 13:50 ` Dan Espen
@ 2008-09-16 20:18 ` Xah
1 sibling, 0 replies; 4+ messages in thread
From: Xah @ 2008-09-16 20:18 UTC (permalink / raw)
To: help-gnu-emacs
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/
☄
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2008-09-16 20:18 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-14 15:13 How do you run your scripts efficiently? Ben Aurel
[not found] <mailman.19322.1221540524.18990.help-gnu-emacs@gnu.org>
2008-09-16 13:50 ` Dan Espen
2008-09-16 16:24 ` harven
2008-09-16 20:18 ` Xah
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).