all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Passing current buffer to compile command
@ 2011-01-16 19:12 duke
  2011-01-16 20:50 ` Peter Dyballa
                   ` (4 more replies)
  0 siblings, 5 replies; 22+ messages in thread
From: duke @ 2011-01-16 19:12 UTC (permalink / raw)
  To: help-gnu-emacs

How do I do that? I'm not using make, but another compiler. So I need
to pass a filename. Instead of inputing the filename, how do I pass
the current buffer file name? %f ?
--
duke


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

* Re: Passing current buffer to compile command
  2011-01-16 19:12 Passing current buffer to compile command duke
@ 2011-01-16 20:50 ` Peter Dyballa
  2011-01-16 21:12 ` Pascal J. Bourguignon
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 22+ messages in thread
From: Peter Dyballa @ 2011-01-16 20:50 UTC (permalink / raw)
  To: duke; +Cc: help-gnu-emacs


Am 16.01.2011 um 20:12 schrieb duke:

> How do I do that? I'm not using make, but another compiler. So I need
> to pass a filename. Instead of inputing the filename, how do I pass
> the current buffer file name? %f ?

I hope your file has a better name than %f! Have you tried to type M-x  
compile RET? Did you see text appear in the echo-area? Now, could you  
try to type SPACE (the character, not the word) in echo-area/mini- 
buffer and than the start of your file's real name (not its path  
name)? Does, when pressing TAB, the file name complete? If so, then  
just press RET! If not, then you have to type some more or make a  
choice at some time...

--
Greetings

   Pete

Imbecility, n.:
	A kind of divine inspiration, or sacred fire affecting censorious  
critics of this dictionary.
				– Ambrose Bierce: _The Devil's Dictionary_




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

* Re: Passing current buffer to compile command
  2011-01-16 19:12 Passing current buffer to compile command duke
  2011-01-16 20:50 ` Peter Dyballa
@ 2011-01-16 21:12 ` Pascal J. Bourguignon
       [not found] ` <mailman.12.1295211063.24679.help-gnu-emacs@gnu.org>
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 22+ messages in thread
From: Pascal J. Bourguignon @ 2011-01-16 21:12 UTC (permalink / raw)
  To: help-gnu-emacs

duke <sidney.reilley.ii@gmail.com> writes:

> How do I do that? 

That's not possible.  Buffers are not accessible from external commands.

You could render them accessible on some system.  For that, you would
have to write a virtual file system, mount it on your host, so that
external commands could open a virtual file whose content would be the
buffer contents.


> I'm not using make, but another compiler. So I need to pass a
> filename.  

Yes.   The problem is that buffers don't have file names.   Some buffers
have a file, and files have file names, but not all buffers have an
associated file, so you cannot do that, in general.


> Instead of inputing the filename, how do I pass
> the current buffer file name? %f ?

What file name?



Once you get a clearer picture in your mind, you may use M-x apropos RET
to find the function you need.


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
A bad day in () is better than a good day in {}.


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

* Re: Passing current buffer to compile command
       [not found] ` <mailman.12.1295211063.24679.help-gnu-emacs@gnu.org>
@ 2011-01-16 21:54   ` duke
  2011-01-16 22:53     ` Eli Zaretskii
                       ` (2 more replies)
  0 siblings, 3 replies; 22+ messages in thread
From: duke @ 2011-01-16 21:54 UTC (permalink / raw)
  To: help-gnu-emacs

On Jan 16, 1:50 pm, Peter Dyballa <Peter_Dyba...@Web.DE> wrote:
> Am 16.01.2011 um 20:12 schrieb duke:
>
> > How do I do that? I'm not using make, but another compiler. So I need
> > to pass a filename. Instead of inputing the filename, how do I pass
> > the current buffer file name? %f ?
>
> I hope your file has a better name than %f! Have you tried to type M-x  
> compile RET? Did you see text appear in the echo-area? Now, could you  
> try to type SPACE (the character, not the word) in echo-area/mini-
> buffer and than the start of your file's real name (not its path  
> name)? Does, when pressing TAB, the file name complete? If so, then  
> just press RET! If not, then you have to type some more or make a  
> choice at some time...

The buffer has been saved to a file.
I continue working on the code.
I want to re-compile
I do M-x compile  or goto the menu M-` t c
then I'm in the mini-buffer.
I enter my compiler name; I've always typed-in the filename currently
being edited.
I'm wondering if there's another to pass that filename to the mini-
buffer?
I realize that once I have a compiling history for the session, I can
navigate using the arrows, but it's that first time that I'm exploring.


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

* Re: Passing current buffer to compile command
  2011-01-16 19:12 Passing current buffer to compile command duke
                   ` (2 preceding siblings ...)
       [not found] ` <mailman.12.1295211063.24679.help-gnu-emacs@gnu.org>
@ 2011-01-16 21:58 ` despen
  2011-01-17  5:48   ` despen
  2011-01-17  3:29 ` rusi
  4 siblings, 1 reply; 22+ messages in thread
From: despen @ 2011-01-16 21:58 UTC (permalink / raw)
  To: help-gnu-emacs

duke <sidney.reilley.ii@gmail.com> writes:

> How do I do that? I'm not using make, but another compiler. So I need
> to pass a filename. Instead of inputing the filename, how do I pass
> the current buffer file name? %f ?

What does make have to do with the compiler?

Your best bet is to learn make, it will pay back dividends later.

But if you insist, one solution is to put a comment block at the end
of your file like this:

# Local Variables:
# compile-command: "mycompiler myfile"
# End:


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

* Re: Passing current buffer to compile command
  2011-01-16 21:54   ` duke
@ 2011-01-16 22:53     ` Eli Zaretskii
  2011-01-19  4:41       ` Kevin Rodgers
  2011-01-16 23:42     ` Peter Dyballa
       [not found]     ` <mailman.1.1295218445.29897.help-gnu-emacs@gnu.org>
  2 siblings, 1 reply; 22+ messages in thread
From: Eli Zaretskii @ 2011-01-16 22:53 UTC (permalink / raw)
  To: help-gnu-emacs

> From: duke <sidney.reilley.ii@gmail.com>
> Newsgroups: gnu.emacs.help
> Date: Sun, 16 Jan 2011 13:54:26 -0800 (PST)
> 
> I do M-x compile  or goto the menu M-` t c
> then I'm in the mini-buffer.
> I enter my compiler name; I've always typed-in the filename currently
> being edited.
> I'm wondering if there's another to pass that filename to the mini-
> buffer?

Customize the value of compile-command.  You can put it in the file's
local variables section for each file that you edit.

> I realize that once I have a compiling history for the session, I can
> navigate using the arrows, but it's that first time that I'm exploring.

Even better: use "M-x recompile" after the first time, it will reissue
the same command automatically.



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

* Re: Passing current buffer to compile command
  2011-01-16 21:54   ` duke
  2011-01-16 22:53     ` Eli Zaretskii
@ 2011-01-16 23:42     ` Peter Dyballa
       [not found]     ` <mailman.1.1295218445.29897.help-gnu-emacs@gnu.org>
  2 siblings, 0 replies; 22+ messages in thread
From: Peter Dyballa @ 2011-01-16 23:42 UTC (permalink / raw)
  To: duke; +Cc: help-gnu-emacs


Am 16.01.2011 um 22:54 schrieb duke:

> I realize that once I have a compiling history for the session, I can
> navigate using the arrows, but it's that first time that I'm  
> exploring.

Start one day (one hoer?) earlier.

Create an artificial session history.

Use session.el.

--
Greetings

   Pete

Build a man a fire and he'll be warm for a night, but set a man on  
fire and he'll be warm for the rest of his life.




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

* Re: Passing current buffer to compile command
       [not found]     ` <mailman.1.1295218445.29897.help-gnu-emacs@gnu.org>
@ 2011-01-17  1:29       ` duke
  2011-01-17 12:44         ` Eli Zaretskii
       [not found]         ` <mailman.2.1295268672.1793.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 22+ messages in thread
From: duke @ 2011-01-17  1:29 UTC (permalink / raw)
  To: help-gnu-emacs

On Jan 16, 3:53 pm, Eli Zaretskii <e...@gnu.org> wrote:
> > From: duke <sidney.reilley...@gmail.com>
> > Newsgroups: gnu.emacs.help
> > Date: Sun, 16 Jan 2011 13:54:26 -0800 (PST)
>
> > I do M-x compile  or goto the menu M-` t c
> > then I'm in the mini-buffer.
> > I enter my compiler name; I've always typed-in the filename currently
> > being edited.
> > I'm wondering if there's another to pass that filename to the mini-
> > buffer?
>
> Customize the value of compile-command.  You can put it in the file's
> local variables section for each file that you edit.

This is not Lisp, or even elisp that I'm coding in. Does that matter
with
respect to the "local variables" you mention above? I tried what was
suggested in another post concerning "local variables". Didn't work -
or I'm not doing it correctly. :)

> > I realize that once I have a compiling history for the session, I can
> > navigate using the arrows, but it's that first time that I'm exploring.
>
> Even better: use "M-x recompile" after the first time, it will reissue
> the same command automatically.

Excellent! Thanks ...


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

* Re: Passing current buffer to compile command
  2011-01-16 19:12 Passing current buffer to compile command duke
                   ` (3 preceding siblings ...)
  2011-01-16 21:58 ` despen
@ 2011-01-17  3:29 ` rusi
  2011-01-17  3:49   ` rusi
  4 siblings, 1 reply; 22+ messages in thread
From: rusi @ 2011-01-17  3:29 UTC (permalink / raw)
  To: help-gnu-emacs

On Jan 17, 12:12 am, duke <sidney.reilley...@gmail.com> wrote:
> How do I do that? I'm not using make, but another compiler. So I need
> to pass a filename. Instead of inputing the filename, how do I pass
> the current buffer file name? %f ?
> --
> duke

In vi '%' at the colon prompt gives the file name. (Like your %f)
The following will give that to you in the minibuffer
[But beware of using it with buffers that have no file associated)

(define-key minibuffer-local-map "%"
  (function
   (lambda ()
     (interactive)
     (insert (file-name-nondirectory
              (buffer-file-name
               (window-buffer (minibuffer-selected-window))))))))


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

* Re: Passing current buffer to compile command
  2011-01-17  3:29 ` rusi
@ 2011-01-17  3:49   ` rusi
  2011-01-17 19:07     ` duke
  2011-01-21  1:08     ` Drew Adams
  0 siblings, 2 replies; 22+ messages in thread
From: rusi @ 2011-01-17  3:49 UTC (permalink / raw)
  To: help-gnu-emacs

On Jan 17, 8:29 am, rusi <rustompm...@gmail.com> wrote:
> The following will give that to you in the minibuffer
> [But beware of using it with buffers that have no file associated)

Now "No-file" should not misbehave


(savehist-mode 1)
(define-key minibuffer-local-map "%"
  (function
   (lambda ()
     (interactive)
     (let ((file-path-maybe (buffer-file-name
			     (window-buffer (minibuffer-selected-window)))))
     (insert (if file-path-maybe
		 (file-name-nondirectory file-path-maybe)
	       "%"))))))


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

* Re: Passing current buffer to compile command
  2011-01-16 21:58 ` despen
@ 2011-01-17  5:48   ` despen
  2011-01-17 19:09     ` duke
  0 siblings, 1 reply; 22+ messages in thread
From: despen @ 2011-01-17  5:48 UTC (permalink / raw)
  To: help-gnu-emacs

despen@verizon.net writes:

> duke <sidney.reilley.ii@gmail.com> writes:
>
>> How do I do that? I'm not using make, but another compiler. So I need
>> to pass a filename. Instead of inputing the filename, how do I pass
>> the current buffer file name? %f ?
>
> What does make have to do with the compiler?
>
> Your best bet is to learn make, it will pay back dividends later.
>
> But if you insist, one solution is to put a comment block at the end
> of your file like this:
>
> # Local Variables:
> # compile-command: "mycompiler myfile"
> # End:

To activate above, save buffer to file, delete buffer, reload buffer.


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

* Re: Passing current buffer to compile command
  2011-01-17  1:29       ` duke
@ 2011-01-17 12:44         ` Eli Zaretskii
       [not found]         ` <mailman.2.1295268672.1793.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 22+ messages in thread
From: Eli Zaretskii @ 2011-01-17 12:44 UTC (permalink / raw)
  To: help-gnu-emacs

> From: duke <sidney.reilley.ii@gmail.com>
> Newsgroups: gnu.emacs.help
> Date: Sun, 16 Jan 2011 17:29:14 -0800 (PST)
> 
> > Customize the value of compile-command.  You can put it in the file's
> > local variables section for each file that you edit.
> 
> This is not Lisp, or even elisp that I'm coding in. Does that matter
> with
> respect to the "local variables" you mention above?

No.  Emacs will take notice of the file-local variables regardless of
the language used by the rest of the file.  See the node "File
Variables" in the Emacs manual for more details.

> I tried what was
> suggested in another post concerning "local variables". Didn't work -
> or I'm not doing it correctly. :)

Probably the latter.  The node in the manual mentioned above should
get you off the ground.



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

* Re: Passing current buffer to compile command
  2011-01-17  3:49   ` rusi
@ 2011-01-17 19:07     ` duke
  2011-01-18  3:42       ` rusi
  2011-01-21  1:08     ` Drew Adams
  1 sibling, 1 reply; 22+ messages in thread
From: duke @ 2011-01-17 19:07 UTC (permalink / raw)
  To: help-gnu-emacs

On Jan 16, 8:49 pm, rusi <rustompm...@gmail.com> wrote:
> On Jan 17, 8:29 am, rusi <rustompm...@gmail.com> wrote:
>
> > The following will give that to you in the minibuffer
> > [But beware of using it with buffers that have no file associated)
>
> Now "No-file" should not misbehave
>
> (savehist-mode 1)
> (define-key minibuffer-local-map "%"
>   (function
>    (lambda ()
>      (interactive)
>      (let ((file-path-maybe (buffer-file-name
>                              (window-buffer (minibuffer-selected-window)))))
>      (insert (if file-path-maybe
>                  (file-name-nondirectory file-path-maybe)
>                "%"))))))

You are too kind! Much obliged for the snippet, but especially the
courtesy. Can't wait to hack my .emacs and try it out :)


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

* Re: Passing current buffer to compile command
       [not found]         ` <mailman.2.1295268672.1793.help-gnu-emacs@gnu.org>
@ 2011-01-17 19:08           ` duke
  0 siblings, 0 replies; 22+ messages in thread
From: duke @ 2011-01-17 19:08 UTC (permalink / raw)
  To: help-gnu-emacs

On Jan 17, 5:44 am, Eli Zaretskii <e...@gnu.org> wrote:
> > From: duke <sidney.reilley...@gmail.com>
> > Newsgroups: gnu.emacs.help
> > Date: Sun, 16 Jan 2011 17:29:14 -0800 (PST)
>
> > > Customize the value of compile-command.  You can put it in the file's
> > > local variables section for each file that you edit.
>
> > This is not Lisp, or even elisp that I'm coding in. Does that matter
> > with
> > respect to the "local variables" you mention above?
>
> No.  Emacs will take notice of the file-local variables regardless of
> the language used by the rest of the file.  See the node "File
> Variables" in the Emacs manual for more details.
>
> > I tried what was
> > suggested in another post concerning "local variables". Didn't work -
> > or I'm not doing it correctly. :)
>
> Probably the latter.  The node in the manual mentioned above should
> get you off the ground.

Thanks for the pointer to the manual. next on my reading list


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

* Re: Passing current buffer to compile command
  2011-01-17  5:48   ` despen
@ 2011-01-17 19:09     ` duke
  0 siblings, 0 replies; 22+ messages in thread
From: duke @ 2011-01-17 19:09 UTC (permalink / raw)
  To: help-gnu-emacs

On Jan 16, 10:48 pm, des...@verizon.net wrote:
> des...@verizon.net writes:
> > duke <sidney.reilley...@gmail.com> writes:
>
> >> How do I do that? I'm not using make, but another compiler. So I need
> >> to pass a filename. Instead of inputing the filename, how do I pass
> >> the current buffer file name? %f ?
>
> > What does make have to do with the compiler?
>
> > Your best bet is to learn make, it will pay back dividends later.
>
> > But if you insist, one solution is to put a comment block at the end
> > of your file like this:
>
> > # Local Variables:
> > # compile-command: "mycompiler myfile"
> > # End:
>
> To activate above, save buffer to file, delete buffer, reload buffer.

Cool! thanks...


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

* Re: Passing current buffer to compile command
  2011-01-17 19:07     ` duke
@ 2011-01-18  3:42       ` rusi
  2011-01-18  4:05         ` rusi
  2011-01-18  5:14         ` duke
  0 siblings, 2 replies; 22+ messages in thread
From: rusi @ 2011-01-18  3:42 UTC (permalink / raw)
  To: help-gnu-emacs

On Jan 18, 12:07 am, duke <sidney.reilley...@gmail.com> wrote:
> On Jan 16, 8:49 pm, rusi <rustompm...@gmail.com> wrote:
>
>
>
> > On Jan 17, 8:29 am, rusi <rustompm...@gmail.com> wrote:
>
> > > The following will give that to you in the minibuffer
> > > [But beware of using it with buffers that have no file associated)
>
> > Now "No-file" should not misbehave
>
> > (savehist-mode 1)
> > (define-key minibuffer-local-map "%"
> >   (function
> >    (lambda ()
> >      (interactive)
> >      (let ((file-path-maybe (buffer-file-name
> >                              (window-buffer (minibuffer-selected-window)))))
> >      (insert (if file-path-maybe
> >                  (file-name-nondirectory file-path-maybe)
> >                "%"))))))
>
> You are too kind! Much obliged for the snippet, but especially the
> courtesy. Can't wait to hack my .emacs and try it out :)

I should attribute this to someone (who helped me write this) -- but
cant remember who :-)

More emacs-ish than vi-ish is to change the first line to
(define-key minibuffer-local-map (kbd "C-f")
;; analogous to C-x C-f

But then the last "%" is of course wrong and I dont know what to do
with it.
There should be a way of chaining back to the default binding of C-f
But (lookup-key minibuffer-local-map (kbd "C-f")) is giving nil --- So
dunno...


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

* Re: Passing current buffer to compile command
  2011-01-18  3:42       ` rusi
@ 2011-01-18  4:05         ` rusi
  2011-01-18 16:06           ` Le Wang
       [not found]           ` <mailman.0.1295366801.24998.help-gnu-emacs@gnu.org>
  2011-01-18  5:14         ` duke
  1 sibling, 2 replies; 22+ messages in thread
From: rusi @ 2011-01-18  4:05 UTC (permalink / raw)
  To: help-gnu-emacs

On Jan 18, 8:42 am, rusi <rustompm...@gmail.com> wrote:
> On Jan 18, 12:07 am, duke <sidney.reilley...@gmail.com> wrote:
: snipped
>
> > You are too kind! Much obliged for the snippet, but especially the
> > courtesy. Can't wait to hack my .emacs and try it out :)
>
> I should attribute this to someone (who helped me write this) -- but
> cant remember who :-)


Found the original thread http://lists.gnu.org/archive/html/help-gnu-emacs/2008-08/msg00433.html


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

* Re: Passing current buffer to compile command
  2011-01-18  3:42       ` rusi
  2011-01-18  4:05         ` rusi
@ 2011-01-18  5:14         ` duke
  1 sibling, 0 replies; 22+ messages in thread
From: duke @ 2011-01-18  5:14 UTC (permalink / raw)
  To: help-gnu-emacs

On Jan 17, 8:42 pm, rusi <rustompm...@gmail.com> wrote:
> On Jan 18, 12:07 am, duke <sidney.reilley...@gmail.com> wrote:
>
>
>
> > On Jan 16, 8:49 pm, rusi <rustompm...@gmail.com> wrote:
>
> > > On Jan 17, 8:29 am, rusi <rustompm...@gmail.com> wrote:
>
> > > > The following will give that to you in the minibuffer
> > > > [But beware of using it with buffers that have no file associated)
>
> > > Now "No-file" should not misbehave
>
> > > (savehist-mode 1)
> > > (define-key minibuffer-local-map "%"
> > >   (function
> > >    (lambda ()
> > >      (interactive)
> > >      (let ((file-path-maybe (buffer-file-name
> > >                              (window-buffer (minibuffer-selected-window)))))
> > >      (insert (if file-path-maybe
> > >                  (file-name-nondirectory file-path-maybe)
> > >                "%"))))))
>
> > You are too kind! Much obliged for the snippet, but especially the
> > courtesy. Can't wait to hack my .emacs and try it out :)
>
> I should attribute this to someone (who helped me write this) -- but
> cant remember who :-)
>
> More emacs-ish than vi-ish is to change the first line to
> (define-key minibuffer-local-map (kbd "C-f")
> ;; analogous to C-x C-f
>
> But then the last "%" is of course wrong and I dont know what to do
> with it.
> There should be a way of chaining back to the default binding of C-f
> But (lookup-key minibuffer-local-map (kbd "C-f")) is giving nil --- So
> dunno...

Don't worry about it. The snippet works great "as is". I'll bet that
the  "gurus"
have scooped this one up.  :) Thanks again.


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

* Re: Passing current buffer to compile command
  2011-01-18  4:05         ` rusi
@ 2011-01-18 16:06           ` Le Wang
       [not found]           ` <mailman.0.1295366801.24998.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 22+ messages in thread
From: Le Wang @ 2011-01-18 16:06 UTC (permalink / raw)
  To: rusi; +Cc: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 1053 bytes --]

For completeness, I'll present the yasnippet solution here, it should be
saved under the "fundamental-mode" subdir of the snippets folder.  This
expansion key works in any buffer, including the minibuffer:

# -*- mode: snippet -*-
# name: buffer-file-name-nondir
# key: %
# --
`(let ((fname (file-name-nondirectory
                (or (buffer-file-name (window-buffer
(minibuffer-selected-window)))
                    ""))))
   (if (zerop (length fname))
       "%"
     fname))`$0


On Tue, Jan 18, 2011 at 12:05 PM, rusi <rustompmody@gmail.com> wrote:

> On Jan 18, 8:42 am, rusi <rustompm...@gmail.com> wrote:
> > On Jan 18, 12:07 am, duke <sidney.reilley...@gmail.com> wrote:
> : snipped
> >
> > > You are too kind! Much obliged for the snippet, but especially the
> > > courtesy. Can't wait to hack my .emacs and try it out :)
> >
> > I should attribute this to someone (who helped me write this) -- but
> > cant remember who :-)
>
>
> Found the original thread
> http://lists.gnu.org/archive/html/help-gnu-emacs/2008-08/msg00433.html
>



-- 
Le

[-- Attachment #2: Type: text/html, Size: 2013 bytes --]

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

* Re: Passing current buffer to compile command
  2011-01-16 22:53     ` Eli Zaretskii
@ 2011-01-19  4:41       ` Kevin Rodgers
  0 siblings, 0 replies; 22+ messages in thread
From: Kevin Rodgers @ 2011-01-19  4:41 UTC (permalink / raw)
  To: help-gnu-emacs

On 1/16/11 3:53 PM, Eli Zaretskii wrote:
>> From: duke<sidney.reilley.ii@gmail.com>
>> Newsgroups: gnu.emacs.help
>> Date: Sun, 16 Jan 2011 13:54:26 -0800 (PST)
>>
>> I do M-x compile  or goto the menu M-` t c
>> then I'm in the mini-buffer.
>> I enter my compiler name; I've always typed-in the filename currently
>> being edited.
>> I'm wondering if there's another to pass that filename to the mini-
>> buffer?
>
> Customize the value of compile-command.  You can put it in the file's
> local variables section for each file that you edit.

Or set compile-command in a mode hook, as suggested in compile-command's
own doc string.

-- 
Kevin Rodgers
Denver, Colorado, USA




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

* Re: Passing current buffer to compile command
       [not found]           ` <mailman.0.1295366801.24998.help-gnu-emacs@gnu.org>
@ 2011-01-19 20:12             ` duke
  0 siblings, 0 replies; 22+ messages in thread
From: duke @ 2011-01-19 20:12 UTC (permalink / raw)
  To: help-gnu-emacs

On Jan 18, 9:06 am, Le Wang <l26w...@gmail.com> wrote:
> For completeness, I'll present the yasnippet solution here, it should be
> saved under the "fundamental-mode" subdir of the snippets folder.  This
> expansion key works in any buffer, including the minibuffer:
>
> # -*- mode: snippet -*-
> # name: buffer-file-name-nondir
> # key: %
> # --
> `(let ((fname (file-name-nondirectory
>                 (or (buffer-file-name (window-buffer
> (minibuffer-selected-window)))
>                     ""))))
>    (if (zerop (length fname))
>        "%"
>      fname))`$0
>
> On Tue, Jan 18, 2011 at 12:05 PM, rusi <rustompm...@gmail.com> wrote:
> > On Jan 18, 8:42 am, rusi <rustompm...@gmail.com> wrote:
> > > On Jan 18, 12:07 am, duke <sidney.reilley...@gmail.com> wrote:
> > : snipped
>
> > > > You are too kind! Much obliged for the snippet, but especially the
> > > > courtesy. Can't wait to hack my .emacs and try it out :)
>
> > > I should attribute this to someone (who helped me write this) -- but
> > > cant remember who :-)
>
> > Found the original thread
> >http://lists.gnu.org/archive/html/help-gnu-emacs/2008-08/msg00433.html
>
> --
> Le

Another useful option! Thanks.


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

* RE: Passing current buffer to compile command
  2011-01-17  3:49   ` rusi
  2011-01-17 19:07     ` duke
@ 2011-01-21  1:08     ` Drew Adams
  1 sibling, 0 replies; 22+ messages in thread
From: Drew Adams @ 2011-01-21  1:08 UTC (permalink / raw)
  To: 'rusi', l26wang, help-gnu-emacs

Rustom, Le, and others have provided precise solutions for this.

FWIW, here is some additional info that can be of general help, but as such is
nowhere near as convenient as a specific, dedicated command such as those
suggested.  Just a few general tools that can sometimes be handy.


1. At the heart of the solutions the others have provided is this Lisp sexp:

(buffer-file-name (window-buffer (minibuffer-selected-window)))

It returns the name of the file associated with the buffer selected before the
minibuffer was activated, as follows:

* `minibuffer-selected-window' (probably not a great name for what it does)
returns the window that was selected before activating the minibuffer.
`window-buffer' then returns that window's buffer.

* `buffer-file-name' returns the name of the file that its buffer arg is
visiting (or nil if not visiting a file).

If you happen to know these Lisp functions then you could evaluate this long
sexp yourself and insert the result in the minibuffer.  No, it's not convenient
to do this kind of thing, but it can be made a little more convenient and more
useful.


2. You can do this while in the minibuffer.  `M-:' prompts for a Lisp sexp to
evaluate, and you can use `M-:' from the minibuffer provided
`enable-recursive-minibuffers' is non-nil.

In Icicles: `M-:' in the minibuffer automatically binds
`enable-recursive-minibuffers' to non-nil.  With a prefix arg, `M-:' inserts the
result of the evaluation into the minibuffer.  With a negative prefix arg (e.g.
`M-') it removes the double-quotes from a string value.

So, for example, to insert the buffer's file name you could do the following
whenever you are in the minibuffer (regardless of the context: `M-x', `C-x C-f',
etc.):

M- M-: (buffer-file-name
        (window-buffer (minibuffer-selected-window)))

If you were in buffer `foo.c' before activating the minibuffer, then the text
`foo.c' (without quotes) would be inserted in the minibuffer at point.  This is
equivalent, BTW:

M- M-: (buffer-file-name icicle-pre-minibuffer-buffer)

This insertion does not change any other text already in the minibuffer.  You
can use `M- M-:' as many times as you like, to insert the values of multiple
Lisp sexps.


3. That's a long sexp to type just to get the current file name.  But 
you can save it and reuse it.  Assign it as a string value to a variable or a
register, then insert the value quickly whenever you want.  `C-=' inserts the
value from a variable.  `C-x r i' inserts it from a register.

You would then type just `M- M-: C-=' to insert what you need.  Not as useful as
a dedicated command, obviously, but maybe good to know.

http://www.emacswiki.org/emacs/Icicles_-_Inserting_a_Regexp_from_a_Variable_or_R
egister.


---

Off-topic but related:

* You can use `C-M-F' (i.e., `C-M-S-f') in any minibuffer to insert one or more
file names on demand, using completion.

* You can use `M-.' in the minibuffer to grab various things at or near point
and insert them into the minibuffer.  When grabbing a sexp you can use a prefix
arg to eval it and insert the result instead.

http://www.emacswiki.org/emacs/Icicles_-_Inserting_Text_from_Cursor




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

end of thread, other threads:[~2011-01-21  1:08 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-01-16 19:12 Passing current buffer to compile command duke
2011-01-16 20:50 ` Peter Dyballa
2011-01-16 21:12 ` Pascal J. Bourguignon
     [not found] ` <mailman.12.1295211063.24679.help-gnu-emacs@gnu.org>
2011-01-16 21:54   ` duke
2011-01-16 22:53     ` Eli Zaretskii
2011-01-19  4:41       ` Kevin Rodgers
2011-01-16 23:42     ` Peter Dyballa
     [not found]     ` <mailman.1.1295218445.29897.help-gnu-emacs@gnu.org>
2011-01-17  1:29       ` duke
2011-01-17 12:44         ` Eli Zaretskii
     [not found]         ` <mailman.2.1295268672.1793.help-gnu-emacs@gnu.org>
2011-01-17 19:08           ` duke
2011-01-16 21:58 ` despen
2011-01-17  5:48   ` despen
2011-01-17 19:09     ` duke
2011-01-17  3:29 ` rusi
2011-01-17  3:49   ` rusi
2011-01-17 19:07     ` duke
2011-01-18  3:42       ` rusi
2011-01-18  4:05         ` rusi
2011-01-18 16:06           ` Le Wang
     [not found]           ` <mailman.0.1295366801.24998.help-gnu-emacs@gnu.org>
2011-01-19 20:12             ` duke
2011-01-18  5:14         ` duke
2011-01-21  1:08     ` Drew Adams

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.