annotate lisp/international/latexenc.el @ 61914:f658c441541a

(resolve_face_name): Add arg SIGNAL_P. Calls changed. Fix cyclic alias check. If alias loop is detected, signal circular-list error if SIGNAL_P, and return Qdefault if !SIGNAL_P.
author Kim F. Storm <storm@cua.dk>
date Thu, 28 Apr 2005 13:14:06 +0000
parents b5cd4f1a1855
children 290ff04b090e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
61909
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1 ;;; latexenc.el --- guess correct coding system in LaTeX files
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
2
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
3 ;; Copyright (C) 2005 Free Software Foundation, Inc.
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
4
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
5 ;; Author: Arne J,Ax(Brgensen <arne@arnested.dk>
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
6 ;; Keywords: mule, coding system, latex
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
7
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
9
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
13 ;; any later version.
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
14
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
18 ;; GNU General Public License for more details.
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
19
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
23 ;; Boston, MA 02111-1307, USA.
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
24
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
25 ;;; Commentary:
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
26
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
27 ;; This code tries to guess the correct coding system of a LaTeX file.
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
28
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
29 ;; First it searches for a \inputencoding{...} or
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
30 ;; \usepackage[...]{inputenc} line in the file and looks up the ... in
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
31 ;; `latex-inputenc-coding-alist' to find the corresponding coding
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
32 ;; system.
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
33
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
34 ;; If this fails it will search for AUCTeX's TeX-master or tex-mode's
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
35 ;; tex-main-file variable in the local variables section and visit
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
36 ;; that file to get the coding system from the master file. This check
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
37 ;; can be disabled by setting `latexenc-dont-use-TeX-master-flag' to
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
38 ;; t.
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
39
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
40 ;; If we have still not found a coding system we will try to use the
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
41 ;; standard tex-mode's `tex-guess-main-file' and get the coding system
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
42 ;; from the main file. This check can be disabled by setting
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
43 ;; `latexenc-dont-use-tex-guess-main-file-flag' to t.
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
44
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
45 ;; The functionality is enabled by adding the function
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
46 ;; `latexenc-find-file-coding-system' to `file-coding-system-alist'
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
47 ;; like this
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
48
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
49 ;; (add-to-list 'file-coding-system-alist
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
50 ;; '("\\.tex\\|\\.ltx\\|\\.dtx\\|\\.drv\\'" . latexenc-find-file-coding-system))
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
51
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
52 ;;; Code:
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
53
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
54 ;;;###autoload
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
55 (defcustom latex-inputenc-coding-alist
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
56 '(("ansinew" . windows-1252) ; MS Windows ANSI encoding, extension of Latin-1
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
57 ("applemac" . mac-roman)
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
58 ("ascii" . us-ascii)
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
59 ("cp1250" . windows-1250) ; MS Windows encoding, codepage 1250
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
60 ("cp1252" . windows-1252) ; synonym of ansinew
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
61 ("cp1257" . cp1257)
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
62 ("cp437de" . cp437) ; IBM code page 437 (German version): 225 is \ss
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
63 ("cp437" . cp437) ; IBM code page 437: 225 is \beta
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
64 ("cp850" . cp850) ; IBM code page 850
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
65 ("cp852" . cp852) ; IBM code page 852
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
66 ;; ("cp858" . undecided) ; IBM code page 850 but with a euro symbol
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
67 ("cp865" . cp865) ; IBM code page 865
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
68 ;; The DECMultinational charaterset used by the OpenVMS system
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
69 ;; ("decmulti" . undecided)
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
70 ("latin1" . iso-8859-1)
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
71 ("latin2" . iso-8859-2)
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
72 ("latin3" . iso-8859-3)
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
73 ("latin4" . iso-8859-4)
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
74 ("latin5" . iso-8859-5)
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
75 ("latin9" . iso-8859-15)
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
76 ;; ("latin10" . undecided)
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
77 ;; ("macce" . undecided) ; Apple Central European
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
78 ("next" . next) ; The Next encoding
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
79 ("utf8" . utf-8)
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
80 ("utf8x" . utf-8)) ; used by the Unicode LaTeX package
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
81 "Mapping from encoding names used by LaTeX's \"inputenc.sty\" to Emacs coding systems.
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
82 Used by the function `latexenc-find-file-coding-system'."
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
83 :group 'files
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
84 :group 'mule
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
85 :type '(alist :key-type (string :tag "LaTeX input encoding")
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
86 :value-type (coding-system :tag "Coding system")))
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
87
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
88 ;;;###autoload
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
89 (defun latexenc-inputenc-to-coding-system (inputenc)
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
90 "Return the corresponding coding-system for the specified input encoding.
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
91 Return nil if no matching coding system can be found."
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
92 (cdr (assoc inputenc latex-inputenc-coding-alist)))
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
93
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
94 ;;;###autoload
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
95 (defun latexenc-coding-system-to-inputenc (cs)
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
96 "Return the corresponding input encoding for the specified coding system.
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
97 Return nil if no matching input encoding can be found."
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
98 (let (result)
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
99 (catch 'result
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
100 (dolist (elem latex-inputenc-coding-alist result)
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
101 (let ((elem-cs (cdr elem)))
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
102 (when (and (coding-system-p elem-cs)
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
103 (coding-system-p cs)
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
104 (eq (coding-system-base cs) (coding-system-base elem-cs)))
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
105 (setq result (car elem))
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
106 (throw 'result result)))))))
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
107
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
108 (defvar latexenc-dont-use-TeX-master-flag nil
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
109 "Non-nil means don't follow TeX-master to find the coding system.")
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
110
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
111 (defvar latexenc-dont-use-tex-guess-main-file-flag nil
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
112 "Non-nil means don't use tex-guessmain-file to find the coding system.")
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
113
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
114 ;;;###autoload
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
115 (defun latexenc-find-file-coding-system (arg-list)
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
116 "Determine the coding system of a LaTeX file if it uses \"inputenc.sty\".
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
117 The mapping from LaTeX's \"inputenc.sty\" encoding names to Emacs
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
118 coding system names is determined from `latex-inputenc-coding-alist'."
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
119 (if (eq (car arg-list) 'insert-file-contents)
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
120 (save-excursion
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
121 ;; try to find the coding system in this file
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
122 (goto-char (point-min))
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
123 (if (or
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
124 (re-search-forward "^[^%$]*\\inputencoding{\\(.*\\)}" nil t)
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
125 (re-search-forward "^[^%$]*\\usepackage\\[\\(.*\\)\\]{inputenc}" nil t))
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
126 (let* ((match (match-string 1))
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
127 (sym (intern match)))
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
128 (when (latexenc-inputenc-to-coding-system match)
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
129 (setq sym (latexenc-inputenc-to-coding-system match))
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
130 (when (coding-system-p sym)
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
131 sym
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
132 (if (and (require 'code-pages nil t) (coding-system-p sym))
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
133 sym
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
134 'undecided))))
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
135 ;; else try to find it in the master/main file
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
136 (let (latexenc-main-file)
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
137 ;; is there a TeX-master or tex-main-file in the local variable section
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
138 (unless latexenc-dont-use-TeX-master-flag
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
139 (goto-char (point-max))
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
140 (when (re-search-backward "^%+ *\\(TeX-master\\|tex-main-file\\): *\"\\(.+\\)\"" nil t)
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
141 (let ((file (concat (file-name-directory (nth 1 arg-list)) (match-string 2))))
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
142 (if (file-exists-p file)
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
143 (setq latexenc-main-file file)
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
144 (if (boundp 'TeX-default-extension)
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
145 (when (file-exists-p (concat file "." TeX-default-extension))
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
146 (setq latexenc-main-file (concat file "." TeX-default-extension)))
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
147 (dolist (ext '("drv" "dtx" "ltx" "tex"))
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
148 (if (file-exists-p (concat file "." ext))
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
149 (setq latexenc-main-file (concat file "." ext)))))))))
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
150 ;; try tex-modes tex-guess-main-file
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
151 (when (and (not latexenc-dont-use-tex-guess-main-file-flag)
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
152 (not latexenc-main-file))
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
153 (when (fboundp 'tex-guess-main-file)
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
154 (let ((tex-start-of-header "\\\\document\\(style\\|class\\)")
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
155 (default-directory (file-name-directory (nth 1 arg-list))))
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
156 (setq latexenc-main-file (tex-guess-main-file)))))
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
157 ;; if we found a master/main file get the coding system from it
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
158 (if (and latexenc-main-file
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
159 (file-readable-p latexenc-main-file))
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
160 (let* ((latexenc-dont-use-tex-guess-main-file-flag t)
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
161 (latexenc-dont-use-TeX-master-flag t)
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
162 (latexenc-main-buffer (find-file-noselect latexenc-main-file t)))
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
163 (or (buffer-local-value 'coding-system-for-write latexenc-main-buffer)
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
164 (buffer-local-value 'buffer-file-coding-system latexenc-main-buffer)))
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
165 'undecided))))
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
166 'undecided))
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
167
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
168 (provide 'latexenc)
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
169
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
170 ;;; latexenc.el ends here