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

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

[elpa] scratch/auctex-lexbind 124b604 08/11: Expose the body of advice t


From: Stefan Monnier
Subject: [elpa] scratch/auctex-lexbind 124b604 08/11: Expose the body of advice to the compiler
Date: Tue, 23 Mar 2021 11:34:01 -0400 (EDT)

branch: scratch/auctex-lexbind
commit 124b604c1fb39ca86606d474ceab726a29949267
Author: Stefan Monnier <monnier@iro.umontreal.ca>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>

    Expose the body of advice to the compiler
    
    While at it, use `advice-add` when available.
    We can drop `defadvice` completely when we bump the required version
    to Emacs-24.4, or if/when we add `nadvice` as a required package.
    
    * context.el (ConTeXt--invalidate-menu): New function.
    (ConTeXt-add-environments): Advise with it.
    
    * latex.el (LaTeX-add-bibliographies): Advise with `TeX-run-style-hooks`.
    (LaTeX--invalidate-menus): New function.
    (LaTeX-add-environments): Advise with it.
    
    * preview.el (preview--open-for-replace): New function.
    (replace-highlight): Advise with it.
    (preview--TeX-region-counters): New function.
    (TeX-region-create): Advise with it.
    (preview--TeX-region-skip-preamble): New function.
    (TeX-region-create): Advise with it.
    
    * tex.el (tex--call-minor-mode): New function.
    (hack-one-local-variable): Advise with it.
---
 context.el |  8 ++++++--
 latex.el   | 18 +++++++++++-------
 preview.el | 47 +++++++++++++++++++++++++++++++----------------
 tex.el     | 10 ++++++----
 4 files changed, 54 insertions(+), 29 deletions(-)

diff --git a/context.el b/context.el
index 4def467..e3a32aa 100644
--- a/context.el
+++ b/context.el
@@ -636,8 +636,12 @@ inserted after the sectioning command."
 
 (TeX-auto-add-type "environment" "ConTeXt")
 
-(defadvice ConTeXt-add-environments (after ConTeXt-invalidate-menu (&rest 
environments) activate)
-  "Add ENVIRONMENTS to the list of known environments."
+(if (fboundp 'advice-add)               ;Emacs≥24.4 (or ELPA package nadvice)
+    (advice-add 'ConTeXt-add-environments :after #'ConTeXt--invalidate-menu)
+  (defadvice ConTeXt-add-environments (after ConTeXt-invalidate-menu (&rest 
environments) activate)
+    (ConTeXt--invalidate-menu)))
+(defun ConTeXt--invalidate-menu (&rest _)
+  "Mark the menu as being in need of a refresh."
   (setq ConTeXt-menu-changed t))
 
 ;; (defvar ConTeXt-environment-list ()
diff --git a/latex.el b/latex.el
index bf42d4e..bfd3bea 100644
--- a/latex.el
+++ b/latex.el
@@ -1967,9 +1967,11 @@ The value is actually the tail of the list of options 
given to PACKAGE."
 
 (add-hook 'TeX-auto-cleanup-hook #'LaTeX-auto-cleanup)
 
-(defadvice LaTeX-add-bibliographies (after run-bib-style-hooks (&rest 
bibliographies) activate)
-  "Add BIBLIOGRAPHIES to the list of known bibliographies and style files."
-  (apply #'TeX-run-style-hooks bibliographies))
+(if (fboundp 'advice-add)               ;Emacs≥24.4 (or ELPA package nadvice)
+    (advice-add 'LaTeX-add-bibliographies :after #'TeX-run-style-hooks)
+  (defadvice LaTeX-add-bibliographies (after run-bib-style-hooks (&rest 
bibliographies) activate)
+    "Add BIBLIOGRAPHIES to the list of known bibliographies and style files."
+    (apply #'TeX-run-style-hooks bibliographies)))
 
 ;;; Biber support
 
@@ -5761,10 +5763,12 @@ corresponds to the variables 
`LaTeX-environment-menu-name' and
                (mapcar #'LaTeX-environment-modify-menu-entry
                        (LaTeX-environment-list))))))))
 
-(defadvice LaTeX-add-environments (after LaTeX-invalidate-environment-menu 
(&rest environments) activate)
-  "Add ENVIRONMENTS to the list of known environments.
-Additionally invalidate the environment submenus to let them be
-regenerated by the respective menu filter."
+(if (fboundp 'advice-add)               ;Emacs≥24.4 (or ELPA package nadvice)
+    (advice-add 'LaTeX-add-environments :after #'LaTeX--invalidate-menus)
+  (defadvice LaTeX-add-environments (after LaTeX-invalidate-environment-menu 
(&rest environments) activate)
+    (LaTeX--invalidate-menus)))
+(defun LaTeX--invalidate-menus (&rest _)
+  "Mark the environment menus as being in need of a refresh."
   (setq LaTeX-environment-menu nil)
   (setq LaTeX-environment-modify-menu nil))
 
diff --git a/preview.el b/preview.el
index 5ef159b..bcbdb8f 100644
--- a/preview.el
+++ b/preview.el
@@ -2060,10 +2060,14 @@ overlays not in the active window."
       (preview-toggle ovr)
       (push ovr preview-temporary-opened))))
 
-(defadvice replace-highlight (before preview)
+(if (fboundp 'advice-add)               ;Emacs≥24.4 (or ELPA package nadvice)
+    (advice-add 'replace-highlight :before #'preview--open-for-replace)
+  (defadvice replace-highlight (before preview)
+    (preview--open-for-replace (ad-get-arg 0) (ad-get-arg 1))))
+
+(defun preview--open-for-replace (beg end &rest _)
   "Make `query-replace' open preview text about to be replaced."
-  (preview-open-overlays
-   (overlays-in (ad-get-arg 0) (ad-get-arg 1))))
+  (preview-open-overlays (overlays-in beg end)))
 
 (defcustom preview-query-replace-reveal t
   "Make `query-replace' autoreveal previews."
@@ -2611,7 +2615,12 @@ not use in advice."
             (next-single-char-property-change begin 'preview-counters)
             'preview-counters))))
 
-(defadvice TeX-region-create (around preview-counters)
+(if (fboundp 'advice-add)               ;Emacs≥24.4 (or ELPA package nadvice)
+    (advice-add 'TeX-region-create :around #'preview--TeX-region-counters)
+  (defadvice TeX-region-create (around preview-counters)
+    (preview--TeX-region-counters (lambda (&rest _) ad-do-it))))
+
+(defun preview--TeX-region-counters (orig-fun &rest args)
   "Write out counter information to region."
   (let ((TeX-region-extra
          (concat
@@ -2624,7 +2633,7 @@ not use in advice."
                  (preview-counter-find (symbol-value 'begin)))
                 "\\setcounter"))
           TeX-region-extra)))
-    ad-do-it))
+    (apply orig-fun args)))
 
 (defun preview-reinstate-preview (tempdirlist timestamp start end
   image filename &optional counters)
@@ -4055,18 +4064,24 @@ 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)
+(if (fboundp 'advice-add)               ;Emacs≥24.4 (or ELPA package nadvice)
+    (advice-add 'TeX-region-create :around #'preview--TeX-region-skip-preamble)
+  (defadvice TeX-region-create (around preview-preamble preactivate activate)
+    (apply #'preview--TeX-region-skip-preamble
+           (lambda (&rest args) (ad-set-args 0 args) ad-do-it)
+           (ad-get-args 0))))
+
+(defun preview--TeX-region-skip-preamble (orig-fun file region original offset)
   "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))))))))
+  (if (string-match TeX-header-end region)
+      (funcall orig-fun file (substring region (match-end 0))
+               original
+               (with-temp-buffer
+                 (insert (substring region 0 (match-end 0)))
+                 (+ offset
+                    (count-lines (point-min) (point-max))
+                    (if (bolp) 0 -1))))
+    (funcall orig-fun file region original offset)))
 
 (defun preview-document ()
   "Run preview on master document."
diff --git a/tex.el b/tex.el
index a295a21..b6d1530 100644
--- a/tex.el
+++ b/tex.el
@@ -752,17 +752,19 @@ emacs 24.1 and is then later run by emacs 24.5."
                           (add-to-list 'Info-file-list-for-emacs
                                        (cons elt "AUCTeX"))))
 
-(defadvice hack-one-local-variable (after TeX-hack-one-local-variable-after
+(if (fboundp 'advice-add)               ;Emacs≥24.4 (or ELPA package nadvice)
+    (advice-add 'hack-one-local-variable :after #'tex--call-minor-mode)
+  (defadvice hack-one-local-variable (after TeX-hack-one-local-variable-after
                                           activate)
+    (tex--call-minor-mode (ad-get-arg 0) (ad-get-arg 1))))
+(defun tex--call-minor-mode (var val &rest _)
   "Call minor mode function if minor mode variable is found."
-  (let ((var (ad-get-arg 0))
-        (val (ad-get-arg 1)))
     ;; Instead of checking for each mode explicitely `minor-mode-list'
     ;; could be used.  But this may make the byte compiler pop up.
     (when (memq var '(TeX-PDF-mode
                       TeX-source-correlate-mode TeX-interactive-mode
                       TeX-fold-mode LaTeX-math-mode))
-      (if (symbol-value val) (funcall var 1) (funcall var 0)))))
+      (funcall var (if (symbol-value val) 1 0))))
 
 (defvar TeX-overlay-priority-step 16
   "Numerical difference of priorities between nested overlays.



reply via email to

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