[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 10/38] Implement link folding* lisp/ol.el (org-link--link-fold
From: |
Ihor Radchenko |
Subject: |
[PATCH v2 10/38] Implement link folding* lisp/ol.el (org-link--link-folding-spec): |
Date: |
Wed, 20 Apr 2022 21:25:18 +0800 |
* lisp/ol.el (org-link--link-folding-spec):
(org-link--description-folding-spec): New variables controlling link
folding settings.
(org-link--reveal-maybe): Handle revealing folded links.
(org-link-descriptive-ensure): Implement `org-link-descriptive'
support with org-fold.
(org-toggle-link-display--overlays):
(org-toggle-link-display--text-properties):
(org-toggle-link-display): Provide text-properties and overlays
versions.
* lisp/org-agenda.el (org-agenda-mode): Use org-fold to fold links in
agenda.
* lisp/org.el (org-do-emphasis-faces): Use org-fold.
---
lisp/ol.el | 42 +++++++++++++++++++++++++++++++++++++++++-
lisp/org-agenda.el | 3 ++-
lisp/org.el | 11 +++++++++--
3 files changed, 52 insertions(+), 4 deletions(-)
diff --git a/lisp/ol.el b/lisp/ol.el
index 4cc813d5b..86f55d7cf 100644
--- a/lisp/ol.el
+++ b/lisp/ol.el
@@ -605,6 +605,22 @@ (defvar org-link--insert-history nil
(defvar org-link--search-failed nil
"Non-nil when last link search failed.")
+
+(defvar-local org-link--link-folding-spec '(org-link
+ (:global t)
+ (:ellipsis . nil)
+ (:isearch-open . t)
+ (:fragile .
org-link--reveal-maybe))
+ "Folding spec used to hide invisible parts of links.")
+
+(defvar-local org-link--description-folding-spec '(org-link-description
+ (:global t)
+ (:ellipsis . nil)
+ (:visible . t)
+ (:isearch-open . nil)
+ (:fragile .
org-link--reveal-maybe))
+ "Folding spec used to reveal link description.")
+
;;; Internal Functions
@@ -762,6 +778,13 @@ (defun org-link--normalize-string (string &optional
context)
(t nil))))
string))
+(defun org-link--reveal-maybe (region _)
+ "Reveal folded link in REGION when needed.
+This function is intended to be used as :fragile property of a folding
+spec."
+ (org-with-point-at (car region)
+ (not (org-in-regexp org-link-any-re))))
+
;;; Public API
@@ -1444,14 +1467,31 @@ (defun org-previous-link ()
(interactive)
(org-next-link t))
+(defun org-link-descriptive-ensure ()
+ "Toggle the literal or descriptive display of links in current buffer if
needed."
+ (if org-link-descriptive
+ (org-fold-core-set-folding-spec-property (car
org-link--link-folding-spec) :visible nil)
+ (org-fold-core-set-folding-spec-property (car org-link--link-folding-spec)
:visible t)))
+
;;;###autoload
-(defun org-toggle-link-display ()
+(defun org-toggle-link-display--overlays ()
"Toggle the literal or descriptive display of links."
(interactive)
(if org-link-descriptive (remove-from-invisibility-spec '(org-link))
(add-to-invisibility-spec '(org-link)))
(org-restart-font-lock)
(setq org-link-descriptive (not org-link-descriptive)))
+(defun org-toggle-link-display--text-properties ()
+ "Toggle the literal or descriptive display of links in current buffer."
+ (interactive)
+ (setq org-link-descriptive (not org-link-descriptive))
+ (org-link-descriptive-ensure))
+(defsubst org-toggle-link-display ()
+ "Toggle the literal or descriptive display of links."
+ (interactive)
+ (if (eq org-fold-core-style 'text-properties)
+ (org-toggle-link-display--text-properties)
+ (org-toggle-link-display--overlays)))
;;;###autoload
(defun org-store-link (arg &optional interactive?)
diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index fa60f4f19..6aed778f0 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -2325,7 +2325,8 @@ (defun org-agenda-mode ()
org-agenda-show-log org-agenda-start-with-log-mode
org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode))
(add-to-invisibility-spec '(org-filtered))
- (add-to-invisibility-spec '(org-link))
+ (org-fold-core-initialize `(,org-link--description-folding-spec
+ ,org-link--link-folding-spec))
(easy-menu-change
'("Agenda") "Agenda Files"
(append
diff --git a/lisp/org.el b/lisp/org.el
index ca4973bc3..f6709f4cc 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -4563,9 +4563,16 @@ (define-derived-mode org-mode outline-mode "Org"
(setq-local org-mode-loading t)
(org-load-modules-maybe)
(org-install-agenda-files-menu)
- (when org-link-descriptive (add-to-invisibility-spec '(org-link)))
+ (when (and org-link-descriptive
+ (eq org-fold-core-style 'overlays))
+ (add-to-invisibility-spec '(org-link)))
+ (org-fold-initialize (or (and (stringp org-ellipsis) (not (equal ""
org-ellipsis)) org-ellipsis)
+ "..."))
(make-local-variable 'org-link-descriptive)
- (add-to-invisibility-spec '(org-hide-block . t))
+ (when (eq org-fold-core-style 'overlays) (add-to-invisibility-spec
'(org-hide-block . t)))
+ (if org-link-descriptive
+ (org-fold-core-set-folding-spec-property (car
org-link--link-folding-spec) :visible nil)
+ (org-fold-core-set-folding-spec-property (car org-link--link-folding-spec)
:visible t))
(setq-local outline-regexp org-outline-regexp)
(setq-local outline-level 'org-outline-level)
(setq bidi-paragraph-direction 'left-to-right)
--
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 00/38] Final call for comments: Merge org-fold feature branch, Ihor Radchenko, 2022/04/20
- [PATCH v2 01/38] Add org-fold-core: new folding engine---, Ihor Radchenko, 2022/04/20
- [PATCH v2 02/38] Separate folding functions from org.el into new library: org-fold, Ihor Radchenko, 2022/04/20
- [PATCH v2 03/38] Separate cycling functions from org.el into new library: org-cycle, Ihor Radchenko, 2022/04/20
- [PATCH v2 04/38] Remove functions from org.el that are now moved elsewhere, Ihor Radchenko, 2022/04/20
- [PATCH v2 05/38] Disable native-comp in agendaIt caused cryptic bugs in the past., Ihor Radchenko, 2022/04/20
- [PATCH v2 06/38] org-macs: New function org-find-text-property-region---, Ihor Radchenko, 2022/04/20
- [PATCH v2 07/38] org-at-heading-p: Accept optional argument* lisp/org.el (org-at-heading-p): Use second argument to allow, Ihor Radchenko, 2022/04/20
- [PATCH v2 08/38] org-string-width: Reimplement to work with new folding, Ihor Radchenko, 2022/04/20
- [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 <=
- [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, 2022/04/20
- [PATCH v2 20/38] Add org-fold-related tests---, Ihor Radchenko, 2022/04/20