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 IIMzOPg8NWMlDQEAbAwnHQ (envelope-from ) for ; Thu, 29 Sep 2022 08:36:40 +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 OCnuN/g8NWNwWgEAauVa8A (envelope-from ) for ; Thu, 29 Sep 2022 08:36:40 +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 601A23710 for ; Thu, 29 Sep 2022 08:36:39 +0200 (CEST) Received: from localhost ([::1]:60758 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1odn9y-0006Cr-Eu for larch@yhetil.org; Thu, 29 Sep 2022 02:36:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56808) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1odmzc-0002fn-Df for emacs-orgmode@gnu.org; Thu, 29 Sep 2022 02:25:56 -0400 Received: from [39.171.215.24] (port=6131 helo=Mac-mini.local) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1odmza-0005Cp-CN for emacs-orgmode@gnu.org; Thu, 29 Sep 2022 02:25:56 -0400 Received: by Mac-mini.local (Postfix, from userid 501) id 2D13C6641B89; Thu, 29 Sep 2022 14:25:44 +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> 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-v1] New: auto display inline images under subtree when `org-cycle'. Date: Thu, 29 Sep 2022 14:06:40 +0800 In-reply-to: <87y1u298yn.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=1664433399; 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=HwROfoewatEwUkylkiTdKD4eOZMBW3gfrnOej2W8a54=; b=gp441aqnSoHfJtGNzq0kl6WEx5arSQjUOJXkFO6VJm7pjWs8JacEDNpVsfnp29dQ4+RX6M gGXdo632z3UuFJAbTWk2eUInqcRQi6y5fwiaSbjlF7rIQk3479Pq9ZDypT0CeHZXYpUvXp guaPqtg6Vay/7wOjPPmTrVSE4ySuAP9pqMraQ1e7VmJl9rYGInVzpQpjJbaZ/yRcYcgGOZ 75DawS9e8ISucnjjfjaIubzqMlHm4YRbYEQisYPhcsrloPqlf61ThP+z35VELZQyST8Io+ h2umG8dBqd/bkgHLRUK78KpsrHN8TnCh8zQmVGk1HaAFmPv+Z6EOoZKG3ntkVA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1664433399; a=rsa-sha256; cv=none; b=tNhH/90OzQDzoTBsCDY0t4mX1r+mvKnoV/0Ezu0mBMaByJw1Fs4aLCnLqhMwQAgK3bK0GZ 3AAJ5fVH6a/YSkIzbQp2M4SZX9R7lEuxYS63vgekyPl7sQHMziJTupXn65PUEwYr4o8OQf R3HWPjLRKsCPRDe0MCseJHznKLfgYSF3vVaTKmCluJRfova/QFuSDe/zEB/9gyf90N9RCV A6RetH7hrJ76eznHdmnMVnQx6dYkfS6efc4yQlENjmi6znMM6n+JRNfJUptdU705ISZ1tk +nqKpDx+/ReZH7kZT/2q94KkDjcPj6Qji9u+doiPRremkdOXNXb6up1Xgb/iCg== 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.75 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: 601A23710 X-Spam-Score: 2.75 X-Migadu-Scanner: scn0.migadu.com X-TUID: C+GULDxGImer --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable 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? > "Christopher M. Miles" writes: > >> 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. > > Thanks for the update! > > For tests, you will need to test the existence of image overlays. > You can refer to test-org-fold/org-fold-reveal-broken-structure but > need to test overlays-at instead of just org-invisible-p. > I will try to write tests later. >> 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. > > I will comment in the code. > >> (defcustom org-cycle-hook '(org-cycle-hide-archived-subtrees >> - org-cycle-show-empty-lines >> - org-cycle-optimize-window-after-visibility-change) >> + org-cycle-show-empty-lines >> + org-cycle-optimize-window-after-visibility-= change >> + 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 indica= tes >> 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 wi= th the cycling commands." >> :group 'org-cycle >> :type 'boolean) >>=20=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) > > 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.) > > In this area, we generally do not use custom variables (see M-x > customize-group org-cycle). So, it is better to use hook. > >> -(defun org-remove-inline-images () >> +(defun org-remove-inline-images (&optional beg end) >> "Remove inline display of images." >> (interactive) >> - (mapc #'delete-overlay org-inline-image-overlays) >> - (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 `del= ete-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))))) > > You can just > > (dolist (ov overlays) > (when (memq ov org-inline-image-overlays) > (setq org-inline-image-overlays (delq ov org-inline-image-overlays)) > (delete-overlay ov))) Done > Note that `delete' and `delq' are not safe to use on their own. You > should always use (setq foo (delq 'member foo)). It is detailed in the > docstring. Thanks for teaching. =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----- iQEzBAEBCAAdFiEE8J9lDX1nSBmJJZFAG13xyVromsMFAmM1OmgACgkQG13xyVro msPRNQgA0BLDOWIwkDrGlNWYQve+DRN4HZPnbhm68v1ilno6xGqn1GuKtAbkqo7T yyEwAqgVDxnLLtgCTovpA8dtbyTIlXWTi0cBxAYj5Yx8KBDWYWlaoAUnIELQo0P2 XS374N+FMKwAu++Ei156jNLjyyNXJGM4jTLy/zr4ZE+YkeV9UzMAugZ8lucEmP44 aau/t9EdQotPucratis3cuFsBRkcMlFX+jOKuPxoBsKdNy20SsTmx+wM0BQv9IU8 3HxAdoj7m5hVyRNiBkHw7vlvQpeJPcoxrQmGn+1CukywRfL8Gi5JeuT4iBxv+euB lMU2djTcdl9EL7dua+NDbELYQW5Fdg== =1ZQa -----END PGP SIGNATURE----- --=-=-=--