[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 17/38] org-compat: Work around some third-party packages using
From: |
Ihor Radchenko |
Subject: |
[PATCH v2 17/38] org-compat: Work around some third-party packages using outline-* functions |
Date: |
Wed, 20 Apr 2022 21:26:05 +0800 |
---
lisp/org-compat.el | 72 +++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 71 insertions(+), 1 deletion(-)
diff --git a/lisp/org-compat.el b/lisp/org-compat.el
index 3e8f49f0a..f599e246e 100644
--- a/lisp/org-compat.el
+++ b/lisp/org-compat.el
@@ -1330,11 +1330,81 @@ (defvar session-globals-exclude)
(eval-after-load 'session
'(add-to-list 'session-globals-exclude 'org-mark-ring))
+;;;; outline-mode
+
+;; Folding in outline-mode is not compatible with org-mode folding
+;; anymore. Working around to avoid breakage of external packages
+;; assuming the compatibility.
+(defadvice outline-flag-region (around outline-flag-region@fix-for-org-fold
(from to flag) activate)
+ "Run `org-fold-region' when in org-mode."
+ (if (eq major-mode 'org-mode)
+ (setq ad-return-value (org-fold-region (max from (point-min)) (min to
(point-max)) flag 'headline))
+ ad-do-it))
+
+(defadvice outline-next-visible-heading (around
outline-next-visible-heading@fix-for-org-fold (arg) activate)
+ "Run `org-next-visible-heading' when in org-mode."
+ (interactive "p")
+ (if (eq major-mode 'org-mode)
+ (setq ad-return-value (org-next-visible-heading arg))
+ ad-do-it))
+
+(defadvice outline-back-to-heading (around
outline-back-to-heading@fix-for-org-fold (&optional invisible-ok) activate)
+ "Run `org-back-to-heading' when in org-mode."
+ (if (eq major-mode 'org-mode)
+ (setq ad-return-value
+ (progn
+ (beginning-of-line)
+ (or (org-at-heading-p (not invisible-ok))
+ (let (found)
+ (save-excursion
+ (while (not found)
+ (or (re-search-backward (concat "^\\(?:" outline-regexp
"\\)")
+ nil t)
+ (signal 'outline-before-first-heading nil))
+ (setq found (and (or invisible-ok (not
(org-fold-folded-p)))
+ (point)))))
+ (goto-char found)
+ found))))
+ ad-do-it))
+
+(defadvice outline-on-heading-p (around outline-on-heading-p@fix-for-org-fold
(&optional invisible-ok) activate)
+ "Run `org-at-heading-p' when in org-mode."
+ (if (eq major-mode 'org-mode)
+ (setq ad-return-value (org-at-heading-p (not invisible-ok)))
+ ad-do-it))
+
+(defadvice outline-hide-sublevels (around
outline-hide-sublevels@fix-for-org-fold (levels) activate)
+ "Run `org-fold-hide-sublevels' when in org-mode."
+ (interactive (list
+ (cond
+ (current-prefix-arg (prefix-numeric-value current-prefix-arg))
+ ((save-excursion (beginning-of-line)
+ (looking-at outline-regexp))
+ (funcall outline-level))
+ (t 1))))
+ (if (eq major-mode 'org-mode)
+ (setq ad-return-value (org-fold-hide-sublevels levels))
+ ad-do-it))
+
+(defadvice outline-toggle-children (around
outline-toggle-children@fix-for-org-fold () activate)
+ "Run `org-fold-hide-sublevels' when in org-mode."
+ (interactive)
+ (if (eq major-mode 'org-mode)
+ (setq ad-return-value
+ (save-excursion
+ (org-back-to-heading)
+ (if (not (org-fold-folded-p (line-end-position)))
+ (org-fold-hide-subtree)
+ (org-fold-show-children)
+ (org-fold-show-entry))))
+ ad-do-it))
+
+;; TODO: outline-headers-as-kill
+
;;;; Speed commands
(make-obsolete-variable 'org-speed-commands-user
"configure `org-speed-commands' instead." "9.5")
-
(provide 'org-compat)
;; Local variables:
--
2.35.1
--
Ihor Radchenko,
PhD,
Center for Advancing Materials Performance from the Nanoscale (CAMP-nano)
State Key Laboratory for Mechanical Behavior of Materials, Xi'an Jiaotong
University, Xi'an, China
Email: yantar92@gmail.com, ihor_radchenko@alumni.sutd.edu.sg
- [PATCH v2 09/38] Rename old function call to use org-fold---, (continued)
- [PATCH v2 09/38] Rename old function call to use org-fold---, Ihor Radchenko, 2022/04/20
- [PATCH v2 10/38] Implement link folding* lisp/ol.el (org-link--link-folding-spec):, Ihor Radchenko, 2022/04/20
- [PATCH v2 12/38] org-fold: Handle indirect buffer visibility---, Ihor Radchenko, 2022/04/20
- [PATCH v2 11/38] Implement overlay- and text-property-based versions of some functions, Ihor Radchenko, 2022/04/20
- [PATCH v2 13/38] Fix subtle differences between overlays and invisible text properties, Ihor Radchenko, 2022/04/20
- [PATCH v2 14/38] Support extra org-fold optimisations for huge buffers, Ihor Radchenko, 2022/04/20
- [PATCH v2 15/38] Alias new org-fold functions to their old shorter names, Ihor Radchenko, 2022/04/20
- [PATCH v2 16/38] Obsolete old function names that are now in org-fold---, Ihor Radchenko, 2022/04/20
- [PATCH v2 18/38] Move `org-buffer-list' to org-macs.el---, Ihor Radchenko, 2022/04/20
- [PATCH v2 19/38] Restore old visibility behaviour of org-refile---, Ihor Radchenko, 2022/04/20
- [PATCH v2 17/38] org-compat: Work around some third-party packages using outline-* functions,
Ihor Radchenko <=
- [PATCH v2 20/38] Add org-fold-related tests---, Ihor Radchenko, 2022/04/20
- [PATCH v2 22/38] ORG-NEWS: Add list of changes---, Ihor Radchenko, 2022/04/20
- [PATCH v2 23/38] Backport contributed commits---, Ihor Radchenko, 2022/04/20
- [PATCH v2 21/38] org-manual: Update to new org-fold function names---, Ihor Radchenko, 2022/04/20
- [PATCH v2 25/38] Fix bug in org-get-headingFixes #26, where fontification could make the matching and extraction of heading, Anders Johansson, 2022/04/20
- [PATCH v2 24/38] Fix typo: delete-duplicates → delete-dups, Anders Johansson, 2022/04/20
- [PATCH v2 26/38] Rename remaining org-force-cycle-archived, Anders Johansson, 2022/04/20
- [PATCH v2 27/38] Fix org-fold--hide-drawers--overlays---, Ihor Radchenko, 2022/04/20
- [PATCH v2 28/38] org-string-width: Handle undefined behaviour in older Emacs, Ihor Radchenko, 2022/04/20
- [PATCH v2 29/38] org-string-width: Work around `window-pixel-width' bug in old Emacs, Ihor Radchenko, 2022/04/20