ソースを参照

org-compat: Add forward-compatibility for argument changes in adviced functions

* lisp/org-compat.el (outline-flag-region):
(outline-next-visible-heading):
(outline-back-to-heading):
(outline-on-heading-p):
(outline-hide-sublevels):
(outline-toggle-children): Accept arbitrary extra arguments and pass
them to original function if its arglist changes in future.

This patch is following the "no-breakage" policy:
>> I won't break your user experience.
https://bzg.fr/en/the-software-maintainers-pledge/
Ihor Radchenko 2 年 前
コミット
0c055d2d31
1 ファイル変更24 行追加12 行削除
  1. 24 12
      lisp/org-compat.el

+ 24 - 12
lisp/org-compat.el

@@ -1469,19 +1469,23 @@ key."
 ;; Folding in outline-mode is not compatible with org-mode folding
 ;; anymore. Working around to avoid breakage of external packages
 ;; assuming the compatibility.
-(define-advice outline-flag-region (:around (oldfun from to flag) fix-for-org-fold)
+(define-advice outline-flag-region (:around (oldfun from to flag &rest extra) fix-for-org-fold)
   "Run `org-fold-region' when in org-mode."
   (if (derived-mode-p 'org-mode)
       (org-fold-region (max from (point-min)) (min to (point-max)) flag 'headline)
-    (funcall oldfun from to flag)))
+    ;; Apply EXTRA to avoid breakages if adviced function definition
+    ;; changes.
+    (apply oldfun from to flag extra)))
 
-(define-advice outline-next-visible-heading (:around (oldfun arg) fix-for-org-fold)
+(define-advice outline-next-visible-heading (:around (oldfun arg &rest extra) fix-for-org-fold)
   "Run `org-next-visible-heading' when in org-mode."
   (if (derived-mode-p 'org-mode)
       (org-next-visible-heading arg)
-    (funcall oldfun arg)))
+    ;; Apply EXTRA to avoid breakages if adviced function definition
+    ;; changes.
+    (apply oldfun arg extra)))
 
-(define-advice outline-back-to-heading (:around (oldfun &optional invisible-ok) fix-for-org-fold)
+(define-advice outline-back-to-heading (:around (oldfun &optional invisible-ok &rest extra) fix-for-org-fold)
   "Run `org-back-to-heading' when in org-mode."
   (if (derived-mode-p 'org-mode)
       (progn
@@ -1497,21 +1501,27 @@ key."
 			           (point)))))
 	      (goto-char found)
 	      found)))
-    (funcall oldfun invisible-ok)))
+    ;; Apply EXTRA to avoid breakages if adviced function definition
+    ;; changes.
+    (apply oldfun invisible-ok extra)))
 
-(define-advice outline-on-heading-p (:around (oldfun &optional invisible-ok) fix-for-org-fold)
+(define-advice outline-on-heading-p (:around (oldfun &optional invisible-ok &rest extra) fix-for-org-fold)
   "Run `org-at-heading-p' when in org-mode."
   (if (derived-mode-p 'org-mode)
       (org-at-heading-p (not invisible-ok))
-    (funcall oldfun invisible-ok)))
+    ;; Apply EXTRA to avoid breakages if adviced function definition
+    ;; changes.
+    (apply oldfun invisible-ok extra)))
 
-(define-advice outline-hide-sublevels (:around (oldfun levels) fix-for-org-fold)
+(define-advice outline-hide-sublevels (:around (oldfun levels &rest extra) fix-for-org-fold)
   "Run `org-fold-hide-sublevels' when in org-mode."
   (if (derived-mode-p 'org-mode)
       (org-fold-hide-sublevels levels)
-    (funcall oldfun levels)))
+    ;; Apply EXTRA to avoid breakages if adviced function definition
+    ;; changes.
+    (apply oldfun levels extra)))
 
-(define-advice outline-toggle-children (:around (oldfun) fix-for-org-fold)
+(define-advice outline-toggle-children (:around (oldfun &rest extra) fix-for-org-fold)
   "Run `org-fold-hide-sublevels' when in org-mode."
   (if (derived-mode-p 'org-mode)
       (save-excursion
@@ -1520,7 +1530,9 @@ key."
             (org-fold-hide-subtree)
           (org-fold-show-children)
           (org-fold-show-entry 'hide-drawers)))
-    (funcall oldfun)))
+    ;; Apply EXTRA to avoid breakages if adviced function definition
+    ;; changes.
+    (apply oldfun extra)))
 
 ;; TODO: outline-headers-as-kill