2009-10-14

run current file

On Oct 12, 3:39 am, wdysun wrote:
> Hello dears,
>
> suppose I have a script in /bin, let us assume it is called mytex. Suppose I
> am editing a file called filename.tex.
>
> If I run the following command from the console:
>
> $ mytex filename
>
> this will do several things (tex the filename with several options, then
> convert the dvi to pdf and it deletes all aux files I don't need).
>
> There is a way to launch the script from emacs or even to build a function
> so that I can run the command just with M - something?

have a look here:

• Elisp Lesson: Execute/Compile Current File
http://xahlee.org/emacs/elisp_run_current_file.html

excerpt:

(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, ruby, javascript, bash, ocaml, java.
File suffix is used to determine what program to run."
(interactive)
(let (ext-map fname suffix progName cmdStr)
(setq ext-map ; a keyed list of file suffix to comand-line program to run
'(
("php" . "php")
("pl" . "perl")
("py" . "python")
("rb" . "ruby")
("js" . "js")
("sh" . "bash")
("ml" . "ocaml")
("lsl" . "lslint")
("vbs" . "cscript")
("java" . "javac")
)
)
(setq fname (buffer-file-name))
(setq suffix (file-name-extension fname))
(setq progName (cdr (assoc suffix ext-map)))
(setq cmdStr (concat progName " \"" fname "\""))

(if (string-equal suffix "el")
(load-file fname)
(progn
(message "Running...")
(shell-command cmdStr)))
))

Xah
∑ http://xahlee.org/

No comments:

Post a Comment