[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] scratch/auctex-lexbind c037cac 02/13: Prepare for enabling lexica
From: |
Stefan Monnier |
Subject: |
[elpa] scratch/auctex-lexbind c037cac 02/13: Prepare for enabling lexical binding in preview.el.in |
Date: |
Tue, 23 Mar 2021 13:56:54 -0400 (EDT) |
branch: scratch/auctex-lexbind
commit c037cac4163c29776d78f795812d706f67609193
Author: Ikumi Keita <ikumi@ikumi.que.jp>
Commit: Ikumi Keita <ikumi@ikumi.que.jp>
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.
---
preview.el.in | 81 ++++++++++++++++++++++++++++-------------------------------
tex-buf.el | 40 ++++++++++++++++++-----------
2 files changed, 64 insertions(+), 57 deletions(-)
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)
- [elpa] branch scratch/auctex-lexbind created (now 7606a49), Stefan Monnier, 2021/03/23
- [elpa] scratch/auctex-lexbind c037cac 02/13: Prepare for enabling lexical binding in preview.el.in,
Stefan Monnier <=
- [elpa] scratch/auctex-lexbind 7ccff10 01/13: ; * latex.el (LaTeX-fill-region-as-paragraph): Fix typo., Stefan Monnier, 2021/03/23
- [elpa] scratch/auctex-lexbind 7c2f403 03/13: * font-latex.el (font-latex-make-built-in-keywords): Reorder defs, Stefan Monnier, 2021/03/23
- [elpa] scratch/auctex-lexbind 1d188f5 05/13: Use #' rather than ' to quote functions, Stefan Monnier, 2021/03/23
- [elpa] scratch/auctex-lexbind e6910bb 07/13: Don't quote `lambda`, Stefan Monnier, 2021/03/23
- [elpa] scratch/auctex-lexbind d7bdc79 10/13: Expose the body of advice to the compiler, Stefan Monnier, 2021/03/23
- [elpa] scratch/auctex-lexbind 00ef597 09/13: Miscellaneous minor changes, Stefan Monnier, 2021/03/23
- [elpa] scratch/auctex-lexbind 7606a49 13/13: Use UTF-8 for all ELisp files, Stefan Monnier, 2021/03/23
- [elpa] scratch/auctex-lexbind 6ca7910 12/13: Prefer lexical closures over hand-built lambda forms, Stefan Monnier, 2021/03/23
- [elpa] scratch/auctex-lexbind 2852adf 11/13: Activate lexical-binding everywhere, Stefan Monnier, 2021/03/23
- [elpa] scratch/auctex-lexbind 7d89628 04/13: * font-latex.el (font-latex-make-built-in-keywords): Make it a macro, Stefan Monnier, 2021/03/23