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 yCpZIgyTHmMBNgAAbAwnHQ (envelope-from ) for ; Mon, 12 Sep 2022 04:01:48 +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 aBV0IgyTHmNdGQEA9RJhRA (envelope-from ) for ; Mon, 12 Sep 2022 04:01:48 +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 41B523F823 for ; Mon, 12 Sep 2022 04:01:48 +0200 (CEST) Received: from localhost ([::1]:52386 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oXYlf-0001yZ-H3 for larch@yhetil.org; Sun, 11 Sep 2022 22:01:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47388) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oXYl6-0001xX-4A for emacs-orgmode@gnu.org; Sun, 11 Sep 2022 22:01:12 -0400 Received: from [2409:8a28:6038:5440:52d2:f5ff:fe16:c591] (port=62913 helo=Mac-mini.local) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oXYl3-0007Bl-Jk for emacs-orgmode@gnu.org; Sun, 11 Sep 2022 22:01:11 -0400 Received: by Mac-mini.local (Postfix, from userid 501) id 9B3D3631495C; Mon, 12 Sep 2022 10:01:01 +0800 (CST) References: <631d472b.c80a0220.2b4b2.bf86SMTPIN_ADDED_BROKEN@mx.google.com> <87h71ew0m0.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] New: auto display inline images under subtree when `org-cycle'. Date: Mon, 12 Sep 2022 09:59:54 +0800 In-reply-to: <87h71ew0m0.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:6038:5440:52d2:f5ff:fe16:c591 (deferred) Received-SPF: softfail client-ip=2409:8a28:6038:5440:52d2:f5ff:fe16:c591; envelope-from=numbchild@gmail.com; helo=Mac-mini.local X-Spam_score_int: 36 X-Spam_score: 3.6 X-Spam_bar: +++ X-Spam_report: (3.6 / 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=1.12, T_SCC_BODY_TEXT_LINE=-0.01 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-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1662948108; 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=DAYbbyeoXi15gGSC/FBucg/sKwo2whOJ+p91yuqpBq0=; b=CU2pjMt8+0eHlGaQGlGJDF/7MGa2Mi2FncYrb/PcPVLT3pVKRyFh3OCkojaq7l6afnWe6a C5mDhGLIqTrStzWJrP6bfdzIHfjvCpvIUtNEbmtnLupCIOM7JDVDTXvHly7Mp8IbAZXYCL hp2nWbKcCYqwBFKoRPQ2pMyhz2o+JS6uTfugzqpWg79y67IyG5ooCPxQGFxZgKxdoFdsX2 8rQ5bp77so2knw6CjbnBRQ5jNlgXORc0HsPWMP11NB4XASS8HVRadEnrDjuTlcIymSVs76 5PnCEKYMIc2dHVdkQHPYlEvFfUerG3a3FOMPuoJaGtZtcLTXtDKQNRRjJ0fmYg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1662948108; a=rsa-sha256; cv=none; b=beJTF2QtUOYUK4fpzkPyHkt1gR1XsKQGpscyTq8U72GQmU/9CI4u3kjr/QnwsN7Dl5QpM5 9Jg/rduWTBPVFhEZGWAaVzU/GHwt284qoTpGRTQhjiQv267LYQhqkl3p3aWh3YuttMAkc2 NM/0MLzQnxhY3MzuserzqbjEMNgo1Da+rq2VWceWSAxu90yT+Tl15T0xqjRQBt0NoHNDJB c/cpO4ObTgphxSbtGx51BCexJv+kDzffpPDDIV1nJSslAK7XvOQvoGmaJ0f1J7jJOjMFN7 Eh4e24ea2OGjzYIFPBujLtbyEsP6PTwOksGyzwt+dGgrLm00lqoIxSmwteiq9Q== 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: 1.30 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: 41B523F823 X-Spam-Score: 1.30 X-Migadu-Scanner: scn1.migadu.com X-TUID: 9F70Gp3zdX3J --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain Ihor Radchenko writes: > "Christopher M. Miles" writes: > >>> When I put it on beginning of org document, then preview inline images, but those global attributes >>> not affected. The inline images still display in actual image size. I want to specify image size >>> under headline properties. Is it possible to do this? >> >> I implemented this feature by written a hook. Hope this can be helpful >> for someone who also has this needs. Here is the code: > > This looks useful. > Would you be interested to write a patch? The is the new patch which updated the defcustom variable docstring has correct description. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-org.el-Add-hook-function-to-auto-display-inline-imag.patch Content-Transfer-Encoding: quoted-printable From=204f66d9d10de5593b863da605ddc375d8f2e06456 Mon Sep 17 00:00:00 2001 From: stardiviner Date: Mon, 12 Sep 2022 09:45:09 +0800 Subject: [PATCH] org.el: Add hook function to auto display inline images of subtree * lisp/org.el (org-display-subtree-with-inline-images): Add an option and hook function to auto display of inline images under current expanded visible subtree. =2D-- lisp/org.el | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/lisp/org.el b/lisp/org.el index 6e6c437d5..92086704e 100644 =2D-- a/lisp/org.el +++ b/lisp/org.el @@ -1108,6 +1108,13 @@ the following lines anywhere in the buffer: :version "24.1" :type 'boolean) =20 +(defcustom org-cycle-display-inline-images nil + "Non-nil means auto display inline images under subtree when `org-cycle' +by the function `org-display-subtree-with-inline-images' on hook `org-cycl= e-hook'." + :group 'org-startup + :version "24.1" + :type 'boolean) + (defcustom org-startup-with-latex-preview nil "Non-nil means preview LaTeX fragments when loading a new Org file. =20 @@ -16284,6 +16291,57 @@ buffer boundaries with possible narrowing." (mapc #'delete-overlay org-inline-image-overlays) (setq org-inline-image-overlays nil)) =20 +(defun org-display-subtree-with-inline-images (&optional state) + "Toggle the display of inline images under current expanded visible subt= ree. +This hook function will auto display or hide inline images after `org-cycl= e'. +It is used to hook on `org-cycle-hook'. +The function behavior is controlled by `org-cycle-display-inline-images'." + (interactive) + ;; (not (memq state '(overview folded contents))) ; global state change + (when org-cycle-display-inline-images + (let ((display-inline-images-local + (lambda (beg end) + (org-display-inline-images t t beg end) + ;; display number of inline images which is intersection of t= wo image overlays lists. + ;; (message "%d images displayed inline" + ;; (length (cl-intersection org-inline-image-overlay= s (overlays-in beg end)))) + )) + (hide-inline-images-local + (lambda () + (setq org-inline-image-overlays nil) ; (org-remove-inline-ima= ges) + (message "Inline image display turned off"))) + (inline-image-width-override ; get headline property value as= inline image width. + (lambda () + ;; The property "INLINE-IMAGE-WIDTH" value should be integer.= Reference `org-display-inline-image--width'. + (let* ((property-value (ignore-errors (org-property-or-variab= le-value 'INLINE-IMAGE-WIDTH))) + (width-integer (or (and property-value + (if (numberp property-value) p= roperty-value (string-to-number property-value))) + (- (/ (window-width (selected-windo= w) t) 2) 100)))) + (setq-local org-image-actual-width width-integer))))) + (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-bindi= ng + ;; `org-next-visible-heading'. + (funcall display-inline-images-local (point-min) (progn (org-= next-visible-heading 1) (point)))))) + ('subtree + (save-excursion + (save-restriction + (org-narrow-to-subtree) + (funcall inline-image-width-override) + ;; If has nested headlines, also inline display images under = all sub-headlines. + (funcall display-inline-images-local (point-min) (point-max))= ))) + ('folded + (funcall hide-inline-images-local)) + ('nil (funcall 'org-toggle-inline-images)))))) + +(add-hook 'org-cycle-hook #'org-display-subtree-with-inline-images) + +(add-to-list 'org-default-properties "INLINE-IMAGE-WIDTH") + (defvar org-self-insert-command-undo-counter 0) (defvar org-speed-command nil) =20 =2D-=20 2.37.2 --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable =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----- iQEzBAEBCAAdFiEE8J9lDX1nSBmJJZFAG13xyVromsMFAmMekt0ACgkQG13xyVro msOGfAgAmw8JfaZAjTHsxKNv4/OgQz3PZ4e8AqxJkIRv5JJaFzEXrAffFz95vwij s8Uj+HxkDejlgcQxPFnAK42S51zBo97z5QlYLKAmLSXImllJbS7SjTkQatmhnNIV ssNrBliMumd7Lj4RHXu4QuHk+71nDPTOsbPHOGdOyJ6nMVaxuF36zXj/LFnAXDcW hdaR9bNvflj+SBk+GEM6wwOgxPE+WS/r6cBpSwE0tqqxmFm1057l2ysc5tsPALOA uMhHzb4eJq6suRS3qRMzpetkRSjHu8jWm+1FjIKvMzofXD0AgqZLMVOziXa9ZUkg vw9u/ql31xfP8/jNxf8YHY8XLiMZPA== =DhuK -----END PGP SIGNATURE----- --==-=-=--