[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Newbie: Help with elisp, please

Brad Camroux <bgcamroux@shaw.ca> wrote:

> Hello,


> <snip>
> (setq latex-skel-file '"~//TeX//skeleton.tex")

Do you really need two / in a row?

> (defun skel ()
>   "Read in LaTeX Document Skeleton"
>   (interactive)
>   (insert-file latex-skel-file)
> )

FWIW, I like the "Template Package for Emacs" by Christoph Wedler as far
as templates go.


  (and http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=228550)

> (defun prit ()
>   (interactive)
>   (set 'str "\\prit{}")

You could write (setq str "\\prit{}"). The 'q' means quoted. Very common
and handy.

Also, you really shouldn't use set/setq for this, because this way,
you're setting the global binding of the variable str (well, the
innermost binding from where the function is called, and since it is
presumably called from top level, this would be in the less bad case a
buffer-local binding). You should use let or let* to make it a local
variable. See the Gnu Emacs Lisp Reference manual (package

>   (insert str)

Er, why did you need str in the first place?...

(insert "\\prit{}") and you're done...

Also, you should never define functions with names like this for your
own stuff. Always use a prefix that identifies you or the package you
are writing. There are so many extensions in Emacs that taking a minimum
of precautions to avoir namespace clashes is definitely advisable.

  (defun brad-prit ()

> (defun prbf ()
>   (interactive)
>   (set 'str "\\prbf{}")
>   (insert str)
>   (backward-char 1)
> )

The same remarks apply here, of course.

> Now, whenever I try to byte-compile this code, I get the message:
> <snip>
> Compiling file /home/frodo/emacs/latex.el at Wed Apr 28 13:00:35 2004
>   ** assignment to free variable latex-skel-file
>   ** assignment to free variable str
>   ** reference to free variable latex-skel-file

Generally, you can safely ignore these messages. The variables are not
bound when the byte-compiler does its job. So what?

If you install Emacs add-ons by hand or even compile Emacs yourself,
you'll see tons of warnings like these. In general, if your program
works well as a .el, turning it into a .elc is quite straightforward.

> I have also had messages telling me that the value of the variable 
> latex-mode-map is void.  I don't understand how to deal with this.  I 

I think that if you have the variable bound as far as the byte-compiler
can see it, you won't get the warning. If this is correct, you are
really safe ignoring the warning.

> have been trying to read through the emacs manual and reference 
> guides available online, but there is no reference to dealing with 
> such problems.

Because they are usually harmless?

> Could someone please help me?  I know that there are pre-defined 
> key-bindings for latex-mode, but I'd rather setup my own that I know 
> work the way I want them to.

Good. Understanding a bit of ELisp helps a lot to use Emacs efficiently.

> I would very much appreciate any help.



Reply to: