From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id 4O0eDtEMYGKtGAEAbAwnHQ (envelope-from ) for ; Wed, 20 Apr 2022 15:38:25 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id qFcBDtEMYGJLpQAAauVa8A (envelope-from ) for ; Wed, 20 Apr 2022 15:38:25 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id EBDE7F319 for ; Wed, 20 Apr 2022 15:38:24 +0200 (CEST) Received: from localhost ([::1]:40584 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nhAXI-0006Aa-4V for larch@yhetil.org; Wed, 20 Apr 2022 09:38:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36910) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nhAJp-0003ft-P6 for emacs-orgmode@gnu.org; Wed, 20 Apr 2022 09:24:29 -0400 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]:39789) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nhAJo-0003Mx-2b for emacs-orgmode@gnu.org; Wed, 20 Apr 2022 09:24:29 -0400 Received: by mail-pj1-x102c.google.com with SMTP id mp16-20020a17090b191000b001cb5efbcab6so4934712pjb.4 for ; Wed, 20 Apr 2022 06:24:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:in-reply-to:references:message-id:date:mime-version; bh=ads6K6sbFIQRucbdwPI88GTwqdtB3RldDbkpBJkXuqM=; b=WejGl8lvYRNd+9VxgA73N1rlrRIB7ML6W36uBtQPEfO3La/4A7J2Ks2ymZD7cmGhw+ dlRJECdyPg0M2JHsvSdjtHMsMGcfBsLFsPeGltsIQ5TBWqPiIhoTwjCU5JtvhRMqkXtq 0+Es0JCGOiNx0ypPgzmSOgNhL5MrodRzlRZratu+0smk8WZhDD+6bVjS7m6o8qLeN4KR SmcwfjyFyXDU2dvrovE8bUtar4ZpmNG0M/rVHRECqVU0O4g9WgwNcG+SDGe1x0oBbmbY 7ddj3xeLwEnXMYHiShiX6R1mklhgYrEXh6lyNtkdWMScl6WRkl0YuVfuQVZYNlI8KdGb uAbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:in-reply-to:references :message-id:date:mime-version; bh=ads6K6sbFIQRucbdwPI88GTwqdtB3RldDbkpBJkXuqM=; b=pD2yhs3deJ9pfjNcCNOVFd4xdPj1fnxyJKXvDpmL0KRHZUJsQiCkRhLtH6YQT8X0Ui vZMdtvzEabBjj1eOIxN6WvODVI6GMP/tELaaf6waVDW7tsMI20XPUd7PwXAzIBZ5yHLP a48tjKAB6Sqragl9aPvoUquvR6xYVh+6AyDZJZr0Mdu43eYHFtkQvmRWqytI6on3XFr9 WGsJcqNVOXYn8/bJgH9cKaahw1Nw/19AuPGViaWEQqC/WznD4H1MQj7Dn3aoofWRU4GY clJbRaw/v4ZZblh50iChOri9ZceC52Td3P5XT8rBI7hJZA6onh+sKAlpYYHJ/DDlasjl QVJA== X-Gm-Message-State: AOAM533I7ZMVz53uNFdoAKAcLCes6GKQjJsz01VGS3SrM5swBFLJHd9q Ugbm7yknxWjCXYGpy2pffXVc3zhB8xixHQ== X-Google-Smtp-Source: ABdhPJypMStw2xkReQ6O2jPD0EitawXmp1lDTBD/zdZMbqTnZAv+Be88eoqfqOUngUJXq2xNNtHxQQ== X-Received: by 2002:a17:903:124a:b0:154:c7a4:9374 with SMTP id u10-20020a170903124a00b00154c7a49374mr20939701plh.68.1650461065955; Wed, 20 Apr 2022 06:24:25 -0700 (PDT) Received: from localhost ([64.32.23.62]) by smtp.gmail.com with ESMTPSA id d16-20020a056a00245000b004f771b48736sm21387252pfj.194.2022.04.20.06.24.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Apr 2022 06:24:25 -0700 (PDT) From: Ihor Radchenko To: emacs-orgmode@gnu.org Subject: [PATCH v2 10/38] Implement link folding* lisp/ol.el (org-link--link-folding-spec): In-Reply-To: References: Message-Id: <273d2171a035c45af674558e3678c9bcd13aaf55.1650460489.git.yantar92@gmail.com> Date: Wed, 20 Apr 2022 21:25:18 +0800 MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=2607:f8b0:4864:20::102c; envelope-from=yantar92@gmail.com; helo=mail-pj1-x102c.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1650461905; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=uAGr7kKwiEcfTUrAnXTtwvv5Yb7tHyKWG0Wp2JndvYA=; b=f4oll797Hdoe6cKNws5M1DfaSGdRNJivINIC9iMGTSO58+61WXJcN3R6SWamLtUcm/p5Ub P6qFx/FTrZTstHy1osL4uhY98yfh0vijhV/lvZR7gfXaTz2FgRJKBQaw6bG1wTDZjLVTAo 22yRpsG/w3qEGXqfJYhwV6xsroDoREJHnKZGGOK3x0IVpTIE/fAPz6JcU8E9gUptVTnWW1 zYnjJMvXeQiZpLpa5sf0bFGP5LRf6DqrWFuNECVvz96Pd+0TrMXn+xdTmZ5crvK8/Ni2HB qsz93ovHGqembO1bwfmHEiWbmm5e7/ffrb9H1lZ8fsz5ebfaGhBBlCF/py0rig== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1650461905; a=rsa-sha256; cv=none; b=HUb6dxn9hv8aaHqa6FWzUl/7XPRdTwqvN69DcjK8J4yF+z9mSXXHBQHQLZ4fbdoABXe+VG 0Yyg9CCWPpwtf67kB41KB+VaHXlAVpDRN9bh/dK5QVTjfHIUK+YkXfmICZMPh7A00MBNbA NsyxZ2j50Cm8pbPNps0o+RRGA3Cyg7qPFIMdParGkjH+uxi66+qadPWj85uh0rRXH4+/88 yCm30yCeD43eJc9XB/U6MikEAHrX83y+gHSyWYv0Erx+eMOVivwZGSWF+B1gXK1elGS9MG xTrmLKyjiKSrv8KVkfxZuWQZnOV591hZS/TR818K7XVtFd51xsPrGSFDxypaSg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gmail.com header.s=20210112 header.b=WejGl8lv; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: 7.16 Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gmail.com header.s=20210112 header.b=WejGl8lv; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: EBDE7F319 X-Spam-Score: 7.16 X-Migadu-Scanner: scn1.migadu.com X-TUID: RwEbiFnuDdE6 * 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