From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id 4HwmNnepNmMoEAEAbAwnHQ (envelope-from ) for ; Fri, 30 Sep 2022 10:31:52 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id yND1NHepNmNtSgEAG6o9tA (envelope-from ) for ; Fri, 30 Sep 2022 10:31:51 +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 73DD63E61E for ; Fri, 30 Sep 2022 10:31:51 +0200 (CEST) Received: from localhost ([::1]:33210 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oeBQz-0001kL-LT for larch@yhetil.org; Fri, 30 Sep 2022 04:31:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42190) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oeBQP-0001k9-G1 for emacs-orgmode@gnu.org; Fri, 30 Sep 2022 04:31:13 -0400 Received: from [2409:8a28:6039:e940:52d2:f5ff:fe16:c591] (port=51973 helo=Mac-mini.local) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oeBQM-00068C-8j for emacs-orgmode@gnu.org; Fri, 30 Sep 2022 04:31:13 -0400 Received: by Mac-mini.local (Postfix, from userid 501) id 42749665B687; Fri, 30 Sep 2022 16:31:00 +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> <633454e3.050a0220.7278b.1fa5SMTPIN_ADDED_BROKEN@mx.google.com> <87y1u298yn.fsf@localhost> <63353c69.370a0220.67788.e8a1SMTPIN_ADDED_BROKEN@mx.google.com> <87o7ux4khz.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: Re: [PATCH 2-v2] New: auto display inline images under subtree when `org-cycle'. Date: Fri, 30 Sep 2022 16:27:24 +0800 In-reply-to: <87o7ux4khz.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 2409:8a28:6039:e940:52d2:f5ff:fe16:c591 (deferred) Received-SPF: softfail client-ip=2409:8a28:6039:e940:52d2:f5ff:fe16:c591; envelope-from=numbchild@gmail.com; helo=Mac-mini.local X-Spam_score_int: 25 X-Spam_score: 2.5 X-Spam_bar: ++ X-Spam_report: (2.5 / 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, 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: 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: , 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=1664526711; 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=r1exSdI94k02wXiP/BRmRDwbKikAYWAulGYOXmlxcgY=; b=WG1OvvEp8GTnG0X60W4GNiESfrlc2qr1C3Odo0LpuqNIYQgO49XpYMp1xwRCawANQPzfoj DUuyMSbt3uoYAIS22aEN3edaBGbLJQ6GpiK9zKZvMsJZEymyey7bIi3DvK22DeB8NeFhwa XuIluRhGZC2DOGMeYTtqcfK+y4gInq8Mp/3dgzQNDQND5/frnxPowqy0XCAQIvdUdLSdNb 63iqrvorroBQOwWYHyfVvxsNfn/XlDIfoTQlilmhCn9he6XyBroh68aS7UPWHW1gy/OzGB kIUr4wkNFh7zDOrg5sHmr7DGdYkhMSza61kJz1D8qC/2zCupdmpPLMSRgAw+Ew== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1664526711; a=rsa-sha256; cv=none; b=hOOaABuTZo1k2ZJl8Mz2OkJBuIom3YQ376uVzGOdw7LbDQlwiiKEN9xP6DbWTR++dHSbL3 +qY6EJh4RcTgMzNtPuCQihfV3jFr9sPzItE2Rh8HZSmbrGioLsmDSo/KWIchrH1DbIs9nZ Oy33eRRlWgRnHExy6kal2XfFRtSawNP4Kz5LiRi2RkaLpuCvbVgPjQ4rG+zj93JxYte5Ke ul/pbmxsQdwCDoSTkA5vv0Exl3D7i4NMnR4fVoq+ILt513oZpi4v55CbFkGlmObZBoi2Bu Gzkj954mS+CaWRumcgp5kYguqkZhdVJIglVZEIsT8O3brINbrT4eL0x7QST3Zw== 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: 2.76 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: 73DD63E61E X-Spam-Score: 2.76 X-Migadu-Scanner: scn1.migadu.com X-TUID: pvBc2u+FXjUO --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain Ihor Radchenko writes: > "Christopher M. Miles" writes: > >> Ihor Radchenko writes: >> >> I got a new problem in patch, the (point-max) in function >> ~org-cycle-display-inline-images~ SOMETIMES return EOF error instead of >> correct max point value when org-cycle `state' is ~'folded~. I can't >> find out what caused this even using Edebug. Do you have any clue? > > Maybe because the 'folded branch in that function is not wrapped into > `save-restriction'? > Ah, Indeed, I forgot to wrap it. Now I fixed this error. I attached new version 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=20570551a39038cf4190cd7cb453a8d059326b9dcb 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. * testing/lisp/test-org-fold.el (test-org-fold/org-fold-display-inline-imag= es): Add test for inline image displaying when cycling. =2D-- lisp/org-cycle.el | 41 ++++++++++++++++++++++++++++-- lisp/org-keys.el | 2 +- lisp/org.el | 21 +++++++++------ testing/lisp/test-org-fold.el | 48 +++++++++++++++++++++++++++++++++++ 4 files changed, 101 insertions(+), 11 deletions(-) diff --git a/lisp/org-cycle.el b/lisp/org-cycle.el index 656ca83f2..6204b8a4f 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,36 @@ 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 + (save-excursion + (save-restriction + (org-narrow-to-subtree) + ;; FIXME: sometimes `point-max' is EOF. + (if (numberp (point-max)) + (org-remove-inline-images (point-min) (point-max)) + (ignore)))))))) + (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..36db62f0c 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,16 @@ 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) + (when (memq ov org-inline-image-overlays) + (setq org-inline-image-overlays (delq ov org-inline-image-overlays= )) + (delete-overlay ov))))) =20 (defvar org-self-insert-command-undo-counter 0) (defvar org-speed-command nil) diff --git a/testing/lisp/test-org-fold.el b/testing/lisp/test-org-fold.el index 0fa800dee..5c47cafb4 100644 =2D-- a/testing/lisp/test-org-fold.el +++ b/testing/lisp/test-org-fold.el @@ -604,6 +604,54 @@ Unfolded Paragraph. (org-fold-check-before-invisible-edit kind) (should (org-invisible-p (1- (point)))))))))) =20 +;;; TODO: reference `test-org-fold/org-fold-reveal-broken-structure' +(ert-deftest test-org-fold/org-fold-display-inline-images () + "Test inline images displaying when cycling." + (let ((org-fold-core-style 'text-properties) + (org-cycle-inline-images-display t)) + ;; `org-cycle' -(state)-> `'children' display child inline images. + (org-test-with-temp-text + "* Heading 1 +[[file:image.png]]" + (org-overview) + (org-cycle) + (org-next-link) + (should (overlays-at (point))) + (org-toggle-inline-images) + (should-not (overlays-at (point)))) + ;; `org-cycle' -(state)-> `'subtree' display subtrees inline images. + (org-test-with-temp-text + "* Heading 1 +[[file:image.png]] +** Subheading 1 +[[file:image2.png]] +** Subheading 2 +[[file:image3.png]]" + (org-overview) + (org-cycle) + (org-cycle) + (org-next-link) + (org-next-link) + (should (overlays-at (point))) + (org-toggle-inline-images) + (should-not (overlays-at (point)))) + ;; `org-cycle' -(state)-> `'folded' remove inline image overlays. + (org-test-with-temp-text + "* Heading 1 +[[file:image.png]] +** Subheading 1 +[[file:image2.png]] +** Subheading 2 +[[file:image3.png]]" + (org-overview) + (org-cycle) + (org-cycle) + (org-cycle) + ;; TODO: how to detect inline image overlays are deleted after folded? + (should (overlays-at (point))) + (org-toggle-inline-images) + (should-not (overlays-at (point)))))) + (provide 'test-org-fold) =20 ;;; test-org-fold.el ends here =2D-=20 2.37.2 --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable >>> You are providing both hook and a customization. It is redundant. Users >>> can already remove the hook when desired. >> >> I mock this style from a very similar existing hook function >> ~org-cycle-hide-archived-subtrees~ and custom variable >> ~org-cycle-open-archived-trees~. I think removing a hook function from >> ~org-cycle-hook~ is a way, but not as convenient as defcustom option. >> (P.S: I think users prefer this defcustom customization style.) > > I see your point. > I agree that having a variable is better and also leaves an option to > introduce in-buffer setting for this. > > Let's leave the hook part for now - if we want to alter it, we may need > to re-consider all the default hooks. Thanks =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----- iQEzBAEBCAAdFiEE8J9lDX1nSBmJJZFAG13xyVromsMFAmM2qUQACgkQG13xyVro msOjHAgAgZc2K0AwPMnqjmpkHt/iDVFjeTnjG8WXcpO6sy0DJrYwljjGGexL9yIt wU4SYq7e6LmJl1ePSbZxnmIHRS4+gkVzYzrzVNV+YnfK8KCMPrrSbHJoWSz5Xzgc Hno9wNzb33pWXFT6Ovb636/fVF66fGko2j5ly3VKBMIXluoq+30GLFqGPScDt+eJ PcU0e8CCUxRlJuwVvVA3UgE/QVBk1kcpLU0Ig1KDEMk2vFjuB4gY/hxrJu4YmsLR KkY5+Lxcz3AzMew5oHB2ntTwRoS+gp0KmoCXI7YZSNmzos2pbjO8GCnzyht5c0Q7 oDQR74R+HvamuavP/R4zBwD5K1GxpQ== =JBCu -----END PGP SIGNATURE----- --==-=-=--