* subsitute for current file name in buffer in emacs
@ 2008-01-26 16:03 shankarrg
2008-01-26 16:29 ` Drew Adams
2008-01-31 5:35 ` Kevin Rodgers
0 siblings, 2 replies; 7+ messages in thread
From: shankarrg @ 2008-01-26 16:03 UTC (permalink / raw)
To: Help-gnu-emacs
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-emacs-tp15109271p15109271.html
Sent from the Emacs - Help mailing list archive at Nabble.com.
^ permalink raw reply [flat|nested] 7+ messages in thread
[parent not found: <mailman.6569.1201363445.18990.help-gnu-emacs@gnu.org>]
* Re: subsitute for current file name in buffer in emacs
[not found] <mailman.6569.1201363445.18990.help-gnu-emacs@gnu.org>
@ 2008-01-26 16:20 ` Exal de Jesus Garcia Carrillo
2008-01-26 16:58 ` Drew Adams
2008-01-26 23:30 ` Xah Lee
2008-02-04 20:58 ` Ken Goldman
2 siblings, 1 reply; 7+ messages in thread
From: Exal de Jesus Garcia Carrillo @ 2008-01-26 16:20 UTC (permalink / raw)
To: help-gnu-emacs
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
shankarrg em gnu.emacs.help escreveu :
> now instead for putting abc.cpp is there a variable or command which
> substitutes itself as the file name in current buffer when used ?
Try evaluating this:
(file-name-nondirectory (buffer-file-name))
- --
Spam protection:
In my e-mail replace the words `no-spam' with `exal'.
.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.8+ <http://mailcrypt.sourceforge.net/>
iD8DBQFHm13NoZmxoVJRtGIRArPdAJ4+PJXges1hBs2RPzarJqtQu4LsDACfYExL
cnh4X5+6XtPEGxa7JsJqviQ=
=scUE
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: subsitute for current file name in buffer in emacs
2008-01-26 16:20 ` Exal de Jesus Garcia Carrillo
@ 2008-01-26 16:58 ` Drew Adams
0 siblings, 0 replies; 7+ messages in thread
From: Drew Adams @ 2008-01-26 16:58 UTC (permalink / raw)
To: Exal de Jesus Garcia Carrillo, help-gnu-emacs
> > now instead for putting abc.cpp is there a variable or command which
> > substitutes itself as the file name in current buffer when used ?
>
> Try evaluating this:
> (file-name-nondirectory (buffer-file-name))
Sorry, I misread the question. Yes, `buffer-file-name' is what you want, if
you want the name of the current buffer's file.
I mistakenly thought you wanted to use a file name that is text in some
buffer.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: subsitute for current file name in buffer in emacs
[not found] <mailman.6569.1201363445.18990.help-gnu-emacs@gnu.org>
2008-01-26 16:20 ` Exal de Jesus Garcia Carrillo
@ 2008-01-26 23:30 ` Xah Lee
2008-02-04 20:58 ` Ken Goldman
2 siblings, 0 replies; 7+ messages in thread
From: Xah Lee @ 2008-01-26 23:30 UTC (permalink / raw)
To: help-gnu-emacs
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.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: subsitute for current file name in buffer in emacs
[not found] <mailman.6569.1201363445.18990.help-gnu-emacs@gnu.org>
2008-01-26 16:20 ` Exal de Jesus Garcia Carrillo
2008-01-26 23:30 ` Xah Lee
@ 2008-02-04 20:58 ` Ken Goldman
2 siblings, 0 replies; 7+ messages in thread
From: Ken Goldman @ 2008-02-04 20:58 UTC (permalink / raw)
To: help-gnu-emacs
I'm sure there is. But if you're doing serious programming, you should
invest in learning 'make'.
shankarrg 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 ?
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2008-02-04 20:58 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-01-26 16:03 subsitute for current file name in buffer in emacs shankarrg
2008-01-26 16:29 ` Drew Adams
2008-01-31 5:35 ` Kevin Rodgers
[not found] <mailman.6569.1201363445.18990.help-gnu-emacs@gnu.org>
2008-01-26 16:20 ` Exal de Jesus Garcia Carrillo
2008-01-26 16:58 ` Drew Adams
2008-01-26 23:30 ` Xah Lee
2008-02-04 20:58 ` Ken Goldman
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.