help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Help: execute scripts form emacs


From: Xah Lee
Subject: Re: Help: execute scripts form emacs
Date: Wed, 14 Oct 2009 02:37:00 -0700 (PDT)
User-agent: G2/1.0

On Oct 12, 3:39 am, wdysun <grammopho...@gmail.com> 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/

reply via email to

[Prev in Thread] Current Thread [Next in Thread]