comparison lisp/international/latexenc.el @ 62243:68b153fd6cd9

(latexenc-find-file-coding-system): Avoid `re-search-forward' when looking for input encoding because of speed and safety. Better regular expressions for recognizing input encoding. Limit a search for TeX-master/tex-main-file to the local variable section.
author Lute Kamstra <lute@gnu.org>
date Wed, 11 May 2005 23:04:08 +0000
parents 935929fcdb78
children d0d78600444a
comparison
equal deleted inserted replaced
62242:cce9501aab6e 62243:68b153fd6cd9
118 coding system names is determined from `latex-inputenc-coding-alist'." 118 coding system names is determined from `latex-inputenc-coding-alist'."
119 (if (eq (car arg-list) 'insert-file-contents) 119 (if (eq (car arg-list) 'insert-file-contents)
120 (save-excursion 120 (save-excursion
121 ;; try to find the coding system in this file 121 ;; try to find the coding system in this file
122 (goto-char (point-min)) 122 (goto-char (point-min))
123 (if (or 123 (if (catch 'cs
124 (re-search-forward "^[^%\n]*\\\\inputencoding{\\(.*\\)}" nil t) 124 (let ((case-fold-search nil))
125 (re-search-forward "^[^%\n]*\\\\usepackage\\[\\(.*\\)\\]{inputenc}" nil t)) 125 (while (search-forward "inputenc" nil t)
126 (let* ((match (match-string 1)) 126 (goto-char (match-beginning 0))
127 (sym (intern match))) 127 (beginning-of-line)
128 (when (latexenc-inputenc-to-coding-system match) 128 (if (or (looking-at "[^%\n]*\\\\usepackage\\[\\([^]]*\\)\\]{\\([^}]*,\\)?inputenc\\(,[^}]*\\)?}")
129 (setq sym (latexenc-inputenc-to-coding-system match)) 129 (looking-at "[^%\n]*\\\\inputencoding{\\([^}]*\\)}"))
130 (when (coding-system-p sym) 130 (throw 'cs t)
131 sym 131 (goto-char (match-end 0))))))
132 (if (and (require 'code-pages nil t) (coding-system-p sym)) 132 (let* ((match (match-string 1))
133 sym 133 (sym (intern match)))
134 'undecided)))) 134 (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)))
135 ;; else try to find it in the master/main file 141 ;; else try to find it in the master/main file
136 (let (latexenc-main-file) 142 (let (latexenc-main-file)
137 ;; is there a TeX-master or tex-main-file in the local variable section 143 ;; is there a TeX-master or tex-main-file in the local variable section
138 (unless latexenc-dont-use-TeX-master-flag 144 (unless latexenc-dont-use-TeX-master-flag
139 (goto-char (point-max)) 145 (goto-char (point-max))
140 (when (re-search-backward "^%+ *\\(TeX-master\\|tex-main-file\\): *\"\\(.+\\)\"" nil t) 146 (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)
141 (let ((file (concat (file-name-directory (nth 1 arg-list)) (match-string 2)))) 149 (let ((file (concat (file-name-directory (nth 1 arg-list)) (match-string 2))))
142 (if (file-exists-p file) 150 (if (file-exists-p file)
143 (setq latexenc-main-file file) 151 (setq latexenc-main-file file)
144 (if (boundp 'TeX-default-extension) 152 (if (boundp 'TeX-default-extension)
145 (when (file-exists-p (concat file "." TeX-default-extension)) 153 (when (file-exists-p (concat file "." TeX-default-extension))