emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/auctex a8ea127 29/48: Accept non-ascii file name in acc


From: Tassilo Horn
Subject: [elpa] externals/auctex a8ea127 29/48: Accept non-ascii file name in accord with change in TL 2018
Date: Sun, 16 Sep 2018 01:47:24 -0400 (EDT)

branch: externals/auctex
commit a8ea1273fd95da5702fe95ad3f41d151b621bc72
Author: Ikumi Keita <address@hidden>
Commit: Ikumi Keita <address@hidden>

    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'.
---
 tests/tex/command-expansion.el |  4 +--
 tex-buf.el                     | 78 +++++++++++++++++++++++++++++++++++-------
 tex.el                         | 38 +++++++++++---------
 3 files changed, 90 insertions(+), 30 deletions(-)

diff --git a/tests/tex/command-expansion.el b/tests/tex/command-expansion.el
index 91b3235..b35b8f3 100644
--- a/tests/tex/command-expansion.el
+++ b/tests/tex/command-expansion.el
@@ -1,6 +1,6 @@
 ;;; command-expansion.el --- tests for TeX command expansion
 
-;; Copyright (C) 2014 Free Software Foundation, Inc.
+;; Copyright (C) 2014, 2018 Free Software Foundation, Inc.
 
 ;; This file is part of AUCTeX.
 
@@ -31,7 +31,7 @@
                  (list (cons "Test" '("%%%% %`%'" TeX-run-command t t)))))
             (TeX-command-expand (nth 1 (assoc "Test" TeX-command-list))
                                 'TeX-master-file))
-           "%%  \"\\input\"")))
+           "%% ")))
 
 (ert-deftest TeX-command-expansion-errors ()
   "Test error handling in `TeX-command-expand'."
diff --git a/tex-buf.el b/tex-buf.el
index eed31f2..aec2579 100644
--- a/tex-buf.el
+++ b/tex-buf.el
@@ -542,12 +542,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
@@ -585,6 +581,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
@@ -2123,8 +2160,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)
@@ -2144,21 +2183,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(")
diff --git a/tex.el b/tex.el
index f7955f3..63ae293 100644
--- a/tex.el
+++ b/tex.el
@@ -116,10 +116,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.
@@ -127,7 +127,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
@@ -498,8 +498,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
@@ -523,18 +534,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)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]