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

Re: Newbie: Help with elisp, please



Thank you for your prompt response :O)

On April 28, 2004 03:13 pm, Florent Rougon scribed:
FR> Brad Camroux <bgcamroux@shaw.ca> wrote:
FR>
FR> > Hello,
FR>
FR> Hi,
FR>
FR> > <snip>
FR> > (setq latex-skel-file '"~//TeX//skeleton.tex")
FR>
FR> Do you really need two / in a row?

I thought that I did need two "/" in a row -- from what I understood, 
"/" is a special character that needs to be escaped with a "/".  
Maybe I'm wrong, but I'm just getting this from a book -- Granted, 
I've found *lots* of typographic, grammatical, and technical errors 
in this book, but it's one of few references I have to go on.

FR> > (defun skel ()
FR> >   "Read in LaTeX Document Skeleton"
FR> >   (interactive)
FR> >   (insert-file latex-skel-file)
FR> > )
FR>
FR> FWIW, I like the "Template Package for Emacs" by Christoph Wedler
 as far FR> as templates go.
FR>
FR>   http://emacs-template.sourceforge.net/
FR>
FR>   (and http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=228550)
FR>
FR> > (defun prit ()
FR> >   (interactive)
FR> >   (set 'str "\\prit{}")
FR>
FR> You could write (setq str "\\prit{}"). The 'q' means quoted. Very
 common FR> and handy.
FR>
FR> Also, you really shouldn't use set/setq for this, because this
 way,
FR> you're setting the global binding of the variable str
 (well, the
FR> innermost binding from where the function is called,
 and since it is
FR> presumably called from top level, this would be
 in the less bad case a 
FR> buffer-local binding). You should use let
 or let* to make it a local 
FR> variable. See the Gnu Emacs Lisp Reference manual (package 
elisp-manual).

Okay... I wasn't really sure about this.  I had just read about how to 
set local variables this morning, and then had to go write an exam 
for school.  I kinda thought that maybe I should set them as local, 
but wasn't sure.  I'll definitely change this.  Thank you.

FR> >   (insert str)
FR>
FR> Er, why did you need str in the first place?...
FR>
FR> (insert "\\prit{}") and you're done...

Yeah... I guess that is a little redundant.  Again, though, I've just 
been using this book, "LaTeX for Linux" by Bernice Sacks Lipkin (not 
really recommended unless you like editing for grammar and 
typographic mistakes, as well as technical errors).

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

Okay... I guess this makes sense with the amount of customization that 
is done with Emacs.  I'm not used to working with such versatile 
packages; when I write code, I'm the only one who ever uses it, and 
it would be quite rare indeed that it would ever potentially interact 
with other codes.  Thanks for this advice.

FR> > (defun prbf ()
FR> >   (interactive)
FR> >   (set 'str "\\prbf{}")
FR> >   (insert str)
FR> >   (backward-char 1)
FR> > )
FR>
FR> The same remarks apply here, of course.
FR>
FR> > Now, whenever I try to byte-compile this code, I get the
 message: FR> >
FR> > <snip>
FR> > Compiling file /home/frodo/emacs/latex.el at Wed Apr 28
 13:00:35 2004 FR> >   ** assignment to free variable latex-skel-file
FR> >   ** assignment to free variable str
FR> >   ** reference to free variable latex-skel-file
FR>
FR> Generally, you can safely ignore these messages. The variables
 are not FR> bound when the byte-compiler does its job. So what?
FR>
FR> If you install Emacs add-ons by hand or even compile Emacs
 yourself, FR> you'll see tons of warnings like these. In general, if
 your program FR> works well as a .el, turning it into a .elc is
 quite straightforward. FR>
FR> > I have also had messages telling me that the value of the
 variable FR> > latex-mode-map is void.  I don't understand how to
 deal with this.  I FR>
FR> I think that if you have the variable bound as far as the
 byte-compiler FR> can see it, you won't get the warning. If this is
 correct, you are FR> really safe ignoring the warning.
FR>
FR> > have been trying to read through the emacs manual and reference
FR> > guides available online, but there is no reference to dealing
 with FR> > such problems.
FR>
FR> Because they are usually harmless?

Alright... now the only problem is that, when I try to load this 
(compiled) code into Emacs and use the assigned key-bindings, they 
don't do anything.  It's really kinda strange.  The only time they 
actually did anything was when I changed 

	(define-key latex-mode-map ...)

to

	(global-set-key ...)

I found this rather surprising, but then I don't really understand 
exactly what I'm doing... such a frustrating learning curve 
sometimes.

FR> > Could someone please help me?  I know that there are
 pre-defined FR> > key-bindings for latex-mode, but I'd rather setup
 my own that I know FR> > work the way I want them to.
FR>
FR> Good. Understanding a bit of ELisp helps a lot to use Emacs
 efficiently. FR>
FR> > I would very much appreciate any help.
FR>
FR> HTH,
FR>
FR> --
FR> Florent

Thank you very much for your suggestions.  I will definitely take them 
into consideration and implement all that I can.  If I have any more 
questions, I will most certainly let you know.  Thanks again!

-- 
+--------------------------+-------------------------------+
|Brad Camroux              | === http://www.debian.org === |
|Student                   | ============================= |
|Geophysics & Applied Math | Proud admin and user of Debian|
|University of Calgary     | since 2003... because Red Hat |
|Calgary, AB, Canada       | just didn't cut it            |
+--------------------------+-------------------------------+



Reply to: