unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* emacs C question
@ 2003-09-24 19:00 John Russell
  2003-09-25  2:30 ` Pascal Bourguignon
  0 siblings, 1 reply; 11+ messages in thread
From: John Russell @ 2003-09-24 19:00 UTC (permalink / raw)


I'm not sure if this is the right group for this.  I am picking
around the emacs C source.  How can I make emacs open a file from the
internal C code.  e.g. write a function in emacs/src/buffer.c that opens a
specific file.  Any ideas?  Thanks

John  

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

* Re: emacs C question
  2003-09-24 19:00 emacs C question John Russell
@ 2003-09-25  2:30 ` Pascal Bourguignon
  2003-09-25 12:51   ` John Russell
  0 siblings, 1 reply; 11+ messages in thread
From: Pascal Bourguignon @ 2003-09-25  2:30 UTC (permalink / raw)


John Russell <jorussel@cisco.com> writes:

> I'm not sure if this is the right group for this.  I am picking
> around the emacs C source.  How can I make emacs open a file from the
> internal C code.  e.g. write a function in emacs/src/buffer.c that opens a
> specific file.  Any ideas?  Thanks
> 
> John  

Why would anyone want to do that?

You can much more easily open a file with (find-file path).
There are a lot of initialization (lisp) files where to put such a command.

Otherwise, obviously, you could call Ffind_file from C.

-- 
__Pascal_Bourguignon__
http://www.informatimago.com/
Do not adjust your mind, there is a fault in reality.

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

* Re: emacs C question
  2003-09-25  2:30 ` Pascal Bourguignon
@ 2003-09-25 12:51   ` John Russell
  2003-09-25 18:35     ` Stefan Monnier
                       ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: John Russell @ 2003-09-25 12:51 UTC (permalink / raw)


Pascal Bourguignon <spam@thalassa.informatimago.com> writes:

> John Russell <jorussel@cisco.com> writes:
> 
> > I'm not sure if this is the right group for this.  I am picking
> > around the emacs C source.  How can I make emacs open a file from the
> > internal C code.  e.g. write a function in emacs/src/buffer.c that opens a
> > specific file.  Any ideas?  Thanks
> > 
> > John  
> 
> Why would anyone want to do that?
> 

Because I'm trying to implement drag and drop for gtk emacs.  I have
gotten the dragging and dropping to work, but now I have to put some
meat in the function that gets called.  I'm new to emacs' inner
workings and am a little lost.  

> You can much more easily open a file with (find-file path).
> There are a lot of initialization (lisp) files where to put such a command.
> 
> Otherwise, obviously, you could call Ffind_file from C.
> 

Excellent, I'll check it out.

John

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

* Re: emacs C question
  2003-09-25 12:51   ` John Russell
@ 2003-09-25 18:35     ` Stefan Monnier
  2003-09-25 18:37     ` Stefan Monnier
  2003-09-25 19:07     ` Jason Rumney
  2 siblings, 0 replies; 11+ messages in thread
From: Stefan Monnier @ 2003-09-25 18:35 UTC (permalink / raw)


>> > I'm not sure if this is the right group for this.  I am picking
>> > around the emacs C source.  How can I make emacs open a file from the
>> > internal C code.  e.g. write a function in emacs/src/buffer.c that opens a
>> > specific file.  Any ideas?  Thanks
>> > 
>> > John  
>> 
>> Why would anyone want to do that?

> Because I'm trying to implement drag and drop for gtk emacs.  I have

Cool.  Please send your patch to emacs-devel@gnu.org so people can give you
feedback (as you might have noticed, there is a fair bit of convention in
the C code, and since you're not familiar with it, you probably missed some
of it).

> gotten the dragging and dropping to work, but now I have to put some
> meat in the function that gets called.  I'm new to emacs' inner
> workings and am a little lost.

Rather than hard-code `find-file', you should make it customizable
in elisp.  Maybe it's worthwhile to look at how drag&drop is handled in the
W32 part of the code.  The two should hopefully provide a similar
functionality to elisp so that the rest of the code can be the same for
all OSes.


        Stefan

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

* Re: emacs C question
  2003-09-25 12:51   ` John Russell
  2003-09-25 18:35     ` Stefan Monnier
@ 2003-09-25 18:37     ` Stefan Monnier
  2003-09-25 20:41       ` John Russell
  2003-09-25 19:07     ` Jason Rumney
  2 siblings, 1 reply; 11+ messages in thread
From: Stefan Monnier @ 2003-09-25 18:37 UTC (permalink / raw)


>> Otherwise, obviously, you could call Ffind_file from C.

There's no such function because it's defined in elisp, not in C.
But you can do

    call1 (intern ("find-file-other-window"), file);


-- Stefan

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

* Re: emacs C question
  2003-09-25 12:51   ` John Russell
  2003-09-25 18:35     ` Stefan Monnier
  2003-09-25 18:37     ` Stefan Monnier
@ 2003-09-25 19:07     ` Jason Rumney
  2003-09-25 20:42       ` John Russell
  2 siblings, 1 reply; 11+ messages in thread
From: Jason Rumney @ 2003-09-25 19:07 UTC (permalink / raw)


John Russell <jorussel@cisco.com> writes:

> Pascal Bourguignon <spam@thalassa.informatimago.com> writes:
> 
> > John Russell <jorussel@cisco.com> writes:
> > 
> > > I'm not sure if this is the right group for this.  I am picking
> > > around the emacs C source.  How can I make emacs open a file from the
> > > internal C code.  e.g. write a function in emacs/src/buffer.c
> > > that opens a specific file.  Any ideas?  Thanks
> 
> Because I'm trying to implement drag and drop for gtk emacs.

It would be better to make drag and drop generate an event, which can
then be bound to any lisp function the user wants (that accepts a
filename). The Windows implementation works like this (although there
is a special function that it is bound to, so maybe it could do with
some work to generalize it).

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

* Re: emacs C question
  2003-09-25 18:37     ` Stefan Monnier
@ 2003-09-25 20:41       ` John Russell
  2003-09-25 21:19         ` Jason Rumney
  2003-09-25 21:36         ` Stefan Monnier
  0 siblings, 2 replies; 11+ messages in thread
From: John Russell @ 2003-09-25 20:41 UTC (permalink / raw)


Stefan Monnier <monnier@iro.umontreal.ca> writes:

> >> Otherwise, obviously, you could call Ffind_file from C.
> 
> There's no such function because it's defined in elisp, not in C.
> But you can do
> 
>     call1 (intern ("find-file-other-window"), file);
> 
> 
> -- Stefan

Ok, this is my first time in the emacs C code and I'm relatively new
to C so please be patient.  

1) Why does this function cause emacs to immediately close with 

Fatal error (6).Aborted

2) While developing, how can I make emacs be more helpful with its
   dying breath.



This is a handler for gtk drag and drop so the args aren't important
yet.  Just the three lines in it cause the crash ( i think).

static void 
jjr_drag_data_received_handler (GtkWidget *widget, GdkDragContext *context, 
		                      gint x, gint y, GtkSelectionData *selection_data, 
				      guint info, guint time)
{
    Lisp_Object filename;

    filename = build_string ("~/.bashrc");

    Fswitch_to_buffer(filename,Qnil);

}

Thanks for the help

John

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

* Re: emacs C question
  2003-09-25 19:07     ` Jason Rumney
@ 2003-09-25 20:42       ` John Russell
  2003-09-25 21:16         ` Jason Rumney
  0 siblings, 1 reply; 11+ messages in thread
From: John Russell @ 2003-09-25 20:42 UTC (permalink / raw)


jasonr (Jason Rumney) @  f2s.com writes:

> John Russell <jorussel@cisco.com> writes:
> 
> > Pascal Bourguignon <spam@thalassa.informatimago.com> writes:
> > 
> > > John Russell <jorussel@cisco.com> writes:
> > > 
> > > > I'm not sure if this is the right group for this.  I am picking
> > > > around the emacs C source.  How can I make emacs open a file from the
> > > > internal C code.  e.g. write a function in emacs/src/buffer.c
> > > > that opens a specific file.  Any ideas?  Thanks
> > 
> > Because I'm trying to implement drag and drop for gtk emacs.
> 
> It would be better to make drag and drop generate an event, which can
> then be bound to any lisp function the user wants (that accepts a
> filename). The Windows implementation works like this (although there
> is a special function that it is bound to, so maybe it could do with
> some work to generalize it).

How does one "bind" something to an event?  Like I keep saying, I'm
new in the emacs C code.  Thanks for the suggestoin.

John

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

* Re: emacs C question
  2003-09-25 20:42       ` John Russell
@ 2003-09-25 21:16         ` Jason Rumney
  0 siblings, 0 replies; 11+ messages in thread
From: Jason Rumney @ 2003-09-25 21:16 UTC (permalink / raw)


John Russell <jorussel@cisco.com> writes:

> How does one "bind" something to an event?

With define-key. There is already a drag-n-drop event defined
globally (though only Windows and Mac generate it currently AFAIK),
so all you need to do is construct the (Emacs) event when you
receive a GTK drop event. See construct_drag_n_drop in w32term.c for
example.

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

* Re: emacs C question
  2003-09-25 20:41       ` John Russell
@ 2003-09-25 21:19         ` Jason Rumney
  2003-09-25 21:36         ` Stefan Monnier
  1 sibling, 0 replies; 11+ messages in thread
From: Jason Rumney @ 2003-09-25 21:19 UTC (permalink / raw)


John Russell <jorussel@cisco.com> writes:

> Ok, this is my first time in the emacs C code and I'm relatively new
> to C so please be patient.  
> 
> 1) Why does this function cause emacs to immediately close with 
> 
> Fatal error (6).Aborted

You are probably calling it from an asynchronous signal handler. The
Lisp engine cannot be called this way, generate an event instead and
let Lisp handle it in its normal loop.

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

* Re: emacs C question
  2003-09-25 20:41       ` John Russell
  2003-09-25 21:19         ` Jason Rumney
@ 2003-09-25 21:36         ` Stefan Monnier
  1 sibling, 0 replies; 11+ messages in thread
From: Stefan Monnier @ 2003-09-25 21:36 UTC (permalink / raw)


> 2) While developing, how can I make emacs be more helpful with its
>    dying breath.

Run inside GDB (and from inside the emacs/src directory so GDB reads the
emacs/src/.gdbinit file.  See etc/DEBUG).


        Stefan

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

end of thread, other threads:[~2003-09-25 21:36 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-09-24 19:00 emacs C question John Russell
2003-09-25  2:30 ` Pascal Bourguignon
2003-09-25 12:51   ` John Russell
2003-09-25 18:35     ` Stefan Monnier
2003-09-25 18:37     ` Stefan Monnier
2003-09-25 20:41       ` John Russell
2003-09-25 21:19         ` Jason Rumney
2003-09-25 21:36         ` Stefan Monnier
2003-09-25 19:07     ` Jason Rumney
2003-09-25 20:42       ` John Russell
2003-09-25 21:16         ` Jason Rumney

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