SHA256
1
0
forked from pool/emacs-auctex
emacs-auctex/utf8-names-a8ea1273.patch

224 lines
9.3 KiB
Diff

Based on a8ea1273fd95da5702fe95ad3f41d151b621bc72 Mon Sep 17 00:00:00 2001
From: Ikumi Keita <ikumi@ikumi.que.jp>
Date: Mon, 28 May 2018 14:39:26 +0900
Subject: [PATCH] Accept non-ascii file name in accord with change in TL 2018
* tex.el (TeX-expand-list-builtin): Add new entry %T. Same as %t,
except to enclose with \detokenize{} for non UTF-8 LaTeX when \input
is supplmented.
Adjust the entries %` and %' so that \input is supplemented only when
any TeX code is present between them and leave the bind to
`TeX-command-text' for later examination.
The bind to `TeX-command-pos' is no longer retained.
(TeX-command-list): Use %T for "LaTeX".
Adjust "TeX" and "AmSTeX" as the same with "LaTeX" in the aspect that
user can supply one's own TeX code, as well as any command line
options, through `TeX-command-extra-options'.
* tex-buf.el (TeX--master-or-region-file-with-extra-quotes): New
function to act as a wrapper of `TeX-master-file' and
`TeX-region-file' inside `TeX-command-expand'.
(TeX-command-expand): Use the above function as the value of `file'
and get rid of tricky temporal overriding of `file' with lambda form.
(TeX-region-create): Make the first line parsing of %&FORMAT
construct, if any, to be valid even for region compilation.
Discard text properties when constructing the content of _region_.tex.
Drop bind check for `buffer-file-coding-system'.
* tests/tex/command-expansion.el (TeX-command-expansion): Reflect the
change that \input is not necessarily supplemented now by %`-%' pair
in `TeX-command-expand'.
---
tex-buf.el | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++----------
tex.el | 38 +++++++++++++++++------------
2 files changed, 88 insertions(+), 28 deletions(-)
--- tex-buf.el
+++ tex-buf.el 2018-07-25 08:47:13.599124117 +0000
@@ -554,12 +554,8 @@ without further expansion."
(let (pat
pos ;;FIXME: Should this be dynamically scoped?
entry TeX-command-text TeX-command-pos
- ;; FIXME: This variable appears to be unused!
- (file `(lambda (&rest args)
- (shell-quote-argument
- (concat (and (stringp TeX-command-pos) TeX-command-pos)
- (apply #',file args)
- (and (stringp TeX-command-pos) TeX-command-pos)))))
+ (orig-file file)
+ (file #'TeX--master-or-region-file-with-extra-quotes)
expansion-res case-fold-search string expansion arguments)
(setq list (cons
(list "%%" (lambda nil
@@ -597,6 +593,47 @@ without further expansion."
(replace-match string t t command)))))
command)
+(defun TeX--master-or-region-file-with-extra-quotes
+ (&optional extension nondirectory ask extra)
+ "Return file name with quote for shell.
+Wrapper for `TeX-master-file' or `TeX-region-file' to be used in
+`TeX-command-expand'.
+It is assumed that `orig-file' has dynamic binding of the value of
+`TeX-master-file' or `TeX-region-file'. Pass EXTENSION, NONDIRECTORY
+and ASK to that function as-is, and arrange the returned file name for
+use with command shell.
+Enclose the file name with space within quotes `\"' first when
+\" \\input\" is supplemented (indicated by dynamically binded
+variable `TeX-command-text' having string value.)
+Enclose the file name within \\detokenize{} when the following three
+conditions are met:
+1. compiling with standard (pdf)LaTeX or upLaTeX
+2. \" \\input\" is supplemented
+3. EXTRA is non-nil. (default when expanding \"%T\")"
+ (shell-quote-argument
+ (let* ((raw (funcall orig-file extension nondirectory ask))
+ ;; String `TeX-command-text' means that the file name is
+ ;; given through \input command.
+ (quote-for-space (if (and (stringp TeX-command-text)
+ (string-match " " raw))
+ "\"" "")))
+ (format
+ (if (and extra
+ (stringp TeX-command-text)
+ (memq major-mode '(latex-mode doctex-mode))
+ (memq TeX-engine '(default uptex)))
+ ;; Since TeXLive 2018, the default encoding for LaTeX
+ ;; files has been changed to UTF-8 if used with
+ ;; classic TeX or pdfTeX. I.e.,
+ ;; \usepackage[utf8]{inputenc} is enabled by default
+ ;; in (pdf)latex.
+ ;; c.f. LaTeX News issue 28
+ ;; Due to this change, \detokenize is required to
+ ;; recognize non-ascii characters in the file name
+ ;; when \input precedes.
+ "\\detokenize{ %s }" "%s")
+ (concat quote-for-space raw quote-for-space)))))
+
(defun TeX-check-files (derived originals extensions)
"Check if DERIVED is newer than any of the ORIGINALS.
Try each original with each member of EXTENSIONS, in all directories
@@ -2104,8 +2141,10 @@ original file."
(if (not (re-search-forward TeX-header-end nil t))
""
(re-search-forward "[\r\n]" nil t)
- (buffer-substring (point-min) (point)))))))))
+ (buffer-substring-no-properties
+ (point-min) (point)))))))))
(header-offset 0)
+ first-line
;; We search for the trailer from the master file, if it is
;; not present in the region.
(trailer-offset 0)
@@ -2125,21 +2164,36 @@ original file."
;;(beginning-of-line 1)
(re-search-backward "[\r\n]" nil t)
(setq trailer-offset (TeX-current-offset))
- (buffer-substring (point) (point-max))))))))))
+ (buffer-substring-no-properties
+ (point) (point-max))))))))))
;; file name should be relative to master
(setq original (TeX-quote-filename (file-relative-name
original (TeX-master-directory)))
master-name (TeX-quote-filename master-name))
+
+ ;; If the first line begins with "%&", put that line separately on
+ ;; the very first line of the region file so that the first line
+ ;; parsing will work.
+ (setq first-line (if (and (> (length header) 1)
+ (string= (substring header 0 2) "%&"))
+ ;; This would work even if header has no newline.
+ (substring header 0 (string-match "\n" header))
+ ""))
+ (unless (string= first-line "")
+ ;; Remove first-line from header.
+ (setq header (substring header (length first-line)))
+ (setq first-line (concat first-line "\n")))
+
(with-current-buffer file-buffer
(setq buffer-read-only t
buffer-undo-list t)
(setq original-content (buffer-string))
(let ((inhibit-read-only t))
(erase-buffer)
- (when (boundp 'buffer-file-coding-system)
- (setq buffer-file-coding-system
- (with-current-buffer master-buffer buffer-file-coding-system)))
- (insert "\\message{ !name(" master-name ")}"
+ (setq buffer-file-coding-system
+ (with-current-buffer master-buffer buffer-file-coding-system))
+ (insert first-line
+ "\\message{ !name(" master-name ")}"
header
TeX-region-extra
"\n\\message{ !name(" original ") !offset(")
--- tex.el
+++ tex.el 2018-07-25 08:47:13.599124117 +0000
@@ -121,10 +121,10 @@ If nil, none is specified."
;; `TeX-expand-list-builtin' for a description of the % escapes
(defcustom TeX-command-list
- '(("TeX" "%(PDF)%(tex) %(file-line-error) %(extraopts) %`%S%(PDFout)%(mode)%' %t"
+ '(("TeX" "%(PDF)%(tex) %(file-line-error) %`%(extraopts) %S%(PDFout)%(mode)%' %t"
TeX-run-TeX nil
(plain-tex-mode ams-tex-mode texinfo-mode) :help "Run plain TeX")
- ("LaTeX" "%`%l%(mode)%' %t"
+ ("LaTeX" "%`%l%(mode)%' %T"
TeX-run-TeX nil
(latex-mode doctex-mode) :help "Run LaTeX")
;; Not part of standard TeX.
@@ -132,7 +132,7 @@ If nil, none is specified."
(texinfo-mode) :help "Run Makeinfo with Info output")
("Makeinfo HTML" "makeinfo %(extraopts) --html %t" TeX-run-compile nil
(texinfo-mode) :help "Run Makeinfo with HTML output")
- ("AmSTeX" "amstex %(PDFout) %(extraopts) %`%S%(mode)%' %t"
+ ("AmSTeX" "amstex %(PDFout) %`%(extraopts) %S%(mode)%' %t"
TeX-run-TeX nil (ams-tex-mode) :help "Run AMSTeX")
;; support for ConTeXt --pg
;; first version of ConTeXt to support nonstopmode: 2003.2.10
@@ -503,8 +503,19 @@ string."
;; `file' means to call `TeX-master-file' or `TeX-region-file'
("%s" file nil t)
("%t" file t t)
+ ;; If any TeX codes appear in the interval between %` and %', move
+ ;; all of them after the interval and supplement " \input". The
+ ;; appearance is marked by leaving the bind to `TeX-command-text'
+ ;; with the TeX codes.
+ ;; Rule:
+ ;; 1. %` and %' must appear in pair.
+ ;; 2. %` and %' must not appear more than once in one command
+ ;; line string (including the results of %-expansion).
+ ;; 3. Each TeX codes between %` and %' must be enclosed in
+ ;; double quotes and preceded by a space.
("%`" (lambda nil
- (setq TeX-command-pos t TeX-command-text "")))
+ (setq TeX-command-pos t TeX-command-text nil)
+ ""))
(" \"\\" (lambda nil
(if (eq TeX-command-pos t)
(setq TeX-command-pos pos
@@ -528,18 +539,13 @@ string."
TeX-command-pos t)
(setq pos (1+ pos)))))
("%'" (lambda nil
- (prog1
- (if (stringp TeX-command-text)
- (progn
- (setq pos (+ pos (length TeX-command-text) 9)
- TeX-command-pos
- (and (string-match " "
- (funcall file t t))
- "\""))
- (concat TeX-command-text " \"\\input\""))
- (setq TeX-command-pos nil)
- "")
- (setq TeX-command-text nil))))
+ (setq TeX-command-pos nil)
+ (if (stringp TeX-command-text)
+ (progn
+ (setq pos (+ pos (length TeX-command-text) 9))
+ (concat TeX-command-text " \"\\input\""))
+ "")))
+ ("%T" TeX--master-or-region-file-with-extra-quotes t t nil t)
("%n" TeX-current-line)
("%d" file "dvi" t)
("%f" file "ps" t)