120 |
(save-excursion |
(save-excursion |
121 |
;; try to find the coding system in this file |
;; try to find the coding system in this file |
122 |
(goto-char (point-min)) |
(goto-char (point-min)) |
123 |
(if (or |
(if (catch 'cs |
124 |
(re-search-forward "^[^%\n]*\\\\inputencoding{\\(.*\\)}" nil t) |
(let ((case-fold-search nil)) |
125 |
(re-search-forward "^[^%\n]*\\\\usepackage\\[\\(.*\\)\\]{inputenc}" nil t)) |
(while (search-forward "inputenc" nil t) |
126 |
(let* ((match (match-string 1)) |
(goto-char (match-beginning 0)) |
127 |
(sym (intern match))) |
(beginning-of-line) |
128 |
(when (latexenc-inputenc-to-coding-system match) |
(if (or (looking-at "[^%\n]*\\\\usepackage\\[\\([^]]*\\)\\]{\\([^}]*,\\)?inputenc\\(,[^}]*\\)?}") |
129 |
(setq sym (latexenc-inputenc-to-coding-system match)) |
(looking-at "[^%\n]*\\\\inputencoding{\\([^}]*\\)}")) |
130 |
(when (coding-system-p sym) |
(throw 'cs t) |
131 |
sym |
(goto-char (match-end 0)))))) |
132 |
(if (and (require 'code-pages nil t) (coding-system-p sym)) |
(let* ((match (match-string 1)) |
133 |
sym |
(sym (intern match))) |
134 |
'undecided)))) |
(when (latexenc-inputenc-to-coding-system match) |
135 |
|
(setq sym (latexenc-inputenc-to-coding-system match))) |
136 |
|
(when (coding-system-p sym) |
137 |
|
sym |
138 |
|
(if (and (require 'code-pages nil t) (coding-system-p sym)) |
139 |
|
sym |
140 |
|
'undecided))) |
141 |
;; else try to find it in the master/main file |
;; else try to find it in the master/main file |
142 |
(let (latexenc-main-file) |
(let (latexenc-main-file) |
143 |
;; is there a TeX-master or tex-main-file in the local variable section |
;; is there a TeX-master or tex-main-file in the local variable section |
144 |
(unless latexenc-dont-use-TeX-master-flag |
(unless latexenc-dont-use-TeX-master-flag |
145 |
(goto-char (point-max)) |
(goto-char (point-max)) |
146 |
(when (re-search-backward "^%+ *\\(TeX-master\\|tex-main-file\\): *\"\\(.+\\)\"" nil t) |
(search-backward "\n\^L" (max (- (point-max) 3000) (point-min)) 'move) |
147 |
|
(search-forward "Local Variables:" nil t) |
148 |
|
(when (re-search-forward "^%+ *\\(TeX-master\\|tex-main-file\\): *\"\\(.+\\)\"" nil t) |
149 |
(let ((file (concat (file-name-directory (nth 1 arg-list)) (match-string 2)))) |
(let ((file (concat (file-name-directory (nth 1 arg-list)) (match-string 2)))) |
150 |
(if (file-exists-p file) |
(if (file-exists-p file) |
151 |
(setq latexenc-main-file file) |
(setq latexenc-main-file file) |