From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.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 iKO3HE5VNGN7SgAAbAwnHQ (envelope-from ) for ; Wed, 28 Sep 2022 16:08:14 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id QELeHE5VNGNoEwEA9RJhRA (envelope-from ) for ; Wed, 28 Sep 2022 16:08:14 +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 2597537F1 for ; Wed, 28 Sep 2022 16:08:14 +0200 (CEST) Received: from localhost ([::1]:52598 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1odXjQ-0005LB-LP for larch@yhetil.org; Wed, 28 Sep 2022 10:08:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47308) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1odWfX-0006n6-Q7 for emacs-orgmode@gnu.org; Wed, 28 Sep 2022 09:00:10 -0400 Received: from [39.171.215.24] (port=5964 helo=Mac-mini.local) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1odWfT-0003Ap-Rg for emacs-orgmode@gnu.org; Wed, 28 Sep 2022 09:00:06 -0400 Received: by Mac-mini.local (Postfix, from userid 501) id CA6156638B01; Wed, 28 Sep 2022 20:59:49 +0800 (CST) References: <631d472b.c80a0220.2b4b2.bf86SMTPIN_ADDED_BROKEN@mx.google.com> <87h71ew0m0.fsf@localhost> <631e92ee.050a0220.f9c18.92f5SMTPIN_ADDED_BROKEN@mx.google.com> <87y1uovp9w.fsf@localhost> <631fe1c9.050a0220.3ab2b.3f52SMTPIN_ADDED_BROKEN@mx.google.com> <87bkrhwc42.fsf@localhost> <6322b0a8.050a0220.59bb8.6923SMTPIN_ADDED_BROKEN@mx.google.com> <87y1uluir1.fsf@localhost> <6322f5ad.c80a0220.5e936.823eSMTPIN_ADDED_BROKEN@mx.google.com> <878rmesf64.fsf@localhost> <6329c8b0.050a0220.412d.0a6cSMTPIN_ADDED_BROKEN@mx.google.com> <87tu51xivh.fsf@localhost> User-agent: mu4e 1.8.9; emacs 29.0.50 From: "Christopher M. Miles" To: Ihor Radchenko Cc: "Christopher M. Miles" , emacs-orgmode@gnu.org Subject: [PATCH 2-v1] New: auto display inline images under subtree when `org-cycle'. Date: Wed, 28 Sep 2022 20:55:00 +0800 In-reply-to: <87tu51xivh.fsf@localhost> Message-ID: MIME-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" X-Host-Lookup-Failed: Reverse DNS lookup failed for 39.171.215.24 (deferred) Received-SPF: softfail client-ip=39.171.215.24; envelope-from=numbchild@gmail.com; helo=Mac-mini.local X-Spam_score_int: 58 X-Spam_score: 5.8 X-Spam_bar: +++++ X-Spam_report: (5.8 / 5.0 requ) BAYES_00=-1.9, DKIM_ADSP_CUSTOM_MED=0.001, FORGED_GMAIL_RCVD=1, FREEMAIL_FROM=0.001, MSGID_MULTIPLE_AT=1, NML_ADSP_CUSTOM_MED=0.9, RCVD_IN_PBL=3.335, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_SOFTFAIL=0.665, SPOOFED_FREEMAIL_NO_RDNS=0.001 autolearn=no autolearn_force=no X-Spam_action: reject 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: , Reply-To: numbchild@gmail.com Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1664374094; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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; bh=T5UsrUcNkO4w2u51wAn8wAhM0llGcFhE8KHbFXYwwHo=; b=XQC9CGXVJNgoYUYWVXFR3PrrB9owh+kUBc8uEZhS1f2NZi4R9VrNaZwTYUR9D/I//epR77 T0c+tBBAOQKVTDXTnZrUfQcOnFFqCYTogbBLniMbwkAqftPOHX6GV34QfG5qyR5LECh1ht 9BQElyeC/03FuVSq46s/klqQKUZr02QXmpCZeUjz5n/ChHLhbOeplmkni/NUyqG7UUtaWW wi+6OQNskCLr7QODyox8e+Hn3T8GbHXzRSgS5SunRrsSYVim7kb7heKORwqc3rpaK0NWGh lacYtfJKx1N7Ur6LpxNTGXV1r+S8+R3VAWfOpaisslL4TY1fiXY1wQItLF4YPQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1664374094; a=rsa-sha256; cv=none; b=NXfvTlPnKkRspIkvWzwnFbcww7mhLkOsYOwMwaVUBqKi7K6Zt21oKjzfIw8y6/PsN0MuFW WIbN44GsxgeRSB/Zj18ZtrCkNmxFjukLgRTVaHAjXCs7BbuQ7G2c8tPTJZitSJhfRjgXvY bvDZGJX3bu1KYVn5O7I9IbVjlK5YWkm5meFrkrFh4/YecOGJ9g82FatAffYO22HGMkoMP5 fWbcO9hSdckaDW7aEEXgIQkgUADdSuJMHlPj7j2yULIO95YUvFaIbw73FpB8OdKyYDGeLv 3A5Js7+hnWA1zgsFQEkpQTe8OhP7Qcri6TMR/OLTo+inuzA28ptK00bwnmAzdA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" 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: 0.45 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" 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: 2597537F1 X-Spam-Score: 0.45 X-Migadu-Scanner: scn0.migadu.com X-TUID: dfE7q5KyWQgJ --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain Ok, I created the patch for subtree cycling display inline images. Tested by edebug when org cycling, it should works fine. I don't know how to write test for this. But I got a little problem: When ~org-fold-core-style~ is ~'overlays~, the ~delete-overlay~ will cause subtree unfolded. More detailed check out the "org.el" function ~org-remove-inline-images~ in my patch. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-org.el-Support-auto-display-inline-images-when-cycli.patch Content-Transfer-Encoding: quoted-printable From=20173772d166c9974db1a76f59fe58988fe8da401a Mon Sep 17 00:00:00 2001 From: stardiviner Date: Wed, 28 Sep 2022 20:46:52 +0800 Subject: [PATCH] org.el: Support auto display inline images when cycling * lisp/org.el (org-toggle-inline-images): Support region. (org-display-inline-images): Fix refresh argument logic. (org-remove-inline-images): Support region. * lisp/org-keys.el (org-toggle-inline-images): Update arguments. * lisp/org-cycle.el (org-cycle-inline-images-display): Add new option to control whether auto display inline images when cycling. (org-cycle-display-inline-images): Add new hook function to auto display inline images when cycling. (org-cycle-hook): Add `org-cycle-display-inline-images' into cycling hook by default. =2D-- lisp/org-cycle.el | 36 ++++++++++++++++++++++++++++++++++-- lisp/org-keys.el | 2 +- lisp/org.el | 25 +++++++++++++++++-------- 3 files changed, 52 insertions(+), 11 deletions(-) diff --git a/lisp/org-cycle.el b/lisp/org-cycle.el index 656ca83f2..da7a7a34e 100644 =2D-- a/lisp/org-cycle.el +++ b/lisp/org-cycle.el @@ -208,8 +208,9 @@ the values `folded', `children', or `subtree'." :type 'hook) =20 (defcustom org-cycle-hook '(org-cycle-hide-archived-subtrees =2D org-cycle-show-empty-lines =2D org-cycle-optimize-window-after-visibility-change) + org-cycle-show-empty-lines + org-cycle-optimize-window-after-visibility-cha= nge + org-cycle-display-inline-images) "Hook that is run after `org-cycle' has changed the buffer visibility. The function(s) in this hook must accept a single argument which indicates the new state that was set by the most recent `org-cycle' command. The @@ -229,6 +230,12 @@ normal outline commands like `show-all', but not with = the cycling commands." :group 'org-cycle :type 'boolean) =20 +(defcustom org-cycle-inline-images-display nil + "Non-nil means auto display inline images under subtree when cycling." + :group 'org-startup + :group 'org-cycle + :type 'boolean) + (defvar org-cycle-tab-first-hook nil "Hook for functions to attach themselves to TAB. See `org-ctrl-c-ctrl-c-hook' for more information. @@ -776,6 +783,31 @@ STATE should be one of the symbols listed in the docst= ring of "Subtree is archived and stays closed. Use \ `\\[org-cycle-force-archived]' to cycle it anyway.")))))) =20 +(defun org-cycle-display-inline-images (state) + "Auto display inline images under subtree when cycling. +It works when `org-cycle-inline-images-display' is non-nil." + (when org-cycle-inline-images-display + (pcase state + ('children + (save-excursion + (save-restriction + (org-narrow-to-subtree) + ;; If has nested headlines, beg,end only from parent + ;; headline to first child headline which reference to + ;; upper let-binding `org-next-visible-heading'. + (org-display-inline-images + nil nil + (point-min) (progn (org-next-visible-heading 1) (point)))))) + ('subtree + (save-excursion + (save-restriction + (org-narrow-to-subtree) + ;; If has nested headlines, also inline display images under al= l sub-headlines. + (org-display-inline-images nil nil (point-min) (point-max))))) + ('folded + (org-narrow-to-subtree) + (org-remove-inline-images (point-min) (point-max)))))) + (provide 'org-cycle) =20 ;;; org-cycle.el ends here diff --git a/lisp/org-keys.el b/lisp/org-keys.el index d65379a72..79e34cbd1 100644 =2D-- a/lisp/org-keys.el +++ b/lisp/org-keys.el @@ -204,7 +204,7 @@ (declare-function org-toggle-radio-button "org" (&optional arg)) (declare-function org-toggle-comment "org" ()) (declare-function org-toggle-fixed-width "org" ()) =2D(declare-function org-toggle-inline-images "org" (&optional include-link= ed)) +(declare-function org-toggle-inline-images "org" (&optional include-linked= beg end)) (declare-function org-latex-preview "org" (&optional arg)) (declare-function org-toggle-narrow-to-subtree "org" ()) (declare-function org-toggle-ordered-property "org" ()) diff --git a/lisp/org.el b/lisp/org.el index 036384a04..e7eba25cc 100644 =2D-- a/lisp/org.el +++ b/lisp/org.el @@ -16071,16 +16071,16 @@ SNIPPETS-P indicates if this is run to create sni= ppet images for HTML." =20 (defvar-local org-inline-image-overlays nil) =20 =2D(defun org-toggle-inline-images (&optional include-linked) +(defun org-toggle-inline-images (&optional include-linked beg end) "Toggle the display of inline images. INCLUDE-LINKED is passed to `org-display-inline-images'." (interactive "P") (if org-inline-image-overlays (progn =2D (org-remove-inline-images) + (org-remove-inline-images beg end) (when (called-interactively-p 'interactive) (message "Inline image display turned off"))) =2D (org-display-inline-images include-linked) + (org-display-inline-images include-linked nil beg end) (when (called-interactively-p 'interactive) (message (if org-inline-image-overlays (format "%d images displayed inline" @@ -16170,8 +16170,8 @@ BEG and END define the considered part. They defau= lt to the buffer boundaries with possible narrowing." (interactive "P") (when (display-graphic-p) =2D (unless refresh =2D (org-remove-inline-images) + (when refresh + (org-remove-inline-images beg end) (when (fboundp 'clear-image-cache) (clear-image-cache))) (let ((end (or end (point-max)))) (org-with-point-at (or beg (point-min)) @@ -16322,11 +16322,20 @@ buffer boundaries with possible narrowing." (delete ov org-inline-image-overlays) (delete-overlay ov)))) =20 =2D(defun org-remove-inline-images () +(defun org-remove-inline-images (&optional beg end) "Remove inline display of images." (interactive) =2D (mapc #'delete-overlay org-inline-image-overlays) =2D (setq org-inline-image-overlays nil)) + (let* ((beg (or beg (point-min))) + (end (or end (point-max))) + (overlays (overlays-in beg end))) + (dolist (ov overlays) + (delete ov org-inline-image-overlays)) + (mapc #'delete-overlay overlays) + ;; FIXME: `org-cycle-display-inline-images' can't fold because `delete= -overlay' will unfold subtree. + (when (eq org-fold-core-style 'overlays) + ;; FIXME: don't know how to get the correct `spec'. + (let ((spec (alist-get 'org-fold-hidden org-fold-core--specs))) + (org-fold-core-region beg end t spec))))) =20 (defvar org-self-insert-command-undo-counter 0) (defvar org-speed-command nil) =2D-=20 2.37.2 --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Ihor Radchenko writes: > "Christopher M. Miles" writes: > >> I checked out your patch, it's fine to me. Should be fine to apply. > > Done. > Applied onto main. > https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=3D95df82c= 5fcf926088da2aaab9354a902956ae881 > > Going back to cycling inline image visibility now. > > I think that the first step should be extending > `org-remove-inline-images' and `org-display-inline-images' to work on > regions. `org-display-inline-images' already provides BEG and END > optional arguments, but it currently clears all the images in buffer > unconditionally. > > We will need to make `org-remove-inline-images' work on region and > modify `org-display-inline-images' to not affect images outside the > provided region. > > Then, we can modify `org-toggle-inline-images' accordingly and make use > of it in org-cycle.el to toggle images in section/subtree. =2D-=20 [ stardiviner ] I try to make every word tell the meaning that I want to express without mi= sunderstanding. Blog: https://stardiviner.github.io/ IRC(libera.chat, freenode): stardiviner, Matrix: stardiviner GPG: F09F650D7D674819892591401B5DF1C95AE89AC3 --=-=-=-- --==-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEE8J9lDX1nSBmJJZFAG13xyVromsMFAmM0RUIACgkQG13xyVro msNM9wf+MwezPOgjo+8rcnFMYmXF2y0BQOk37JO98aG2Ikvbj+KgK7YPSog/SE3B gq5abc8rL0qhXPHVyzxoVjNK/CutY7vm0U7seRlBFfvu24z+jggn+GKEBQk+iNQH x6N6DpGYzzzhWvIYjLr27tbQjTK6RZswkXnFoUTQiSGwZNiJq8ZFDuJ1txE6gzVo hipmHIj3CtY8p9/YkXot0Zi/EgNQlA5xXrdGNsjtYLPsyAl6BNo3kuWCbQ91b4Mb qvQ/cgiN3BjBZhfMcEChIBzzJ37PcDKuKBEzltCXlEy2F9h7AHYAsEcbDy7wvkka xx2QhG/afVP839i/2TM7JE6GKgMdGw== =dgrg -----END PGP SIGNATURE----- --==-=-=--