annotate lisp/international/latexenc.el @ 91202:018583232611

(tibetan-composition-function): Use font-shape-text if auto-compose-current-font is non-nil.
author Kenichi Handa <handa@m17n.org>
date Thu, 06 Dec 2007 07:36:14 +0000
parents 451a2d341d55
children 5b9f6405b71a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
68419
c72649ca09b5 Add a coding: tag.
Eli Zaretskii <eliz@gnu.org>
parents: 68418
diff changeset
1 ;;; latexenc.el --- guess correct coding system in LaTeX files -*-coding: iso-2022-7bit -*-
61909
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
2
75347
e3694f1cb928 Add 2007 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 72692
diff changeset
3 ;; Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc.
61909
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
78274
451a2d341d55 Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents: 75347
diff changeset
12 ;; the Free Software Foundation; either version 3, or (at your option)
61909
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
64085
18a818a2ee7c Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 63091
diff changeset
22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18a818a2ee7c Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 63091
diff changeset
23 ;; Boston, MA 02110-1301, USA.
61909
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
63091
81d7efcce2ff Doc fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 63084
diff changeset
50 ;; '("\\.\\(tex\\|ltx\\|dtx\\|drv\\)\\'" . latexenc-find-file-coding-system))
61909
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
72692
0b31ecee2604 * international/latexenc.el (latex-inputenc-coding-alist): Add cp858.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 72322
diff changeset
66 ("cp858" . cp858) ; IBM code page 850 but with a euro symbol
61909
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
67256
47d2cf396650 (latex-inputenc-coding-alist): Doc fix.
Eli Zaretskii <eliz@gnu.org>
parents: 67205
diff changeset
81 "Mapping from LaTeX encodings in \"inputenc.sty\" to Emacs coding systems.
67205
06635bf17a9e (latex-inputenc-coding-alist): Reword doc string.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 64085
diff changeset
82 LaTeX encodings are specified with \"\\usepackage[encoding]{inputenc}\".
61909
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
83 Used by the function `latexenc-find-file-coding-system'."
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
84 :group 'files
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
85 :group 'mule
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
86 :type '(alist :key-type (string :tag "LaTeX input encoding")
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
87 :value-type (coding-system :tag "Coding system")))
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
88
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
89 ;;;###autoload
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
90 (defun latexenc-inputenc-to-coding-system (inputenc)
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
91 "Return the corresponding coding-system for the specified input encoding.
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
92 Return nil if no matching coding system can be found."
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
93 (cdr (assoc inputenc latex-inputenc-coding-alist)))
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
94
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
95 ;;;###autoload
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
96 (defun latexenc-coding-system-to-inputenc (cs)
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
97 "Return the corresponding input encoding for the specified coding system.
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
98 Return nil if no matching input encoding can be found."
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
99 (let (result)
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
100 (catch 'result
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
101 (dolist (elem latex-inputenc-coding-alist result)
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
102 (let ((elem-cs (cdr elem)))
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
103 (when (and (coding-system-p elem-cs)
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
104 (coding-system-p cs)
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
105 (eq (coding-system-base cs) (coding-system-base elem-cs)))
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
106 (setq result (car elem))
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
107 (throw 'result result)))))))
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
108
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
109 (defvar latexenc-dont-use-TeX-master-flag nil
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
110 "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
111
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
112 (defvar latexenc-dont-use-tex-guess-main-file-flag nil
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
113 "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
114
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
115 ;;;###autoload
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
116 (defun latexenc-find-file-coding-system (arg-list)
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
117 "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
118 The mapping from LaTeX's \"inputenc.sty\" encoding names to Emacs
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
119 coding system names is determined from `latex-inputenc-coding-alist'."
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
120 (if (eq (car arg-list) 'insert-file-contents)
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
121 (save-excursion
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
122 ;; try to find the coding system in this file
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
123 (goto-char (point-min))
62243
68b153fd6cd9 (latexenc-find-file-coding-system): Avoid `re-search-forward' when
Lute Kamstra <lute@gnu.org>
parents: 61958
diff changeset
124 (if (catch 'cs
68b153fd6cd9 (latexenc-find-file-coding-system): Avoid `re-search-forward' when
Lute Kamstra <lute@gnu.org>
parents: 61958
diff changeset
125 (let ((case-fold-search nil))
68b153fd6cd9 (latexenc-find-file-coding-system): Avoid `re-search-forward' when
Lute Kamstra <lute@gnu.org>
parents: 61958
diff changeset
126 (while (search-forward "inputenc" nil t)
68b153fd6cd9 (latexenc-find-file-coding-system): Avoid `re-search-forward' when
Lute Kamstra <lute@gnu.org>
parents: 61958
diff changeset
127 (goto-char (match-beginning 0))
68b153fd6cd9 (latexenc-find-file-coding-system): Avoid `re-search-forward' when
Lute Kamstra <lute@gnu.org>
parents: 61958
diff changeset
128 (beginning-of-line)
68b153fd6cd9 (latexenc-find-file-coding-system): Avoid `re-search-forward' when
Lute Kamstra <lute@gnu.org>
parents: 61958
diff changeset
129 (if (or (looking-at "[^%\n]*\\\\usepackage\\[\\([^]]*\\)\\]{\\([^}]*,\\)?inputenc\\(,[^}]*\\)?}")
68b153fd6cd9 (latexenc-find-file-coding-system): Avoid `re-search-forward' when
Lute Kamstra <lute@gnu.org>
parents: 61958
diff changeset
130 (looking-at "[^%\n]*\\\\inputencoding{\\([^}]*\\)}"))
68b153fd6cd9 (latexenc-find-file-coding-system): Avoid `re-search-forward' when
Lute Kamstra <lute@gnu.org>
parents: 61958
diff changeset
131 (throw 'cs t)
68b153fd6cd9 (latexenc-find-file-coding-system): Avoid `re-search-forward' when
Lute Kamstra <lute@gnu.org>
parents: 61958
diff changeset
132 (goto-char (match-end 0))))))
68b153fd6cd9 (latexenc-find-file-coding-system): Avoid `re-search-forward' when
Lute Kamstra <lute@gnu.org>
parents: 61958
diff changeset
133 (let* ((match (match-string 1))
62974
ecfed70e0c5c (latexenc-find-file-coding-system): Don't inherit the EOL part of the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 62398
diff changeset
134 (sym (or (latexenc-inputenc-to-coding-system match)
ecfed70e0c5c (latexenc-find-file-coding-system): Don't inherit the EOL part of the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 62398
diff changeset
135 (intern match))))
ecfed70e0c5c (latexenc-find-file-coding-system): Don't inherit the EOL part of the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 62398
diff changeset
136 (cond
ecfed70e0c5c (latexenc-find-file-coding-system): Don't inherit the EOL part of the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 62398
diff changeset
137 ((coding-system-p sym) sym)
ecfed70e0c5c (latexenc-find-file-coding-system): Don't inherit the EOL part of the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 62398
diff changeset
138 ((and (require 'code-pages nil t) (coding-system-p sym)) sym)
ecfed70e0c5c (latexenc-find-file-coding-system): Don't inherit the EOL part of the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 62398
diff changeset
139 (t 'undecided)))
61909
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
140 ;; else try to find it in the master/main file
72322
2552d32034c7 (latexenc-find-file-coding-system):
Kenichi Handa <handa@m17n.org>
parents: 68421
diff changeset
141
2552d32034c7 (latexenc-find-file-coding-system):
Kenichi Handa <handa@m17n.org>
parents: 68421
diff changeset
142 ;; Fixme: If the current file is in an archive (e.g. tar,
2552d32034c7 (latexenc-find-file-coding-system):
Kenichi Handa <handa@m17n.org>
parents: 68421
diff changeset
143 ;; zip), we should find the master file in that archive.
2552d32034c7 (latexenc-find-file-coding-system):
Kenichi Handa <handa@m17n.org>
parents: 68421
diff changeset
144 ;; But, that is not yet implemented. -- K.Handa
2552d32034c7 (latexenc-find-file-coding-system):
Kenichi Handa <handa@m17n.org>
parents: 68421
diff changeset
145 (let ((default-directory (if (stringp (nth 1 arg-list))
2552d32034c7 (latexenc-find-file-coding-system):
Kenichi Handa <handa@m17n.org>
parents: 68421
diff changeset
146 (file-name-directory (nth 1 arg-list))
2552d32034c7 (latexenc-find-file-coding-system):
Kenichi Handa <handa@m17n.org>
parents: 68421
diff changeset
147 default-directory))
2552d32034c7 (latexenc-find-file-coding-system):
Kenichi Handa <handa@m17n.org>
parents: 68421
diff changeset
148 latexenc-main-file)
62974
ecfed70e0c5c (latexenc-find-file-coding-system): Don't inherit the EOL part of the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 62398
diff changeset
149 ;; Is there a TeX-master or tex-main-file in the local variables
ecfed70e0c5c (latexenc-find-file-coding-system): Don't inherit the EOL part of the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 62398
diff changeset
150 ;; section?
61909
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
151 (unless latexenc-dont-use-TeX-master-flag
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
152 (goto-char (point-max))
62974
ecfed70e0c5c (latexenc-find-file-coding-system): Don't inherit the EOL part of the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 62398
diff changeset
153 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min))
ecfed70e0c5c (latexenc-find-file-coding-system): Don't inherit the EOL part of the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 62398
diff changeset
154 'move)
62243
68b153fd6cd9 (latexenc-find-file-coding-system): Avoid `re-search-forward' when
Lute Kamstra <lute@gnu.org>
parents: 61958
diff changeset
155 (search-forward "Local Variables:" nil t)
62974
ecfed70e0c5c (latexenc-find-file-coding-system): Don't inherit the EOL part of the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 62398
diff changeset
156 (when (re-search-forward
ecfed70e0c5c (latexenc-find-file-coding-system): Don't inherit the EOL part of the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 62398
diff changeset
157 "^%+ *\\(TeX-master\\|tex-main-file\\): *\"\\(.+\\)\""
ecfed70e0c5c (latexenc-find-file-coding-system): Don't inherit the EOL part of the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 62398
diff changeset
158 nil t)
ecfed70e0c5c (latexenc-find-file-coding-system): Don't inherit the EOL part of the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 62398
diff changeset
159 (let ((file (match-string 2)))
ecfed70e0c5c (latexenc-find-file-coding-system): Don't inherit the EOL part of the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 62398
diff changeset
160 (dolist (ext `("" ,(if (boundp 'TeX-default-extension)
ecfed70e0c5c (latexenc-find-file-coding-system): Don't inherit the EOL part of the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 62398
diff changeset
161 (concat "." TeX-default-extension)
ecfed70e0c5c (latexenc-find-file-coding-system): Don't inherit the EOL part of the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 62398
diff changeset
162 "")
ecfed70e0c5c (latexenc-find-file-coding-system): Don't inherit the EOL part of the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 62398
diff changeset
163 ".tex" ".ltx" ".dtx" ".drv"))
ecfed70e0c5c (latexenc-find-file-coding-system): Don't inherit the EOL part of the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 62398
diff changeset
164 (if (and (null latexenc-main-file) ;Stop at first.
68421
f8e7e79d2ca2 Undo last change.
Eli Zaretskii <eliz@gnu.org>
parents: 68419
diff changeset
165 (file-exists-p (concat file ext)))
62974
ecfed70e0c5c (latexenc-find-file-coding-system): Don't inherit the EOL part of the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 62398
diff changeset
166 (setq latexenc-main-file (concat file ext)))))))
61909
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
167 ;; try tex-modes tex-guess-main-file
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
168 (when (and (not latexenc-dont-use-tex-guess-main-file-flag)
63084
33bc4355d988 (latexenc-find-file-coding-system):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 62974
diff changeset
169 (not latexenc-main-file))
33bc4355d988 (latexenc-find-file-coding-system):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 62974
diff changeset
170 ;; Use a separate `when' so the byte-compiler sees the fboundp.
33bc4355d988 (latexenc-find-file-coding-system):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 62974
diff changeset
171 (when (fboundp 'tex-guess-main-file)
33bc4355d988 (latexenc-find-file-coding-system):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 62974
diff changeset
172 (let ((tex-start-of-header "\\\\document\\(style\\|class\\)"))
33bc4355d988 (latexenc-find-file-coding-system):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 62974
diff changeset
173 (setq latexenc-main-file (tex-guess-main-file)))))
61909
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
174 ;; 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
175 (if (and latexenc-main-file
68418
0927d6785ca7 (latexenc-find-file-coding-system): Make sure latexenc-main-file is
Eli Zaretskii <eliz@gnu.org>
parents: 68356
diff changeset
176 (file-regular-p latexenc-main-file)
61909
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
177 (file-readable-p latexenc-main-file))
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
178 (let* ((latexenc-dont-use-tex-guess-main-file-flag t)
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
179 (latexenc-dont-use-TeX-master-flag t)
62974
ecfed70e0c5c (latexenc-find-file-coding-system): Don't inherit the EOL part of the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 62398
diff changeset
180 (latexenc-main-buffer
ecfed70e0c5c (latexenc-find-file-coding-system): Don't inherit the EOL part of the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 62398
diff changeset
181 (find-file-noselect latexenc-main-file t)))
ecfed70e0c5c (latexenc-find-file-coding-system): Don't inherit the EOL part of the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 62398
diff changeset
182 (coding-system-base ;Disregard the EOL part of the CS.
ecfed70e0c5c (latexenc-find-file-coding-system): Don't inherit the EOL part of the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 62398
diff changeset
183 (with-current-buffer latexenc-main-buffer
ecfed70e0c5c (latexenc-find-file-coding-system): Don't inherit the EOL part of the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 62398
diff changeset
184 (or coding-system-for-write buffer-file-coding-system))))
61909
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
185 'undecided))))
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
186 'undecided))
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
187
62398
d0d78600444a Add page marker to force the "Local Variables:" string out of the last page.
Juanma Barranquero <lekktu@gmail.com>
parents: 62243
diff changeset
188
61909
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
189 (provide 'latexenc)
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
190
61920
290ff04b090e Add arch tagline
Miles Bader <miles@gnu.org>
parents: 61909
diff changeset
191 ;; arch-tag: f971bc3e-1fec-4609-8f2f-73dd41ab22e1
61909
b5cd4f1a1855 Initial revision.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
192 ;;; latexenc.el ends here