From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id sONEHVELNWPfVAAAbAwnHQ (envelope-from ) for ; Thu, 29 Sep 2022 05:04:49 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id yKugHVELNWMVdAEA9RJhRA (envelope-from ) for ; Thu, 29 Sep 2022 05:04:49 +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 144E43DDCC for ; Thu, 29 Sep 2022 05:04:49 +0200 (CEST) Received: from localhost ([::1]:41754 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1odjqy-0007LX-9s for larch@yhetil.org; Wed, 28 Sep 2022 23:04:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55162) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1odjqS-0007Ja-2j for emacs-orgmode@gnu.org; Wed, 28 Sep 2022 23:04:16 -0400 Received: from mail-pg1-x532.google.com ([2607:f8b0:4864:20::532]:37386) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1odjqQ-00082k-8h for emacs-orgmode@gnu.org; Wed, 28 Sep 2022 23:04:15 -0400 Received: by mail-pg1-x532.google.com with SMTP id bh13so283805pgb.4 for ; Wed, 28 Sep 2022 20:04:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:from:to:cc:subject:date; bh=XoaIQtiAOWdZN3pt6zcU+Uut9cpb6F5aLiBWT2toP6c=; b=OrlsVKTI/omYP7V8M6NdVeNMvlvoegLADkLNbtFFaNmxvdNsrRxp1NLzOeG395iecg b3m2cuOLqQMj/XTuQgsEl80ZSnDxI+zUS9cXVJoWSrIQQGGjzbCC/M/s/pfKSDAW3vio KFQV+xaxXeXmGn2nvK/oT2qP5G1U83d5Uv4kfe+PWSXSEHrzxunEhIEnVDq59SG89Pnj I/LYV+Gki81QGdsojKvyk0DTlvxLVR19fcxCbv7Da5ao8UUcvX078zruZfjWtNAu91SG bQFK8cPznH2wtPHBr0ib/RdsJRPORrT5xiyBMtlc7KWhlijxliR4Lk0ucNbKDM9INPXI q7DA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date; bh=XoaIQtiAOWdZN3pt6zcU+Uut9cpb6F5aLiBWT2toP6c=; b=AXDAsg9o4he1tKemr7GK4WlbHZnbLaoYRtvzlG9BfuFxdAb0zp4dZrIHFvVQTpf1VE DnKt3eKsU6jPuLVxkj/tozVnAQs9lD/kXNq/YpThdnZR8J8Y09/kqNyLB1nPloKfbucf kqCCD5K9v9wn9bVG1Nbas53kZs3htamL2+8zF1fQrMVVlRnHCgX1FyVNBchIyZgAkwGJ RdkIcs0V2+Ic1/Ll2gNrRZK1IlPjWuOTYad0lIjcsJL7YS8puLXeFOuovOJP4josO64Y Oar2C5yHykPc+eJI03njNP9cVrrx+E1e+fFg4/VKgnuErFL4sBqcpXBkCmIPAXHLAhCa 4niw== X-Gm-Message-State: ACrzQf1H4UODKURW/DroiOx7GlZaiKODGEZr7fejyvdTt6GwqtiNMqHn MI1TxzoF7pAasbGk+JhfjNA= X-Google-Smtp-Source: AMsMyM7WjZhGp9VDt1OAXXpnaV+DvG7xRXp5omteo/U+7lPrMeEmnYMnJRqH7nQeOCbT7pvy+KS51w== X-Received: by 2002:a63:a61:0:b0:43c:9d3b:9c8f with SMTP id z33-20020a630a61000000b0043c9d3b9c8fmr967164pgk.228.1664420652388; Wed, 28 Sep 2022 20:04:12 -0700 (PDT) Received: from localhost ([2409:8970:a80:3a4:8ec6:81ff:fe70:339d]) by smtp.gmail.com with ESMTPSA id e18-20020a17090301d200b00172e19c2fa9sm4629188plh.9.2022.09.28.20.04.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Sep 2022 20:04:11 -0700 (PDT) From: Ihor Radchenko To: "Christopher M. Miles" Cc: emacs-orgmode@gnu.org Subject: Re: [PATCH 2-v1] New: auto display inline images under subtree when `org-cycle'. In-Reply-To: <633454e3.050a0220.7278b.1fa5SMTPIN_ADDED_BROKEN@mx.google.com> 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> Date: Thu, 29 Sep 2022 11:05:04 +0800 Message-ID: <87y1u298yn.fsf@localhost> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=2607:f8b0:4864:20::532; envelope-from=yantar92@gmail.com; helo=mail-pg1-x532.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 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 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-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1664420689; h=from:from:sender:sender: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:dkim-signature; bh=XoaIQtiAOWdZN3pt6zcU+Uut9cpb6F5aLiBWT2toP6c=; b=qA+qjBlchPyGrr+BAAw0vMG4K3KV9nQT1R3xxs1FFqFnIr5LDc2vGtpua1CuMv7wUovRrd r5VmYR4B5PcBhcGyi5TR3bhwCpw/Bq+KaATy54LAwFiGzlYLuKIOtdyxFfuIhHvz/ninLb q7gYedBYc4t27MWxcQ+5Xb38RlcQdUSNTvpfeN+fwZOu7tc8ifGigtMT9nrGMW/7z4Ydy+ /gcRqSBjX0J/e62l0co4WdmpesZv8MOkuGl3ZGWusxdpaUUIm0qGsoWPpIvXt6BG2LMdTT YovybRd5d+Im6N/OS/f10EYJL7azmXE1Z2umlof+Hiuyo0vdJqO+YqytIk47Mg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1664420689; a=rsa-sha256; cv=none; b=rAekh+eijrXziOb/JQ5zXrz0rLIp8XnG4sNRoQ8fmNQR4X3Gg8UdCxDHYr04YlFGwm241h pCG+xQch1434erEfVg10esQtVW2d8QI+zEYHq5MqRPQVYza8Rd7WUG6M2t+LEDAzysgK15 U4GEixNmPuqHaxWOQGqkalt4mQ3LQIppWGSJ0eGeyz4tkKpcdGZc0pOhAkHUdU6/vvs7VA /+vT7UF+JSwTIog2SE3miJGjpAfGy6u257oQtSRApTMr/6G47yJ+PUJy9DEsDfe71gtuZE fCNXmmBccUU7ORXJ2s13oPmGAQKiZ2tC7LxrO3QSyrfzVUIDJnwe/n5+q8DNJw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=OrlsVKTI; dmarc=pass (policy=none) header.from=gmail.com; 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: -3.35 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=OrlsVKTI; dmarc=pass (policy=none) header.from=gmail.com; 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: 144E43DDCC X-Spam-Score: -3.35 X-Migadu-Scanner: scn0.migadu.com X-TUID: tXD1fLlT7V9V "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. > 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 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) > > +(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. 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 `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))))) 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))) 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. -- Ihor Radchenko, Org mode contributor, Learn more about Org mode at https://orgmode.org/. Support Org development at https://liberapay.com/org-mode, or support my work at https://liberapay.com/yantar92