emacs-devel
[Top][All Lists]
Advanced

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

Re: auto-coding-function for LaTeX


From: Reiner Steib
Subject: Re: auto-coding-function for LaTeX
Date: Fri, 12 Nov 2004 02:12:27 +0100
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/21.3.50 (gnu/linux)

On Fri, Nov 12 2004, Arne Jørgensen wrote:

> It could look like this: [...]

I have added some other coding systems available in Emacs and I tried
to improve the code and doc-strings.  WDYT?

--8<---------------cut here---------------start------------->8---
(defcustom latex-auto-coding-alist
  '(("ansinew" . windows-1252) ; MS Windows ANSI encoding, extension of Latin-1
    ("applemac" . mac-roman)
    ("ascii" . us-ascii)
    ("cp1250" . cp1250) ; MS Windows encoding, codepage 1250
    ("cp1252" . windows-1252) ; synonym of ansinew
    ("cp437de" . cp437) ; IBM code page 437 (German version): 225 is \ss
    ("cp437" . cp437) ; IBM code page 437: 225 is \beta
    ("cp850" . cp850) ; IBM code page 850
    ("cp852" . cp852) ; IBM code page 852
    ("cp865" . cp865) ; IBM code page 865
    ;; The DECMultinational charaterset used by the OpenVMS system
    ;; ("decmulti" . undecided)
    ("latin1" . iso-8859-1)
    ("latin2" . iso-8859-2)
    ("latin3" . iso-8859-3)
    ("latin4" . iso-8859-4)
    ("latin5" . iso-8859-5)
    ("latin9" . iso-8859-15)
    ;; ("next" . undecided) ; The Next encoding
    ("utf8" . utf-8))
  "Mapping from encoding names used by \"inputenc.sty\" Emacs coding systems.
Used by the function `latex-auto-coding-function'."
  :group 'mule
  :type '(alist :key-type (string :tag "LaTeX input encoding")
                :value-type (coding-system :tag "Coding system")))

(defun latex-find-file-coding-system (arg)
"Determine the encoding of a LaTeX buffer if it uses \"inputenc.sty\".

This function is intended to be added to `auto-coding-functions'.

The mapping from LaTeX's \"inputenc.sty\" encoding names to Emacs
coding system names is determined from `latex-auto-coding-alist'."
  (when (re-search-forward "\\usepackage\\[\\(.*\\)\\]{inputenc}" 1000 t)
    (let* ((match (match-string 1))
           (inputenc-match (cdr (assoc match latex-auto-coding-alist)))
           (sym (intern match)))
      (when inputenc-match (setq sym inputenc-match))
      (when (coding-system-p sym)
        sym))))

(add-to-list 'file-coding-system-alist
             '("\\.tex\\|\\.ltx\\'" . latex-find-file-coding-system))
--8<---------------cut here---------------end--------------->8---

Bye, Reiner.
-- 
       ,,,
      (o o)
---ooO-(_)-Ooo---  |  PGP key available  |  http://rsteib.home.pages.de/




reply via email to

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