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

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

[elpa] scratch/auctex-lexbind d7bdc79 10/13: Expose the body of advice t


From: Stefan Monnier
Subject: [elpa] scratch/auctex-lexbind d7bdc79 10/13: Expose the body of advice to the compiler
Date: Tue, 23 Mar 2021 13:56:57 -0400 (EDT)

branch: scratch/auctex-lexbind
commit d7bdc79cafa1bca2a0da5caa9aa7911393175366
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.in (preview--open-for-replace): New function.
    (replace-highlight): 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.in | 10 +++++++---
 tex.el        | 10 ++++++----
 4 files changed, 30 insertions(+), 16 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 3265615..9e22628 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.in b/preview.el.in
index a15629b..2789a0e 100644
--- a/preview.el.in
+++ b/preview.el.in
@@ -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."
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]