auctex-devel
[Top][All Lists]
Advanced

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

Re: Onwards to lexical binding (attempt 1)


From: Tassilo Horn
Subject: Re: Onwards to lexical binding (attempt 1)
Date: Fri, 11 Sep 2020 09:39:44 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Ikumi Keita <ikumi@ikumi.que.jp> writes:

>>>> Here's the patch which was empty yesterday where I actually do
>>>> that.
>>> 
>>> Thanks. I'll test it later, probably tommorow.
>
>> Great, thanks!
>
> It doesn't work for region preview. After Setting region on circ.tex
> and C-c C-p C-r, I get error and in process buffer I find Running
> `Preview-PDF2DSC' with ``pdf2dsc circ.pdf
> circ.prv/tmpSYCDuG/preview.dsc'' . Thus preview-latex provides
> "master" file name "circ.pdf" rather than "_region_.pdf" for pdf2dsc
> for this case.
>
> I think `preview-region' should bind TeX-current-process-region-p
> permanently by `setq', not `let', so that TeX-active-master returns
> intended file name even in process sentinels.

Indeed, below is a patch which does that.  It works for me as far as I
have tested.  If more testing doesn't reveal any blocker, I'm slightly
leaning towards doing that change.  IMHO, it makes the code a bit
easier to understand.

I noticed some other (unrelated) strange things:

1. My preview.el was terribly outdated.  It seems it's not re-generated
from preview.el.in on every "make" invocation.  I needed to delete it to
be re-generated...

2. The first preview invocation errors out with:

--8<---------------cut here---------------start------------->8---
[1{/var/lib/texmf/fonts/map/pdftex/updmap/pdftex.map}]  !name(2.tex) 
!offset(47)  )
(see the transcript file for additional 
information)</usr/share/texmf-dist/fonts/type1/public/amsfonts/cm/cmex10.pfb></usr/share/texmf-dist/fonts/type1/public/amsfonts/cm/cmmi10.pfb></usr/share/texmf-dist/fonts/type1/public/amsfonts/cm/cmr10.pfb>
Output written on _region_.pdf (1 page, 23275 bytes).
SyncTeX written on _region_.synctex.gz.
Transcript written on _region_.log.

TeX Output exited as expected with code 1 at Fri Sep 11 09:28:23
Running `Preview-DviPS' with ``dvips -Pwww _region_.dvi -o 
_region_.prv/tmpLKkFSa/preview.ps''
Parser: End of Preview snippet 1 unexpected

Preview-DviPS killed at Fri Sep 11 09:28:23
LaTeX: End of Preview snippet 1 unexpected
--8<---------------cut here---------------end--------------->8---

Trying again, it works and previews are displayed.  That also happens on
master.

Bye,
Tassilo

diff --git a/preview.el.in b/preview.el.in
index c14e4900..6d0b9789 100644
--- a/preview.el.in
+++ b/preview.el.in
@@ -3671,8 +3671,7 @@ The fourth value is the transparent border thickness."
         (colors (preview-dvipng-color-string preview-colors res))
         (command (with-current-buffer TeX-command-buffer
                    (prog1
-                       (concat (TeX-command-expand preview-dvipng-command
-                                                   (car file))
+                       (concat (TeX-command-expand preview-dvipng-command)
                                " " colors resolution)
                      (setq tempdir TeX-active-tempdir))))
         (name "Preview-DviPNG"))
@@ -3710,8 +3709,7 @@ If FAST is set, do a fast conversion."
                    (prog1
                        (TeX-command-expand (if fast
                                                preview-fast-dvips-command
-                                             preview-dvips-command)
-                                           (car file))
+                                             preview-dvips-command))
                      (setq tempdir TeX-active-tempdir))))
         (name "Preview-DviPS"))
     (setq TeX-active-tempdir tempdir)
@@ -3751,8 +3749,7 @@ If FAST is set, do a fast conversion."
         pdfsource
         (command (with-current-buffer TeX-command-buffer
                    (prog1
-                       (TeX-command-expand preview-pdf2dsc-command
-                                           (car file))
+                       (TeX-command-expand preview-pdf2dsc-command)
                      (setq tempdir TeX-active-tempdir
                            pdfsource (funcall (car file) "pdf" t)))))
         (name "Preview-PDF2DSC"))
@@ -3930,8 +3927,7 @@ If FORMAT-CONS is non-nil, a previous format may get 
reused."
         (master-file (expand-file-name (TeX-master-file t)))
         (command (preview-do-replacements
                   (TeX-command-expand
-                   (preview-string-expand preview-LaTeX-command)
-                   'TeX-master-file)
+                   (preview-string-expand preview-LaTeX-command))
                   preview-dump-replacements))
         (preview-auto-cache-preamble nil))
     (unless (and (consp (cdr format-cons))
@@ -4003,11 +3999,11 @@ stored in `preview-dumped-alist'."
                            (save-excursion
                              (goto-char begin)
                              (if (bolp) 0 -1))))))
+  (setq TeX-current-process-region-p t)
   (preview-generate-preview t (TeX-region-file)
                            (preview-do-replacements
                             (TeX-command-expand
-                             (preview-string-expand preview-LaTeX-command)
-                             'TeX-region-file)
+                             (preview-string-expand preview-LaTeX-command))
                             preview-LaTeX-command-replacements)))
 
 (defun preview-buffer ()
@@ -4046,8 +4042,7 @@ stored in `preview-dumped-alist'."
    nil (TeX-master-file)
    (preview-do-replacements
     (TeX-command-expand
-     (preview-string-expand preview-LaTeX-command)
-     'TeX-master-file)
+     (preview-string-expand preview-LaTeX-command))
     preview-LaTeX-command-replacements)))
 
 (defun preview-environment (count)
@@ -4090,9 +4085,7 @@ It returns the started process."
   (let* ((geometry (preview-get-geometry))
         (commandbuff (current-buffer))
         (pr-file (cons
-                  (if TeX-current-process-region-p
-                      'TeX-region-file
-                    'TeX-master-file)
+                  'TeX-active-master
                   (file-name-nondirectory file)))
         (master (TeX-master-file))
         (master-file (expand-file-name master))
diff --git a/tests/japanese/preview-latex.el b/tests/japanese/preview-latex.el
index 41907dfd..5ca3d968 100644
--- a/tests/japanese/preview-latex.el
+++ b/tests/japanese/preview-latex.el
@@ -228,8 +228,7 @@ String encoded in `shift_jis' can have regexp meta 
characters in it."
          (setq process (TeX-inline-preview-internal
                         (preview-do-replacements
                          (TeX-command-expand
-                          (preview-string-expand preview-LaTeX-command)
-                          'TeX-master-file)
+                          (preview-string-expand preview-LaTeX-command))
                          preview-LaTeX-command-replacements)
                         dummyfile '(nil . nil) (current-buffer)
                         '(nil . (t . t)) dummyfile '(nil nil nil)))
@@ -263,8 +262,7 @@ String encoded in `shift_jis' can have regexp meta 
characters in it."
          (setq process (TeX-inline-preview-internal
                         (preview-do-replacements
                          (TeX-command-expand
-                          (preview-string-expand preview-LaTeX-command)
-                          'TeX-master-file)
+                          (preview-string-expand preview-LaTeX-command))
                          preview-dump-replacements)
                         dummyfile '(nil . nil) (current-buffer)
                         nil dummyfile '(nil nil nil)))
diff --git a/tests/tex/command-expansion.el b/tests/tex/command-expansion.el
index 0de5831c..bb5c7d49 100644
--- a/tests/tex/command-expansion.el
+++ b/tests/tex/command-expansion.el
@@ -29,8 +29,7 @@
   (should (string=
            (let ((TeX-command-list
                  (list (cons "Test" '("%%%% %`%'" TeX-run-command t t)))))
-            (TeX-command-expand (nth 1 (assoc "Test" TeX-command-list))
-                                'TeX-master-file))
+            (TeX-command-expand (nth 1 (assoc "Test" TeX-command-list))))
            "%% ")))
 
 (ert-deftest TeX-command-expansion-errors ()
@@ -39,7 +38,7 @@
    ;; This error is actually thrown by `TeX-engine-in-engine-alist', but we 
want
    ;; to be sure that `TeX-command-expand' fails when the engine is not valid.
    (let ((TeX-engine 'non-existing-engine))
-     (TeX-command-expand "%l" 'TeX-master-file))))
+     (TeX-command-expand "%l"))))
 
 (ert-deftest TeX-view-command-raw-errors ()
   "Tests to trigger errors in `TeX-view-command-raw'."
@@ -94,7 +93,7 @@
                 (TeX-engine 'default)
                 (TeX-master "/tmp/abc")
                 (TeX-command-extra-options " \"\\foo\""))
-            (TeX-command-expand "%`%(extraopts)%' %T" #'TeX-master-file))
+            (TeX-command-expand "%`%(extraopts)%' %T"))
           " \"\\foo\" \"\\input\" \\\\detokenize\\{\\ abc.tex\\ \\}")))
 
 (ert-deftest TeX-command-expand-skip-file-name ()
@@ -108,24 +107,24 @@ See 
<https://lists.gnu.org/r/bug-auctex/2014-08/msg00012.html>."
   (let ((TeX-master "abc-def")
        (TeX-expand-list '(("-" (lambda () ":")))))
     (should (string=
-            (TeX-command-expand "%s" #'TeX-master-file)
+            (TeX-command-expand "%s")
             TeX-master))
     (should (string=
-            (TeX-command-expand "%t" #'TeX-master-file)
+            (TeX-command-expand "%t")
             (TeX-master-file "tex" t)))
     (should (string=
-            (TeX-command-expand "%T" #'TeX-master-file)
+            (TeX-command-expand "%T")
             (TeX-master-file "tex" t)))
     (should (string=
-            (TeX-command-expand "%d" #'TeX-master-file)
+            (TeX-command-expand "%d")
             (TeX-master-file "dvi" t)))
     (should (string=
-            (TeX-command-expand "%f" #'TeX-master-file)
+            (TeX-command-expand "%f")
             (TeX-master-file "ps" t)))
     ;; The expander of "%o" does not yet cater for this possible endless
     ;; loop.
     ;; (should (string=
-    ;;              (TeX-command-expand "%o" #'TeX-master-file)
+    ;;              (TeX-command-expand "%o")
     ;;              (TeX-master-file "pdf" t)))
     ))
 
@@ -138,11 +137,11 @@ See 
<https://lists.gnu.org/r/bug-auctex/2014-08/msg00012.html>."
        TeX-current-process-region-p)
     (setq TeX-current-process-region-p nil)
     (should (string=
-            (TeX-command-expand "%s" #'TeX-active-master)
+            (TeX-command-expand "%s")
             TeX-master))
     (setq TeX-current-process-region-p t)
     (should (string=
-            (TeX-command-expand "%s" #'TeX-active-master)
+            (TeX-command-expand "%s")
             TeX-region))))
 
 ;;; command-expansion.el ends here
diff --git a/tex-buf.el b/tex-buf.el
index 975c6fc9..b9d90858 100644
--- a/tex-buf.el
+++ b/tex-buf.el
@@ -494,8 +494,7 @@ been set."
   ;; of point in the region file so that forward search works.
   (if (string= name "View") (TeX-region-update-point))
 
-  (let ((command (TeX-command-expand (nth 1 (assoc name TeX-command-list))
-                                    file-fn))
+  (let ((command (TeX-command-expand (nth 1 (assoc name TeX-command-list))))
        (hook (nth 2 (assoc name TeX-command-list)))
        (confirm (if override-confirm
                     (> (prefix-numeric-value override-confirm) 0)
@@ -535,8 +534,8 @@ remember to add /Library/TeX/texbin/ to your PATH"
       (TeX-process-set-variable file 'TeX-command-next TeX-command-Show)
       (funcall hook name command file))))
 
-(defun TeX-command-expand (command file-fn &optional list)
-  "Expand COMMAND for FILE as described in LIST.
+(defun TeX-command-expand (command &optional list)
+  "Expand COMMAND for `TeX-active-master' as described in LIST.
 LIST default to `TeX-expand-list'.  As a special exception,
 `%%' can be used to produce a single `%' sign in the output
 without further expansion."
@@ -551,40 +550,32 @@ without further expansion."
                             "%"))
                (or list (TeX-expand-list)))
          pat (regexp-opt (mapcar #'car list)))
-    ;; `TeX-command-expand' is called with `file-fn' argument being one
-    ;; of `TeX-master-file', `TeX-region-file' and
-    ;; `TeX-active-master'.  The return value of these functions
-    ;; sometimes needs suitable "decorations" for an argument for
-    ;; underlying shell or latex executable, or both, when the
-    ;; relavant file-fn name involves some special characters such as
-    ;; space and multibyte characters.  Hence embed that function in a
-    ;; template prepared for that purpose.
-    (setq file-fn #'TeX--master-or-region-file-with-extra-quotes)
-    (while (setq TeX-expand-pos (string-match pat TeX-expand-command 
TeX-expand-pos))
-      (setq string (match-string 0 TeX-expand-command)
-           entry (assoc string list)
-           expansion (car (cdr entry)) ;Second element
-           arguments (cdr (cdr entry)) ;Remaining elements
-           string (save-match-data
-                    (cond
-                      ((memq expansion (list 'TeX-active-master
-                                             #'TeX-active-master))
-                       (let ((res (apply file-fn arguments)))
-                         ;; Advance past the file name in order to
-                         ;; prevent expanding any substring of it.
-                         (setq TeX-expand-pos
-                               (+ TeX-expand-pos (length res)))
-                         res))
-                      ((functionp expansion)
-                       (apply expansion arguments))
-                     ((boundp expansion)
-                       (apply (symbol-value expansion) arguments))
-                     (t
-                      (error "Nonexpansion %s" expansion)))))
-      (if (stringp string)
-         (setq TeX-expand-command
-               (replace-match string t t TeX-expand-command))))
-    TeX-expand-command))
+    (let ((file-fn #'TeX--master-or-region-file-with-extra-quotes))
+      (while (setq TeX-expand-pos (string-match pat TeX-expand-command 
TeX-expand-pos))
+        (setq string (match-string 0 TeX-expand-command)
+             entry (assoc string list)
+             expansion (car (cdr entry)) ;Second element
+             arguments (cdr (cdr entry)) ;Remaining elements
+             string (save-match-data
+                      (cond
+                        ((memq expansion (list 'TeX-active-master
+                                               #'TeX-active-master))
+                         (let ((res (apply file-fn arguments)))
+                           ;; Advance past the file name in order to
+                           ;; prevent expanding any substring of it.
+                           (setq TeX-expand-pos
+                                 (+ TeX-expand-pos (length res)))
+                           res))
+                        ((functionp expansion)
+                         (apply expansion arguments))
+                       ((boundp expansion)
+                         (apply (symbol-value expansion) arguments))
+                       (t
+                        (error "Nonexpansion %s" expansion)))))
+        (if (stringp string)
+           (setq TeX-expand-command
+                 (replace-match string t t TeX-expand-command))))
+      TeX-expand-command)))
 
 (defun TeX--master-or-region-file-with-extra-quotes
     (&optional extension nondirectory ask extra)
diff --git a/tex.el b/tex.el
index 4719eb49..ce31831e 100644
--- a/tex.el
+++ b/tex.el
@@ -1567,11 +1567,11 @@ predicates are true, nil otherwise."
     (unless (or (null executable)
                (cond
                 ((stringp executable)
-                 (executable-find (TeX-command-expand executable nil)))
+                 (executable-find (TeX-command-expand executable)))
                 ((listp executable)
                  (catch 'notfound
                    (dolist (exec executable t)
-                     (unless (executable-find (TeX-command-expand exec nil))
+                     (unless (executable-find (TeX-command-expand exec))
                        (throw 'notfound nil)))))))
       (error (format "Cannot find %S viewer.  \
 Select another one in `TeX-view-program-selection'" viewer)))

reply via email to

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