aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLute Kamstra2005-05-11 23:04:08 +0000
committerLute Kamstra2005-05-11 23:04:08 +0000
commit4b0fcb5dcf999e50f61ce307e1c701f9b2b3e90a (patch)
treea5a055b1070eb46a491aa81ba61ba6858f68366b
parent8cec35c42eefe184f694c62f5d58b7fd6009141c (diff)
downloademacs-4b0fcb5dcf999e50f61ce307e1c701f9b2b3e90a.tar.gz
emacs-4b0fcb5dcf999e50f61ce307e1c701f9b2b3e90a.zip
(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.
-rw-r--r--lisp/international/latexenc.el34
1 files changed, 21 insertions, 13 deletions
diff --git a/lisp/international/latexenc.el b/lisp/international/latexenc.el
index 1fd04b55919..39acbb33dfd 100644
--- a/lisp/international/latexenc.el
+++ b/lisp/international/latexenc.el
@@ -120,24 +120,32 @@ coding system names is determined from `latex-inputenc-coding-alist'."
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)