help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: elisp questions for Advanced Closing brackets function


From: Rupert Swarbrick
Subject: Re: elisp questions for Advanced Closing brackets function
Date: Wed, 21 May 2008 11:28:18 +0100
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux)

"Lorenzo Isella" <address@hidden> writes:

> Dear All,
> My questions are even more basic than the ones expressed here.
> I would like to do some "trivial" emacs customization.
> First of all, I should say I am not a lisp programmer at all and that
> my .emacs file
> is at the present a patchwork of examples I found online.
> Yet, what I would like to do should be quite simple.
> A few examples:
> (1) I often use auctex, but when I open a tex file I would like to
> have pdflatex as
> the default, so I would like to skip the tedious C-c C-t C-p.
> How can I include this command in the .emacs file? Obviously it should
> be executed only when I am opening and reading a .tex file.

Ok, I didn't know the answer to this at first, so here's how I found it:

Firstly, what does C-c C-t C-p run? (I know what it does, but what
function name?) Use C-h c which tells you the name of the function
bound to the given key sequence.

C-h c C-c C-t C-p gives TeX-PDF-mode. Now, what does that do? Well,
let's look at its docs: C-h f TeX-PDF-mode

Gives:

,----
| TeX-PDF-mode is an interactive compiled Lisp function in <long stuff>
| It is bound to C-c C-t C-p.
| (TeX-PDF-mode &optional ARG)
| 
| Minor mode for using PDFTeX.
| 
| If enabled, PDFTeX will be used as an executable by default.
| You can customize an initial value, and you can use the
| function `TeX-global-PDF-mode' for toggling this value.
`----

Ahah! So we want to know about TeX-global-PDF-mode! Roight, let's look
at that function, using C-h f TeX-global-PDF-mode. Well that says:

,----
| TeX-global-PDF-mode is an interactive compiled Lisp func <blah blah>
| (TeX-global-PDF-mode &optional ARG)
| 
| Toggle default for `TeX-PDF-mode'.
`----

(Ye gods, will we ever get there?!) But TeX-PDF-mode is a variable,
which is looking promising. Maybe we can use customise. Finally (!)
call C-h v TeX-PDF-mode and you'll see near the bottom of the help
page a link to customise the variable. Tada!

I realise this is a roundabout way to get the answer, but maybe this
answer will help you solve the next problem you come across.


> (2) Here is something I do not understand.  I found online the
> following handy function for automatically inserting another "$" sign
> when I type one and moving back the cursor:
>
>    (defun TeX-insert-dollar () "custom redefined insert-dollar" (interactive)
>      (insert "$$")       ;in LaTeX mode, typing "$" automatically insert "$$"
>      (backward-char 1)) ;and go between them: no more matching problems!
>
> Then, I tried doing something similar when quoting:
>
>    (defun TeX-insert-quote () "custom redefined insert-quote" (interactive)
>      (insert "``''")
>      (backward-char 2))
>
> and it worked. However, when I tried doing the same with brackets:
>
>    (defun TeX-insert-curly () "custom redefined insert-curly" (interactive)
>      (insert "{}")
>      (backward-char 1))
>
> I did not get any error message, but it surely does not work on my
> system.

What is happening is that you are (successfully) *redefining* the
functions TeX-insert-quote and TeX-insert-dollar, which were
originally defined somewhere in the depths of auctex and bound to the
keys " and $ respectively.

What you need to do is get auctex to run your TeX-insert-curly when
you hit { in the same way. The following should work:

(local-set-key "{" 'TeX-insert-curly)

But it needs to get run whenever you enter tex mode, so you can't just
plonk it in your .emacs (otherwise it would apply to emacs lisp mode,
I think) and instead need to run it on what is called a mode
hook. Since you haven't done much elisp and this is a bit obscure, the
magic incantation to put in your .emacs is

(add-hook 'TeX-mode-hook
          (lambda () (local-set-key "{" 'TeX-insert-curly)))


(after you've defined TeX-insert-curly)


Rupert


reply via email to

[Prev in Thread] Current Thread [Next in Thread]