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

Re: Newbie: Help with elisp, please

Brad Camroux <bgcamroux@shaw.ca> wrote:

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

Not for the Emacs Lisp interpreter. It might be the case for some ELisp
program out there, but Emacs doesn't treat "/" in a special way. You are
confusing it with "\", I think.

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

Then just use the GNU Emacs Lisp Reference Manual. It's really

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

And apart from avoiding potential clashes, it will save you time when
you have defined so many commands that you cannot remember their names

  M-x brad-<tab>

will become helpful one day!

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

The syntax you gave in your first mail was correct. You're probably
using latex-mode-map instead of LaTeX-mode-map or something. For one,
I'm using AUCTeX and need to alter LaTeX-mode-map for its LaTeX mode.

If you want to see what is happening, you can go in a buffer in
LaTeX-mode, do:

   M-: (setq some-temporary-global-variable (current-local-map))

then go to the *scratch* buffer, write:

   (print some-temporary-global-variable (current-buffer))

and hit C-x C-e with the point placed after the last closing
parenthesis. This will dump the local map that was in use in the buffer
where you called current-local-map so you can have a look at it.

Also, you can type in *scratch*:

  (eq some-temporary-global-variable LaTeX-mode-map)

followed by C-x C-e (or C-j to have the result written to the buffer) to
see if that map is really LaTeX-mode-map or something else. In my case,
it prints t, so it is OK. If I use latex-mode-map instead, it will
complain that this references a void variable.

Also, you should use those define-key calls in the appropriate hook to
be sure that the map is already defined. For instance:

  (add-hook 'LaTeX-mode-hook
            #'(lambda ()
                (define-key LaTeX-mode-map [C-f5] 'do-LaTeX)))

or, better:

  (defun brad-setup-LaTeX-keybindings ()
    (define-key LaTeX-mode-map [C-f5] 'do-LaTeX)
    (define-key LaTeX-mode-map ...))

  (add-hook 'LaTeX-mode-hook 'brad-setup-LaTeX-keybindings)

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

Once you get the basic concepts, it will become relatively easy.


Reply to: