auctex-diffs
[Top][All Lists]
Advanced

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

[AUCTeX-diffs] GNU AUCTeX branch, master, updated. c037cac4163c29776d78f


From: Ikumi Keita
Subject: [AUCTeX-diffs] GNU AUCTeX branch, master, updated. c037cac4163c29776d78f795812d706f67609193
Date: Tue, 23 Mar 2021 12:57:47 -0400 (EDT)

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU AUCTeX".

The branch, master has been updated
       via  c037cac4163c29776d78f795812d706f67609193 (commit)
      from  7ccff10d48639e995f8f2fcfcae6e7265bbcff0d (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit c037cac4163c29776d78f795812d706f67609193
Author: Ikumi Keita <ikumi@ikumi.que.jp>
Date:   Tue Mar 23 21:24:18 2021 +0900

    Prepare for enabling lexical binding in preview.el.in
    
    * tex-buf.el (TeX-region-update):
    * preview.el.in (preview-region, preview-counters)
    (preview--counter-information):
    Turn a piece of advice for `TeX-region-create' into a helper function
    `preview--counter-information', and invoke it at all calls of
    `TeX-region-create'.
    Use `buffer-substring-no-properties' instead of `buffer-substring' to
    save memory usage a bit.
    Simplify code by `TeX-current-offset'.
    
    * tex-buf.el (TeX-region-create):
    * preview.el.in (preview-preamble, preview--skip-preamble-region):
    Turn another advice for `TeX-region-create' into a helper function
    `preview--skip-preamble-region' and call it in `TeX-region-create'.
    
    * tex-buf.el (TeX-region-extra): Move `defcustom' before its new first
    usage.

diff --git a/preview.el.in b/preview.el.in
index c24c1c5..5833b9e 100644
--- a/preview.el.in
+++ b/preview.el.in
@@ -2586,10 +2586,6 @@ to the close hook."
                    (list (preview-active-string ov)))
       (preview-toggle ov t))))
 
-;; The following is a brutal hack.  It relies on `begin' being let to
-;; the start of the interesting area when TeX-region-create is being
-;; called.
-
 (defun preview-counter-find (begin)
   "Fetch the next preceding or next preview-counters property.
 Factored out because of compatibility macros XEmacs would
@@ -2608,20 +2604,20 @@ not use in advice."
             (next-single-char-property-change begin 'preview-counters)
             'preview-counters))))
 
-(defadvice TeX-region-create (around preview-counters)
-  "Write out counter information to region."
-  (let ((TeX-region-extra
-         (concat
-          (and (boundp 'begin)
-               preview-buffer-has-counters
-               (mapconcat
-                #'identity
-                (cons
-                 ""
-                 (preview-counter-find (symbol-value 'begin)))
-                "\\setcounter"))
-          TeX-region-extra)))
-    ad-do-it))
+(defun preview--counter-information (begin)
+  "Return repeated \\setcounter declaration based on point BEGIN.
+If `preview-buffer-has-counters' is non-nil, return string to
+insert into region tex file containing as many
+\\setcounter{COUNTER}{VALUE} as possible built from
+`preview-counters' property near the point BEGIN.  Otherwise,
+return nil."
+  (if preview-buffer-has-counters
+      (mapconcat
+       #'identity
+       (cons
+        ""
+        (preview-counter-find begin))
+       "\\setcounter")))
 
 (defun preview-reinstate-preview (tempdirlist timestamp start end
   image filename &optional counters)
@@ -4017,19 +4013,16 @@ stored in `preview-dumped-alist'."
 (defun preview-region (begin end)
   "Run preview on region between BEGIN and END."
   (interactive "r")
-  (TeX-region-create (TeX-region-file TeX-default-extension)
-                     (buffer-substring begin end)
-                     (if buffer-file-name
-                         (file-name-nondirectory buffer-file-name)
-                       "<none>")
-                     (save-restriction
-                       (widen)
-                       (let ((inhibit-point-motion-hooks t)
-                             (inhibit-field-text-motion t))
-                         (+ (count-lines (point-min) begin)
-                            (save-excursion
-                              (goto-char begin)
-                              (if (bolp) 0 -1))))))
+  (let ((TeX-region-extra
+         ;; Write out counter information to region.
+         (concat (preview--counter-information begin)
+                 TeX-region-extra)))
+    (TeX-region-create (TeX-region-file TeX-default-extension)
+                       (buffer-substring-no-properties begin end)
+                       (if buffer-file-name
+                           (file-name-nondirectory buffer-file-name)
+                         "<none>")
+                       (TeX-current-offset begin)))
   (setq TeX-current-process-region-p t)
   (preview-generate-preview (TeX-region-file)
                             (preview-do-replacements
@@ -4052,18 +4045,20 @@ stored in `preview-dumped-alist'."
 ;; This will fail if the region is to contain just part of the
 ;; preamble -- a bad idea anyhow.
 
-(defadvice TeX-region-create (before preview-preamble preactivate activate)
-  "Skip preamble for the sake of predumped formats."
-  (when (string-match TeX-header-end (ad-get-arg 1))
-    (ad-set-arg 1
-                (prog1 (substring (ad-get-arg 1) (match-end 0))
-                  (ad-set-arg 3
-                              (with-temp-buffer
-                                (insert (substring (ad-get-arg 1)
-                                                   0 (match-end 0)))
-                                (+ (ad-get-arg 3)
-                                   (count-lines (point-min) (point-max))
-                                   (if (bolp) 0 -1))))))))
+(defun preview--skip-preamble-region (region-text region-offset)
+  "Skip preamble for the sake of predumped formats.
+Helper function of `TeX-region-create'.
+
+If REGION-TEXT doesn't contain preamble, it returns nil.
+Otherwise, it returns cons (ALTERED-TEXT . ALTERED-OFFSET) where
+ALTERED-TEXT is REGION-TEXT without the preamble part and
+ALTERED-OFFSET is REGION-OFFSET increased by the number of lines
+of the preamble part of REGION-TEXT."
+  (if (string-match TeX-header-end region-text)
+      (cons (substring region-text (match-end 0))
+            (with-temp-buffer
+              (insert (substring region-text 0 (match-end 0)))
+              (+ region-offset (TeX-current-offset))))))
 
 (defun preview-document ()
   "Run preview on master document."
diff --git a/tex-buf.el b/tex-buf.el
index 9f174f0..419abf8 100644
--- a/tex-buf.el
+++ b/tex-buf.el
@@ -107,6 +107,17 @@ depend on it being positive instead of the entry in 
`TeX-command-list'."
   (TeX-command (TeX-command-query #'TeX-master-file)
                'TeX-master-file override-confirm))
 
+(defcustom TeX-region-extra ""
+  "String to insert in the region file between the header and the text."
+  :group 'TeX-command
+  :type 'string)
+
+;; This was "{\\makeatletter\\gdef\\AucTeX@cite#1[#2]#3{[#3#1#2]}\
+;;           \\gdef\\cite{\\@ifnextchar[{\\AucTeX@cite{, }}\
+;;           {\\AucTeX@cite{}[]}}}\n"
+;; However, that string is inappropriate for plain TeX and ConTeXt.
+;; This needs reconsideration.
+
 (defvar TeX-command-region-begin nil)
 (defvar TeX-command-region-end nil)
 ;; Used for marking the last region.
@@ -164,10 +175,15 @@ pinned region will get unpinned and vice versa."
            (markerp TeX-command-region-begin))
        (TeX-active-mark)
        (TeX-pin-region (region-beginning) (region-end)))
-  (let ((begin (or TeX-command-region-begin (region-beginning)))
-        (end (or TeX-command-region-end (region-end))))
+  (let* ((begin (or TeX-command-region-begin (region-beginning)))
+         (end (or TeX-command-region-end (region-end)))
+         (TeX-region-extra
+         ;; Write out counter information to region.
+         (concat (and (fboundp 'preview--counter-information)
+                      (preview--counter-information begin))
+                 TeX-region-extra)))
     (TeX-region-create (TeX-region-file TeX-default-extension)
-                       (buffer-substring begin end)
+                       (buffer-substring-no-properties begin end)
                        (file-name-nondirectory (buffer-file-name))
                        (TeX-current-offset begin))))
 
@@ -2042,17 +2058,6 @@ The compatibility argument IGNORE is ignored."
 
 ;;; Region File
 
-(defcustom TeX-region-extra ""
-  "String to insert in the region file between the header and the text."
-  :group 'TeX-command
-  :type 'string)
-
-;; This was "{\\makeatletter\\gdef\\AucTeX@cite#1[#2]#3{[#3#1#2]}\
-;;           \\gdef\\cite{\\@ifnextchar[{\\AucTeX@cite{, }}\
-;;           {\\AucTeX@cite{}[]}}}\n"
-;; However, that string is inappropriate for plain TeX and ConTeXt.
-;; This needs reconsideration.
-
 
 (defvar TeX-region-hook nil
   "List of hooks to run before the region file is saved.
@@ -2115,6 +2120,13 @@ that the TeX header and trailer information is also 
included.
 
 The OFFSET is used to provide the debugger with information about the
 original file."
+  (if (fboundp 'preview--skip-preamble-region)
+      (let ((temp (preview--skip-preamble-region region offset)))
+        (if temp
+            ;; Skip preamble for the sake of predumped formats.
+            (setq region (car temp)
+                  offset (cdr temp)))))
+
   (let* (;; We shift buffer a lot, so we must keep track of the buffer
          ;; local variables.
          (header-end TeX-header-end)

-----------------------------------------------------------------------

Summary of changes:
 preview.el.in | 81 ++++++++++++++++++++++++++++-------------------------------
 tex-buf.el    | 40 ++++++++++++++++++-----------
 2 files changed, 64 insertions(+), 57 deletions(-)


hooks/post-receive
-- 
GNU AUCTeX



reply via email to

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