unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* 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

* 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:03 shankarrg
@ 2008-01-26 16:29 ` Drew Adams
  2008-01-31  5:35 ` Kevin Rodgers
  1 sibling, 0 replies; 7+ messages in thread
From: Drew Adams @ 2008-01-26 16:29 UTC (permalink / raw)
  To: shankarrg, 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 ?

ffap.el is one way (but some people find it overbearing).

http://www.emacswiki.org/cgi-bin/wiki/FindFileAtPoint

If you use Icicles, you can always use `M-.' to yank the file name (or
whatever) that is under the cursor into the minibuffer.

http://www.emacswiki.org/cgi-bin/wiki/Icicles_-_Inserting_Text_from_Cursor

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

* RE: subsitute for current file name in buffer in emacs
  2008-01-26 16:20 ` subsitute for current file name in buffer in emacs 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 ` subsitute for current file name in buffer in emacs 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
  2008-01-26 16:03 shankarrg
  2008-01-26 16:29 ` Drew Adams
@ 2008-01-31  5:35 ` Kevin Rodgers
  1 sibling, 0 replies; 7+ messages in thread
From: Kevin Rodgers @ 2008-01-31  5:35 UTC (permalink / raw)
  To: help-gnu-emacs

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 ? 

Even better, perhaps:

(add-hook 'find-file-hook
	  (lambda ()
	    (when (string-match "\\.cpp\\'" buffer-file-name)
	      (set (make-local-variable 'compile-command)
		   (format "g++ %s"
			   (file-name-nondirectory buffer-file-name))))))

-- 
Kevin Rodgers
Denver, Colorado, USA





^ 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 ` subsitute for current file name in buffer in emacs 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 --
     [not found] <mailman.6569.1201363445.18990.help-gnu-emacs@gnu.org>
2008-01-26 16:20 ` subsitute for current file name in buffer in emacs 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
2008-01-26 16:03 shankarrg
2008-01-26 16:29 ` Drew Adams
2008-01-31  5:35 ` Kevin Rodgers

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