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

Re: Newbie: Help with elisp, please



 >>>>> On Wed, 28 Apr 2004 13:26:15 -0600, Brad Camroux
 >>>>> <bgcamroux@shaw.ca> was rumoured to have said:

 > Hello,
 > I'm relatively new to *customizing* emacs.  I've been using emacs for 
 > a while, though not efficiently.  I would like to learn how to do 
 > things more effectively and efficiently.  To start with, I'm trying 
 > to setup some LaTeX keyboard mappings that *I* want.  I have setup a 
 > few function definitions in a file called latex.el which has a 
 > general form similar to the following:

Hello,

I'm not an experienced lisp programmer by any means, but here are some
suggestions...

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

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

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

This function creates a global variable, which is probably why emacs complains
about it when you byte-compile it. How about this:

(defun prit ()
  (interactive)
  (let ((str "\\prit{}"))
    (insert str))
  (backward-char 1))

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

 > (define-key latex-mode-map "\C-cb" 'prbf)
 > (define-key latex-mode-map "\C-ci" 'prit)
 > (define-key latex-mode-map [f5] 'skel)
 > </snip>

 > 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

 > While compiling prit:
 >   ** reference to free variable str

 > While compiling prbf:
 >   ** reference to free variable str
 > </snip>

 > 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 
 > have been trying to read through the emacs manual and reference 
 > guides available online, but there is no reference to dealing with 
 > such problems.

I'm not really familiar with keymaps but it seems a keymap has to be created
first (make-keymap). Looking at how various modes define their keymaps would
certainly help.

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

Hmm, personally I try to keep custom keybindings down to a minimum (and even
so I have more than I can remember), but when I need one I tend to define it
in some hook like so (which probably explains why I don't know about
keymaps!):

(add-hook 'some-mode-hook
	  '(lambda ()
	     (local-set-key "some-key" '(lambda ()
				     	  (interactive)
				       	  (do-something-simple)))))

This of course can get messy with many bindings...

 > I would very much appreciate any help.

 > Thanks in advance,

 > (PS: Please do not CC me in your reply; I read the list)

 > -- 
 > +--------------------------+-------------------------------+
 > |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            |
 > +--------------------------+-------------------------------+


Rgds,
/-sb.



Reply to: