From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms13.migadu.com with LMTPS id CFhFHstI52amqwAAe85BDQ:P1 (envelope-from ) for ; Sun, 15 Sep 2024 20:51:23 +0000 Received: from aspmx1.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2.migadu.com with LMTPS id CFhFHstI52amqwAAe85BDQ (envelope-from ) for ; Sun, 15 Sep 2024 22:51:23 +0200 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=bx3pey0Q; 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" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1726433483; 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=BqiXEfX7qWzkxrGUPs+jQjqYQ09Zn3bPHwLgkTv94lA=; b=jJMeGhIFefJ8vdQwMVLokIt4rAATCNzihZBdIZpoo278SXyRTkyCsA09PziwuEOVzitfK2 mlObO+TdYoMJLnyk6GRYl/N7XvINz/R9qh/KSwzM6oHXBOZv+Ld+ek352D0Y6KvuaA8UYo s2zkWUXfw6CXiZCR1F6rK46hkeskmEGEf8dhVCz2+onit0KItDDLOMNCFOQ7vhbYsuRIap IB8UyeK+UktoPyWbRaViR4DfNSRydACFR/VOdWiGjp03A/hDuIKcaRGqZo1XZj5mbxn/dS 5Tf5BJrkSdDILXNmJn1/1raKeJfpsZthh3BGE6h7gvs23xEXByMbaz/7n6lj+g== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1726433483; a=rsa-sha256; cv=none; b=IromF9P3LeIYKyxLhg/dcFplF8vps0Ab7bRolfOrKswE63Eh/PwL/5IgsbscWu/cdeo/0k F7UomU/ouNMT6hSL6w2fQZNPMAf/VKryBV7PkebkHGBQlZkMk0g6os+8MvsmSHR+/sy4iC BL/mQTilr31h92VW9ekOm65bZKknFvXB82PvGosjmBlnHZrqkBwoWjuS6LqY2yGkr5a0Ae mQk4eESriqjA6kQrh5+KveV5iZg1mOs5Z8julNKd8FwIMRG/lo4JWU8AQPwgCOt1Q1qIag Li0SQ7HVpwWv+SmRjRDFegFCdGsFpJdw0wLOaeiDWr3V5tjLsKLHZOoEuUAoSQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=bx3pey0Q; 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" 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 1B114114FB for ; Sun, 15 Sep 2024 22:51:23 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1spwCX-000612-F6; Sun, 15 Sep 2024 16:50:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1spwCQ-00060e-7G for emacs-orgmode@gnu.org; Sun, 15 Sep 2024 16:50:27 -0400 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1spwCN-0002g8-L3 for emacs-orgmode@gnu.org; Sun, 15 Sep 2024 16:50:24 -0400 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-207115e3056so34056015ad.2 for ; Sun, 15 Sep 2024 13:50:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726433421; x=1727038221; darn=gnu.org; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=BqiXEfX7qWzkxrGUPs+jQjqYQ09Zn3bPHwLgkTv94lA=; b=bx3pey0QH/aGsg1RdhMjyoInj43zysOlGYSS5N5HlMRhSfrDsroxHW5NRjIXNjjEVi 7OvxSP9VPJJWTjve640Ha98tZt9lx0P50Sk/quoZm4i3KNA8VJo3OQ7xFJ68rY9TvMmz tcrogQpUsSgrKrr98zzrKvVFpXIKDXNJEa3weZQ7k+AuhtUn3lYWHwVNvwc1HhTXT/DL 7+6MpBQBBdhuNLmJyEyA1N/DLxMlpCpInfe/LHMp9xlWIVifH2SnLhTArr9Bzco3k8V3 4kA/qZ4/7UIiofYAFuT1WaynOS3wnCCydQ8RVU38id3O84VO1UAPwcxoTCnlADQJTcqG TJTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726433421; x=1727038221; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=BqiXEfX7qWzkxrGUPs+jQjqYQ09Zn3bPHwLgkTv94lA=; b=rAQu/BlstuBnJkI85kdkGUIJ4py12E0J+xWdVFm/zG5QtwsVOHS5uopM2sumNwdhnk Ky0Tac0URdbU8+IaiUpFo+TysBeliRQWPWW1iPnmpdpNnRyhZbql29+djE/oeXXgzufL gBtX6qdcGkRvjXeUyoGhtXssidHeNZgRVp2SmdCD3yoD1B1PKyckfiTjSDah0DpFwSJP 3Vcq40OnxYNpLqOrFAtsR55lA4UrIpuxZkccrnLNA4nuWynABIc/4cE+8oOqk2Cn/69e aURpQ/sv3b9QUIijdVVYcL5FKD6wAk1lHd6CoqQBvleJ38VZXfhF3CS0qZgIf/4kk0o4 /L1g== X-Forwarded-Encrypted: i=1; AJvYcCXNM/DxCxapITj2A6enPA83Ok4dZHDLReUg/+6GLt6hE8aZU1wSoNgCw2uVyRFQNmDyObRDASRw2lQRlNSJ@gnu.org X-Gm-Message-State: AOJu0Yy7zhIhL0htoJBZfF4LWy1RF/dNU4Vwuv6/uOmeVVpS6Nu1rf4B pOKyHJ5Q0wAM1py9UMlaSiAHdwvCq1tCi2BgGm7v3anUNhMICmxA X-Google-Smtp-Source: AGHT+IFQ55B9CNd2ypgce/Vp8i1cnpjh/NZsbOgykAtZVDwGuHf4iinHPNov9rCU1b7ov8RALufRJg== X-Received: by 2002:a17:902:dad2:b0:205:9112:efee with SMTP id d9443c01a7336-2076e3b6137mr201529005ad.21.1726433420633; Sun, 15 Sep 2024 13:50:20 -0700 (PDT) Received: from localhost ([2600:8802:5726:2500:bb6e:1fe8:98d1:570a]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-207946032aesm25520875ad.67.2024.09.15.13.50.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Sep 2024 13:50:19 -0700 (PDT) From: Karthik Chikmagalur To: Ihor Radchenko Cc: stardiviner , Org mode Subject: Re: [PATCH v3] Inline image display as part of a new org-link-preview system In-Reply-To: <87h6ah72ui.fsf@localhost> References: <6461a84b.a70a0220.b6d36.5d00@mx.google.com> <871q3logb9.fsf@localhost> <66a8b73b.170a0220.383476.996e@mx.google.com> <87o75yhwnu.fsf@localhost> <87v7zyyvm3.fsf@localhost> <87frr07xz8.fsf@gmail.com> <87cym38aj8.fsf@gmail.com> <87r0ajawgj.fsf@localhost> <87a5h77zb1.fsf@gmail.com> <87msl4wv8d.fsf@localhost> <875xrqg6cb.fsf@gmail.com> <874j70n559.fsf@localhost> <87msksabld.fsf@gmail.com> <87jzfwljkq.fsf@localhost> <87h6b09v4o.fsf@gmail.com> <878qwb8qw1.fsf@localhost> <878qw9ak6a.fsf@gmail.com> <87o74ypp3b.fsf@localhost> <87r09rxpjg.fsf@gmail.com> <87h6ah72ui.fsf@localhost> Date: Sun, 15 Sep 2024 13:50:18 -0700 Message-ID: <875xqw63qt.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=2607:f8b0:4864:20::62c; envelope-from=karthikchikmagalur@gmail.com; helo=mail-pl1-x62c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_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-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: -5.61 X-Spam-Score: -5.61 X-Migadu-Scanner: mx13.migadu.com X-Migadu-Queue-Id: 1B114114FB X-TUID: mL08Um1ar1/j >>> Image cache is cleared _only_ with REFRESH argument. >>> I think that makes sense, right? >> >> Yes. But `org-link-preview-region' is always called with the REFRESH >> argument set to `t' though. > > Sure. What's a problem with that? Why flush Emacs' entire image cache to preview images in one Org buffer? This has implications for other Emacs buffers with lots of images, like Org buffers with LaTeX previews. I'm not sure about how much it matters though. > In theory, we might not need to clear image cache as long as we call > `image-flush' in `org-link-preview-clear'. image-flush is called unconditionally in `org-link-preview-file', so it should be fine to not set REFRESH unconditionally. I'll keep the REFRESH argument around but remove the Emacs-wide (clear-image-cache). >> Moved (require 'image) to inside the `org-link-preview-file'. I know it >> doesn't affect performance in any reasonable way, but I'm usually >> hesitant to do this in functions that run inside loops. > > There are pros and cons. > Ideally, we should have these previews in a separate library, so that > loading Org mode does not need to require so much staff. Loading time is > not great already. > > My hesitance about top-level require is that ol.el is loaded by default > and that the preview functionality may or may not be used by the > users. So, loading image.el ought to be optional. Okay. >> ... >> + ;; Run preview asynchronously in batches: >> + ;; preview-queue is a list of preview-batch, which is a list of preview-spec >> + (when (car preview-queue) >> + (dolist (preview-batch (nreverse preview-queue)) >> + (run-with-idle-timer >> + org-link-preview-delay nil > > It means that you are scheduling every single preview batch to fire at > the same time. I think that the timers here should run sequentially - > (1) fire the first batch without delay; (2) wait org-link-preview-delay > and fire the next batch; (3) ... You're right, I'll redo this. Scheduling many idle timers at once is tricky, the manual even warns against making idle timers setting up the next one with the same idle time: --8<---------------cut here---------------start------------->8--- Similarly, do not write an idle timer function that sets up another idle timer (including the same idle timer) with SECS argument less than or equal to the current idleness time. Such a timer will run almost immediately, and continue running again and again, instead of waiting for the next time Emacs becomes idle. The correct approach is to reschedule with an appropriate increment of the current value of the idleness time, as described below. --8<---------------cut here---------------end--------------->8--- So I'll have to do it carefully. >> + (lambda (previews) >> + ;; (message "queue: %d" preview-queue-size) >> + (cl-decf preview-queue-size) >> + (dolist (preview-spec (nreverse previews)) ;spec is (preview-func overlay path link) >> + (when-let* ((ov (cadr preview-spec)) >> + (buf (overlay-buffer ov))) > > ov or its buffer may not exit at the time the timer is fired. > Because, for example, the buffer is killed, or because user edited the > underlying link before it got displayed. This is handled by the (when-let* ((buf (overlay-buffer ov)))) part. (overlay-buffer ov) is nil if the overlay is gone, or if the buffer is gone. Karthik