Commit 14cb9d7b authored by Stefan Monnier's avatar Stefan Monnier

(latexenc-find-file-coding-system): Don't inherit the EOL part of the

coding-system from the tex-main buffer.  Fit within 80 columns.
parent 774a1a1a
...@@ -130,46 +130,49 @@ coding system names is determined from `latex-inputenc-coding-alist'." ...@@ -130,46 +130,49 @@ coding system names is determined from `latex-inputenc-coding-alist'."
(throw 'cs t) (throw 'cs t)
(goto-char (match-end 0)))))) (goto-char (match-end 0))))))
(let* ((match (match-string 1)) (let* ((match (match-string 1))
(sym (intern match))) (sym (or (latexenc-inputenc-to-coding-system match)
(when (latexenc-inputenc-to-coding-system match) (intern match))))
(setq sym (latexenc-inputenc-to-coding-system match))) (cond
(when (coding-system-p sym) ((coding-system-p sym) sym)
sym ((and (require 'code-pages nil t) (coding-system-p sym)) sym)
(if (and (require 'code-pages nil t) (coding-system-p sym)) (t 'undecided)))
sym
'undecided)))
;; else try to find it in the master/main file ;; else try to find it in the master/main file
(let (latexenc-main-file) (let ((default-directory (file-name-directory (nth 1 arg-list)))
;; is there a TeX-master or tex-main-file in the local variable section latexenc-main-file)
;; Is there a TeX-master or tex-main-file in the local variables
;; section?
(unless latexenc-dont-use-TeX-master-flag (unless latexenc-dont-use-TeX-master-flag
(goto-char (point-max)) (goto-char (point-max))
(search-backward "\n\^L" (max (- (point-max) 3000) (point-min)) 'move) (search-backward "\n\^L" (max (- (point-max) 3000) (point-min))
'move)
(search-forward "Local Variables:" nil t) (search-forward "Local Variables:" nil t)
(when (re-search-forward "^%+ *\\(TeX-master\\|tex-main-file\\): *\"\\(.+\\)\"" nil t) (when (re-search-forward
(let ((file (concat (file-name-directory (nth 1 arg-list)) (match-string 2)))) "^%+ *\\(TeX-master\\|tex-main-file\\): *\"\\(.+\\)\""
(if (file-exists-p file) nil t)
(setq latexenc-main-file file) (let ((file (match-string 2)))
(if (boundp 'TeX-default-extension) (dolist (ext `("" ,(if (boundp 'TeX-default-extension)
(when (file-exists-p (concat file "." TeX-default-extension)) (concat "." TeX-default-extension)
(setq latexenc-main-file (concat file "." TeX-default-extension))) "")
(dolist (ext '("drv" "dtx" "ltx" "tex")) ".tex" ".ltx" ".dtx" ".drv"))
(if (file-exists-p (concat file "." ext)) (if (and (null latexenc-main-file) ;Stop at first.
(setq latexenc-main-file (concat file "." ext))))))))) (file-exists-p (concat file ext)))
(setq latexenc-main-file (concat file ext)))))))
;; try tex-modes tex-guess-main-file ;; try tex-modes tex-guess-main-file
(when (and (not latexenc-dont-use-tex-guess-main-file-flag) (when (and (not latexenc-dont-use-tex-guess-main-file-flag)
(not latexenc-main-file)) (not latexenc-main-file)
(when (fboundp 'tex-guess-main-file) (fboundp 'tex-guess-main-file))
(let ((tex-start-of-header "\\\\document\\(style\\|class\\)") (let ((tex-start-of-header "\\\\document\\(style\\|class\\)"))
(default-directory (file-name-directory (nth 1 arg-list)))) (setq latexenc-main-file (tex-guess-main-file))))
(setq latexenc-main-file (tex-guess-main-file)))))
;; if we found a master/main file get the coding system from it ;; if we found a master/main file get the coding system from it
(if (and latexenc-main-file (if (and latexenc-main-file
(file-readable-p latexenc-main-file)) (file-readable-p latexenc-main-file))
(let* ((latexenc-dont-use-tex-guess-main-file-flag t) (let* ((latexenc-dont-use-tex-guess-main-file-flag t)
(latexenc-dont-use-TeX-master-flag t) (latexenc-dont-use-TeX-master-flag t)
(latexenc-main-buffer (find-file-noselect latexenc-main-file t))) (latexenc-main-buffer
(or (buffer-local-value 'coding-system-for-write latexenc-main-buffer) (find-file-noselect latexenc-main-file t)))
(buffer-local-value 'buffer-file-coding-system latexenc-main-buffer))) (coding-system-base ;Disregard the EOL part of the CS.
(with-current-buffer latexenc-main-buffer
(or coding-system-for-write buffer-file-coding-system))))
'undecided)))) 'undecided))))
'undecided)) 'undecided))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment