From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Rupert Swarbrick Newsgroups: gmane.emacs.help Subject: Re: elisp questions for Advanced Closing brackets function Date: Wed, 21 May 2008 11:28:18 +0100 Organization: albasani.net Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1211366521 31917 80.91.229.12 (21 May 2008 10:42:01 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 21 May 2008 10:42:01 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed May 21 12:42:39 2008 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1Jyllz-0002cO-TX for geh-help-gnu-emacs@m.gmane.org; Wed, 21 May 2008 12:42:20 +0200 Original-Received: from localhost ([127.0.0.1]:38081 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JyllF-0007fp-Ay for geh-help-gnu-emacs@m.gmane.org; Wed, 21 May 2008 06:41:33 -0400 Original-Path: news.stanford.edu!headwall.stanford.edu!fu-berlin.de!news.albasani.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 105 Original-X-Trace: news.albasani.net SLKe0KOzjQMIpVKFJ6uaTroCzJF2m66cDlBYZ2mKGnkZTGtstuItXpeQJafrfMehpLiXu9bTc3lKWaEdH8zguehpFuQTpIKLBNP/IBvHlyw4XxpXk4yxcxLIoOhg1Heq Original-X-Complaints-To: abuse@albasani.net Original-NNTP-Posting-Date: Wed, 21 May 2008 10:28:18 +0000 (UTC) X-User-ID: 7LM7orPXpdEC0Iy9WTm/5G3bTBfyPDNhJpfF3YBXchA= Cancel-Lock: sha1:YcZGnZW0cUdnbO3L2+WNYv5m7oI= User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux) X-NNTP-Posting-Host: LYjJWpA+twC90vTMuBOsjzT148X7nrEtmck1DbfyMNc= Original-Xref: news.stanford.edu gnu.emacs.help:158832 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:54199 Archived-At: "Lorenzo Isella" 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 | 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 | (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