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

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

Re: subsitute for current file name in buffer in emacs


From: Xah Lee
Subject: Re: subsitute for current file name in buffer in emacs
Date: Sat, 26 Jan 2008 15:30:26 -0800 (PST)
User-agent: G2/1.0

you might be interested in the following code. It allows you to press
a button, and have emacs compile the file in the current buffer.

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

Full explanation of this code is here:
http://xahlee.org/emacs/elisp_run_current_file.html

in your case, you might add:

    ("cpp" . "path-to-your-g++")

  Xah
  xah@xahlee.org
∑ http://xahlee.org/

☄

On Jan 26, 8:03 am, shankarrg <shnka...@gmail.com> wrote:
> suppose i need to use the file name which is currently present in buffer
> opened before me in emacs ..
>
> now suppose it is a .cpp file  say abc.cpp
>
> now to compile this file i have to use        ...\g++  abc.cpp
>
> now  instead for putting abc.cpp  is there a variable or command which
> substitutes itself as the file name in current buffer  when used ?
> --
> View this message in 
> context:http://www.nabble.com/subsitute-for-current-file-name-in-buffer-in-em...
> Sent from the Emacs - Help mailing list archive at Nabble.com.



reply via email to

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