unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Help: execute scripts form emacs
@ 2009-10-12 10:39 wdysun
  2009-10-12 18:37 ` wdysun
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: wdysun @ 2009-10-12 10:39 UTC (permalink / raw)
  To: Help-gnu-emacs


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?

Best Wishes
Piere
 
-- 
View this message in context: http://www.nabble.com/Help%3A-execute-scripts-form-emacs-tp25853628p25853628.html
Sent from the Emacs - Help mailing list archive at Nabble.com.





^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Help: execute scripts form emacs
       [not found] <mailman.8598.1255354671.2239.help-gnu-emacs@gnu.org>
@ 2009-10-12 14:10 ` Olivier Sirven
  2009-10-12 17:30 ` Pascal J. Bourguignon
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 10+ messages in thread
From: Olivier Sirven @ 2009-10-12 14:10 UTC (permalink / raw)
  To: help-gnu-emacs

wdysun <grammophonia@gmail.com> writes:

> 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?

Hello,

You might want have a look at shell-command lisp function (C-h f) for this
purpose.
All you'd have to do is to write a small lisp function retreiving the
current file name and path and running your command against it.
Then a simple define-key or global-set-key would do the trick for your
shortcut.

Olivier


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Help: execute scripts form emacs
       [not found] <mailman.8598.1255354671.2239.help-gnu-emacs@gnu.org>
  2009-10-12 14:10 ` Help: execute scripts form emacs Olivier Sirven
@ 2009-10-12 17:30 ` Pascal J. Bourguignon
  2009-10-14  9:37 ` Xah Lee
  2009-10-14 16:01 ` Raymond Wiker
  3 siblings, 0 replies; 10+ messages in thread
From: Pascal J. Bourguignon @ 2009-10-12 17:30 UTC (permalink / raw)
  To: help-gnu-emacs

wdysun <grammophonia@gmail.com> writes:

> 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?

If you are editing this filename.tex in emacs, you may also use
   M-x compile RET C-a C-k mytex filename RET
and thereafter:
   M-x recompile RET

-- 
__Pascal Bourguignon__


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Help: execute scripts form emacs
  2009-10-12 10:39 wdysun
@ 2009-10-12 18:37 ` wdysun
  2009-10-13 20:49 ` Maurizio Vitale
       [not found] ` <mailman.8700.1255466814.2239.help-gnu-emacs@gnu.org>
  2 siblings, 0 replies; 10+ messages in thread
From: wdysun @ 2009-10-12 18:37 UTC (permalink / raw)
  To: Help-gnu-emacs


mmmh! Seems complicated... given my knowledge of Lisp. Thanks for your help
anyway.

Pietro 




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?
> 
> Best Wishes
> Piere
>  
> 

-- 
View this message in context: http://www.nabble.com/Help%3A-execute-scripts-form-emacs-tp25853628p25860960.html
Sent from the Emacs - Help mailing list archive at Nabble.com.





^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Help: execute scripts form emacs
  2009-10-12 10:39 wdysun
  2009-10-12 18:37 ` wdysun
@ 2009-10-13 20:49 ` Maurizio Vitale
  2009-10-13 23:10   ` Andreas Politz
       [not found] ` <mailman.8700.1255466814.2239.help-gnu-emacs@gnu.org>
  2 siblings, 1 reply; 10+ messages in thread
From: Maurizio Vitale @ 2009-10-13 20:49 UTC (permalink / raw)
  To: help-gnu-emacs

>>>>> "wdysun" == wdysun  <grammophonia@gmail.com> writes:

    wdysun> Hello dears,

    wdysun> suppose I have a script in /bin, let us assume it is called
    wdysun> mytex. Suppose I am editing a file called filename.tex.

    wdysun> If I run the following command from the console:

    wdysun> $ mytex filename

    wdysun> this will do several things (tex the filename with several
    wdysun> options, then convert the dvi to pdf and it deletes all aux
    wdysun> files I don't need).

    wdysun> There is a way to launch the script from emacs or even to
    wdysun> build a function so that I can run the command just with M -
    wdysun> something?

You can do two things:

    - in a buffer local variable set the compile command to mytex
      filename and then use M-x compile

    - but if your script is only for running latex as much as needed,
      then bibtex, then latex again (and maybe switch between the dvi
      and pdf path), do yourself a favour and use AUCTeX 
      (http://www.gnu.org/software/auctex/). You won't look back.

OTH,

        Maurizio





^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Help: execute scripts form emacs
       [not found] ` <mailman.8700.1255466814.2239.help-gnu-emacs@gnu.org>
@ 2009-10-13 22:49   ` Jon Solberg
  0 siblings, 0 replies; 10+ messages in thread
From: Jon Solberg @ 2009-10-13 22:49 UTC (permalink / raw)
  To: help-gnu-emacs

On 2009-10-13, Maurizio Vitale 
<mav@cuma.i-did-not-set--mail-host-address--so-tickle-me> wrote:
>>>>>> "wdysun" == wdysun  <grammophonia@gmail.com> writes:
>
>    wdysun> Hello dears,
>
>    wdysun> suppose I have a script in /bin, let us assume it is called
>    wdysun> mytex. Suppose I am editing a file called filename.tex.
>
>    wdysun> If I run the following command from the console:
>
>    wdysun> $ mytex filename
>
>    wdysun> this will do several things (tex the filename with several
>    wdysun> options, then convert the dvi to pdf and it deletes all aux
>    wdysun> files I don't need).
>
>    wdysun> There is a way to launch the script from emacs or even to
>    wdysun> build a function so that I can run the command just with M -
>    wdysun> something?
>
> You can do two things:
>
>     - in a buffer local variable set the compile command to mytex
>       filename and then use M-x compile
>
>     - but if your script is only for running latex as much as needed,
>       then bibtex, then latex again (and maybe switch between the dvi
>       and pdf path), do yourself a favour and use AUCTeX 
>       (http://www.gnu.org/software/auctex/). You won't look back.

Agreed. 

AUCTeX (and RefTeX for that matter) are indeed very useful tools for
compiling *TeX files and I wouldn't want to be without them. 

However, sometimes using a command line script can be quite convenient
(especially if you have many source files or need to create different
types of output on the fly). A couple of years back when I wrote my
thesis I used the following Makefile to be able to easier comqpile
versions for print, review and keeping my directories clean. This
enabled me to create a final pdf with "make final" remove temporary
files from my working directory with "make clear" et c.

Nothing mind blowing I admit, but the general idea should be easy to
use for similar jobs. I'll post it here and hopes it can help the OP:

THESIS_FILES=thesis.tex introduction.tex summary.tex appendix.tex
REFERENCES=biblio.bib LATEX=latex

all:  thesis

# You are supposed to make a readers digest of your thesis before your
# presentation:

condensate:
	latex condensate
	dvips -Pcmz -Pamz -o condensate.ps condensate
	rm -f condensate.pdf
#	pdfmake -4 condensate.ps
	ps2pdf condensate.ps
final:  thesis references postscript pdf

clear:
	rm -f *.aux *.dvi *.lot *.bbl *.lof *.ps *.toc *.blg *.log
	*.ilg
	rm -f *.thm *.tmp *.info *.idx
	rm -f *~

thesis: $(THESIS_FILES)
	$(LATEX) thesis

references: $(REFERENCES)
	    bibtex thesis
	    $(LATEX) thesis
	    $(LATEX) thesis

postscript: thesis
	    dvips -Pcmz -Pamz thesis -o thesis.ps

booklet: postscript
	 rm -f thesis-booklet.ps
	 ./booklet thesis.ps thesis-booklet.ps

pdf: thesis
     rm -f thesis.pdf
#    pdfmake -4 thesis.ps
     ps2pdf thesis.ps
     gv thesis.pdf
# Put your index settings in thesis.ist
index: thesis
       makeindex -s thesis.ist thesis.idx
       $(LATEX) thesis.tex

-- 
Jon Solberg (remove "nospam." from email address).


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Help: execute scripts form emacs
  2009-10-13 20:49 ` Maurizio Vitale
@ 2009-10-13 23:10   ` Andreas Politz
  2009-10-14  8:24     ` wdysun
  0 siblings, 1 reply; 10+ messages in thread
From: Andreas Politz @ 2009-10-13 23:10 UTC (permalink / raw)
  To: help-gnu-emacs

Maurizio Vitale
<mav@cuma.i-did-not-set--mail-host-address--so-tickle-me> writes:

>>>>>> "wdysun" == wdysun  <grammophonia@gmail.com> writes:
[how to run a shellscript]
> You can do two things:
>

Here is one more thing to do.

(defun mytex ()
  (interactive)
  (or buffer-file-name
      (call-interactively 'save-buffer))
  (shell-command
   (format "mytex '%s'" buffer-file-name)))

-ap





^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Help: execute scripts form emacs
  2009-10-13 23:10   ` Andreas Politz
@ 2009-10-14  8:24     ` wdysun
  0 siblings, 0 replies; 10+ messages in thread
From: wdysun @ 2009-10-14  8:24 UTC (permalink / raw)
  To: Help-gnu-emacs


Hello ap,

your suggestion, this one
;;---------------------------------------------------------------
(defun mytex ()
  (interactive)
  (or buffer-file-name
      (call-interactively 'save-buffer))
  (shell-command
   (format "mytex '%s'" buffer-file-name)))
;;----------------------------------------------------------------

works except that is takes the entire buffer name, so it also take the file
extension, in fact it returns a warning like this:


WARNING    /home/pietro/try.tex.tex does not exists

How can I modify the function above in order to get the file name without
extension in the last line above? I tried to put somehow the function
file-name-sans-extension which is supposed to what I probably put it in a
wrong way.

Best 
Pietro 




-- 
View this message in context: http://www.nabble.com/Help%3A-execute-scripts-form-emacs-tp25853628p25887185.html
Sent from the Emacs - Help mailing list archive at Nabble.com.





^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Help: execute scripts form emacs
       [not found] <mailman.8598.1255354671.2239.help-gnu-emacs@gnu.org>
  2009-10-12 14:10 ` Help: execute scripts form emacs Olivier Sirven
  2009-10-12 17:30 ` Pascal J. Bourguignon
@ 2009-10-14  9:37 ` Xah Lee
  2009-10-14 16:01 ` Raymond Wiker
  3 siblings, 0 replies; 10+ messages in thread
From: Xah Lee @ 2009-10-14  9:37 UTC (permalink / raw)
  To: help-gnu-emacs

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/^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Help: execute scripts form emacs
       [not found] <mailman.8598.1255354671.2239.help-gnu-emacs@gnu.org>
                   ` (2 preceding siblings ...)
  2009-10-14  9:37 ` Xah Lee
@ 2009-10-14 16:01 ` Raymond Wiker
  3 siblings, 0 replies; 10+ messages in thread
From: Raymond Wiker @ 2009-10-14 16:01 UTC (permalink / raw)
  To: help-gnu-emacs

wdysun <grammophonia@gmail.com> writes:

> 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?

	Looks like M-x compile will do what you want... at the prompt,
type the command (mytex), space, and the filename. As a bonus, you will
get filename completion for both the command and the filename(s).

	Even better, the next time you want to do this, the previous
command will come up as default.

	Even even better: if error messages from the command fit a
certain pattern, you should be able to use M-x next-error to locate the
offending line(s) in your input file.

	Note: tex-mode (or whatever it is called) will probably have
some predefined support for doing this even more easily.


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2009-10-14 16:01 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.8598.1255354671.2239.help-gnu-emacs@gnu.org>
2009-10-12 14:10 ` Help: execute scripts form emacs Olivier Sirven
2009-10-12 17:30 ` Pascal J. Bourguignon
2009-10-14  9:37 ` Xah Lee
2009-10-14 16:01 ` Raymond Wiker
2009-10-12 10:39 wdysun
2009-10-12 18:37 ` wdysun
2009-10-13 20:49 ` Maurizio Vitale
2009-10-13 23:10   ` Andreas Politz
2009-10-14  8:24     ` wdysun
     [not found] ` <mailman.8700.1255466814.2239.help-gnu-emacs@gnu.org>
2009-10-13 22:49   ` Jon Solberg

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).