From: Ryan Schram
Subject: How to write an Emacs Lisp library
Date: 
Message-ID: <1b25eec7.0208161143.7b6841c5@posting.google.com>
I got so many useful responses to my query about data structures that
I thought that I could post this here, even if it is slightly OT.

Thanks to the help of many on CLL, the program I was working on works.
It is not beautiful, but it works.

The next problem has to do with making the code available to Emacs.
There is one main defun I want to autoload. It consists of several
defuns defined in the main source file. I get an error when I load the
function and attempt to execute it. I don't get this error in
evaluating the function in the buffer when working on the main source
file.

This seems like a simple problem. But I haven't been able to find any
guidance in manuals and tutorials on writing functions that will
autoload well. Nothing I've read goes far beyond the syntax reference
entry for autoload. Everything says that you should export/autoload
only the functions one wants to use. It doesn't explain how to write
code that will cooperate with the autoload function. I mean that I
have a feeling that my whole design of my program is incorrect and
hence, my attempt to follow the standard example of using autoload
failed.

Are there any good tutorials for writing Emacs libraries? I am
familiar with the Glickstein book (O'Reilly) - few generic approaches
are described in it. The case-study approach fails for me. I don't see
why the examples are different from my program, so I odn't understand
why they work and mine don't. I think a good introduction to writing
clean programs could help me avoid this kind of error.

Furthermore, I want to raise a point for discussion. There seems to be
very little online documentation for Lisp, especially Emacs Lisp.
There is of course the standard language reference manuals. These are
tersely written and lack helpful examples. They often require a lot of
knowledge about other parts of the language, not necessarily more
basic, just to understand an entry for a single function.

Thanks, 
Ryan

From: Barry Margolin
Subject: Re: How to write an Emacs Lisp library
Date: 
Message-ID: <gIc79.27$%k.5033@paloalto-snr1.gtei.net>
In article <····························@posting.google.com>,
Ryan Schram <······@ryanschram.com> wrote:
>I got so many useful responses to my query about data structures that
>I thought that I could post this here, even if it is slightly OT.

It would really be better to ask questions that are specific to Emacs in an
Emacs newsgroup, either comp.emacs or gnu.emacs.help.

>Thanks to the help of many on CLL, the program I was working on works.
>It is not beautiful, but it works.
>
>The next problem has to do with making the code available to Emacs.
>There is one main defun I want to autoload. It consists of several
>defuns defined in the main source file. I get an error when I load the
>function and attempt to execute it. I don't get this error in
>evaluating the function in the buffer when working on the main source
>file.

What error do you get?

>This seems like a simple problem. But I haven't been able to find any
>guidance in manuals and tutorials on writing functions that will
>autoload well. Nothing I've read goes far beyond the syntax reference
>entry for autoload. Everything says that you should export/autoload
>only the functions one wants to use. It doesn't explain how to write
>code that will cooperate with the autoload function. I mean that I
>have a feeling that my whole design of my program is incorrect and
>hence, my attempt to follow the standard example of using autoload
>failed.

The only things you need to autoload are the functions that a user is
supposed to call.  When they call that function, Emacs will load the file,
and all the auxiliary functions will get loaded in along with it.

>Are there any good tutorials for writing Emacs libraries? I am
>familiar with the Glickstein book (O'Reilly) - few generic approaches
>are described in it. The case-study approach fails for me. I don't see
>why the examples are different from my program, so I odn't understand
>why they work and mine don't. I think a good introduction to writing
>clean programs could help me avoid this kind of error.

If you posted your code to an Emacs group, I'll bet someone will spot the
problem.

Do you have (provide '<yourlibname>) at the end of your file?

-- 
Barry Margolin, ······@genuity.net
Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
From: Oliver Scholz
Subject: Re: How to write an Emacs Lisp library
Date: 
Message-ID: <m3vg6a5vbr.fsf@ID-87814.user.dfncis.de>
······@ryanschram.com (Ryan Schram) writes:

> I got so many useful responses to my query about data structures that
> I thought that I could post this here, even if it is slightly OT.

I think you are better off with a question so specific to Emacs as
this one in one of the Emacs newsgroups:

gnu.emacs.help -- for GNU Emacs
comp.emacs.xemacs -- for XEmacs
comp.emacs -- for both

I cross-posted this and set a follow-up to comp.emacs.

[...]
> The next problem has to do with making the code available to Emacs.
> There is one main defun I want to autoload. It consists of several
> defuns defined in the main source file. I get an error when I load the
> function and attempt to execute it. I don't get this error in
> evaluating the function in the buffer when working on the main source
> file.

I am afraid, you have to be a bit more specific about what you are
trying to do.

[What says the error-message, what is the autoload-definition, what
version and what flavour of Emacs are you using ...? Is your file per
chance not in a directory listed in the variable `load-path'?]

[...]
> Are there any good tutorials for writing Emacs libraries? I am
> familiar with the Glickstein book (O'Reilly) - few generic approaches
> are described in it. The case-study approach fails for me. I don't see
> why the examples are different from my program, so I odn't understand
> why they work and mine don't. I think a good introduction to writing
> clean programs could help me avoid this kind of error.
>
> Furthermore, I want to raise a point for discussion. There seems to be
> very little online documentation for Lisp, especially Emacs Lisp.
> There is of course the standard language reference manuals. These are
> tersely written and lack helpful examples. They often require a lot of
> knowledge about other parts of the language, not necessarily more
> basic, just to understand an entry for a single function.
[...]

There is the IMO very good "Introduction to Emacs Lisp":

ftp://ftp.gnu.org/pub/gnu/emacs/emacs-lisp-intro-2.04.tar.gz

Furthermore you have LOTS of documentation at hand with the commands:

`C-h f' (`describe-function')
`C-h v' (`describe-variable')

    -- Oliver

-- 
29 Thermidor an 210 de la R�volution
Libert�, Egalit�, Fraternit�!
From: Pascal Bourguignon
Subject: Re: How to write an Emacs Lisp library
Date: 
Message-ID: <87bs82z12z.fsf@thalassa.informatimago.com>
······@ryanschram.com (Ryan Schram) writes:

> I got so many useful responses to my query about data structures that
> I thought that I could post this here, even if it is slightly OT.
> 
> Thanks to the help of many on CLL, the program I was working on works.
> It is not beautiful, but it works.
> 
> The next problem has to do with making the code available to Emacs.
> There is one main defun I want to autoload. It consists of several
> defuns defined in the main source file. I get an error when I load the
> function and attempt to execute it. I don't get this error in
> evaluating the function in the buffer when working on the main source
> file.

You should ask in gnu.emacs.help
 
> This seems like a simple problem. But I haven't been able to find any
> guidance in manuals and tutorials on writing functions that will
> autoload well. Nothing I've read goes far beyond the syntax reference
> entry for autoload. Everything says that you should export/autoload
> only the functions one wants to use. It doesn't explain how to write
> code that will cooperate with the autoload function. I mean that I
> have a feeling that my whole design of my program is incorrect and
> hence, my attempt to follow the standard example of using autoload
> failed.
> 
> Are there any good tutorials for writing Emacs libraries? I am
> familiar with the Glickstein book (O'Reilly) - few generic approaches
> are described in it. The case-study approach fails for me. I don't see
> why the examples are different from my program, so I odn't understand
> why they work and mine don't. I think a good introduction to writing
> clean programs could help me avoid this kind of error.
> 
> Furthermore, I want to raise a point for discussion. There seems to be
> very little online documentation for Lisp, especially Emacs Lisp.
> There is of course the standard language reference manuals. These are
> tersely written and lack helpful examples. They often require a lot of
> knowledge about other parts of the language, not necessarily more
> basic, just to understand an entry for a single function.
> 
> Thanks, 
> Ryan

-- 
__Pascal_Bourguignon__                   http://www.informatimago.com/
----------------------------------------------------------------------
 The name is Baud,...... James Baud.