Skip to content

Commit

Permalink
org-compat: Add forward-compatibility for argument changes in adviced…
Browse files Browse the repository at this point in the history
… 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/
  • Loading branch information
yantar92 committed Sep 6, 2022
1 parent a3788bd commit 0c055d2
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions lisp/org-compat.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down

0 comments on commit 0c055d2

Please sign in to comment.