[OS X TeX] Emacs 22.92, %! and TeXShop
Jens Noeckel
noeckel at uoregon.edu
Fri Jan 26 13:03:07 EST 2007
On Jan 26, 2007, at 2:06 AM, Stephen Moye wrote:
>
> On Jan 26, 2007, at 12:12 AM, Jens Noeckel wrote:
>
>>
>> On Jan 25, 2007, at 8:49 PM, Jens Noeckel wrote:
>>
>>>
>>> On Jan 25, 2007, at 6:49 PM, Stephen Moye wrote:
>>>
>>>> On Jan 25, 2007, at 9:10 PM, Jens Noeckel wrote:
>>>>
>>>>>
>>>>> On Jan 25, 2007, at 5:41 PM, Stephen Moye wrote:
>>>>>
>>>>>> On Jan 25, 2007, at 8:34 PM, Stephen Moye wrote:
>>>>>>
>>>>>>> I just started using emacs 22.92 -- I have been using emacs
>>>>>>> 22.50. Unlike v22.50, when I open a TeXShop TeX file with
>>>>>>> emacs 22.92, it is opened as a PostScript file. I imagined
>>>>>>> that it had something to do with the first line of the file:
>>>>>>>
>>>>>>> %!TEX TS-program = latex
>>>>>>>
>>>>>>> Sure enough, I went digging using
>>>>>>>
>>>>>>> C-h v auto-mode-alist
>>>>>>>
>>>>>>> and found a line in files.el:
>>>>>>>
>>>>>>> ("%![^V]" . ps-mode)
>>>>>>>
>>>>>>> in addition to what I expected:
>>>>>>>
>>>>>>> ("\\.[tT]e[xX]\\'" . tex-mode)
>>>>>>>
>>>>>>> So emacs is looking inside the file to make a better guess
>>>>>>> about what kind of file it is. I tried changing
>>>>>>>
>>>>>>> ("%![^V]" . ps-mode)
>>>>>>>
>>>>>>> to
>>>>>>>
>>>>>>> ("%![^VT]" . ps-mode)
>>>>>>>
>>>>>>> but that did not work.
>>>>>>>
>>>>>>> I really like emacs 22.nn, but this is a bit of a bother. Can
>>>>>>> I put something in my .emacs file to counter this unwanted
>>>>>>> cleverness? I know that I can put
>>>>>>>
>>>>>>> %-*-latex-*-
>>>>>>>
>>>>>>> as the first line of the file and both emacs and TeXShop will
>>>>>>> be happy, but that seems an unnecessary complication.
>>>>>>>
>>>>>>> Any suggestions? Or, alternatively, where else should I more
>>>>>>> appropriately post this query?
>>>>>>>
>>>>>>> Thank you for any insights.
>>>>>>
>>>>>> Sorry, but I should have mentioned that I am using emacs under
>>>>>> X11.
>>>>>>
>>>>>>
>>>>>>
>>>>>> Stephen
>>>>>>
>>>>>
>>>>> Stephen,
>>>>> not knowing what exactly is in your .emacs already, I would
>>>>> suggest adding the line
>>>>>
>>>>> (setq auto-mode-alist (cons '("\\.tex$" . tex-mode)
>>>>> auto-mode-alist))
>>>>>
>>>>> as close to the end of .emacs as possible (so that it doesn't
>>>>> get overridden by other associations - the order of these
>>>>> things matters).
>>>>>
>>>>> Jens
>>>>
>>>> I placed the line you suggested at the very end of my .emacs
>>>> file (which has very little in it), but a TeX file with %! at
>>>> the top still opened as a PostScript file.
>>>>
>>>> I am puzzled. Shouldn't the extension take precedence over
>>>> anything else? Surely a .tex file is almost certainly not going
>>>> to be a PostScript file...
>>>>
>>>> Anyway, thank you for the suggestion though.
>>>>
>>>> Stephen
>>>>
>>>> PS I did make the discovery that if the first line of the TeX
>>>> file is empty and the *second* line begins with %! then the
>>>> emacs mechanism is fooled and the file opens in TeX mode. Hmmmm...
>>>
>>>
>>> Ah, I just saw in the documentation that the magic-mode-alist
>>> takes precedence over the auto-mode-alist. I had not encountered
>>> this problem before, but I can reproduce it now with Carbon Emacs
>>> from fink. Here is something that fixes the problem: if you put
>>> this line in your .emacs, it will be stricter about what it
>>> considers as postscript:
>>>
>>> (mapc (lambda (pair) (if (eq (cdr pair) 'ps-mode) (setcar pair
>>> '"%!PS[^V]"))) magic-mode-alist)
>>>
>>> Now you have to have %!PS at the start to make it a PS file. What
>>> this code does is simply to search the magic-mode-alist for the
>>> ps-mode definition and replace the condition for recognizing it.
>>> This worked for me - hope it solves your problem, too.
>>>
>>> Jens
>>>
>>
>> One more change:
>> to avoid an error when using other emacs versions that don't
>> define magic-mode-alist, enclose everything in an if statement:
>>
>> (if (fboundp 'magic-mode-alist)
>> (mapc (lambda (pair) (if (eq (cdr pair) 'ps-mode) (setcar pair '"%!
>> PS[^V]"))) magic-mode-alist))
>>
>> I think that should cover everything now...
>> Jens
>
> Thank you -- that worked perfectly. I'll have to study and learn
> from your fix, so thank you again for explaining it to me.
>
>
Stephen,
great to know it worked. By the way, this lisp code could be
translated almost one-to-one to Mathematica. So if you know
Mathematica, you known lisp (and vice versa) - except that the
keywords are different. Don't know if this helps... if not, here is a
link for learning emacs (and lisp):
http://xahlee.org/emacs/emacs_fun.html
Regards,
Jens
------------------------- Helpful Info -------------------------
Mac-TeX Website: http://www.esm.psu.edu/mac-tex/
TeX FAQ: http://www.tex.ac.uk/faq
List Archive: http://tug.org/pipermail/macostex-archives/
List Reminders & Etiquette: http://www.esm.psu.edu/mac-tex/list/
More information about the MacOSX-TeX
mailing list