emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Christopher M. Miles" <numbchild@gmail.com>
To: Ihor Radchenko <yantar92@posteo.net>
Cc: "Christopher M. Miles" <numbchild@gmail.com>,
	Org mode <emacs-orgmode@gnu.org>
Subject: [PATCH v3.1] Re: [PATCH] add a function to only refresh inline images under current headline instead of global buffer
Date: Tue, 01 Aug 2023 20:17:04 +0800	[thread overview]
Message-ID: <64c905d7.170a0220.f434a.fddb@mx.google.com> (raw)
In-Reply-To: <87il9zgpdp.fsf@localhost>

[-- Attachment #1.1: Type: text/plain, Size: 2342 bytes --]

Ihor Radchenko <yantar92@posteo.net> writes:

> "Christopher M. Miles" <numbchild@gmail.com> writes:
>>> This is not a toggle. This is unconditional refresh.
>> Yes, indeed it's a unconditional refresh. It does not match the meaning of word "toggle".
>> Seems need to detect whether has image overlays in region. I added this
>> detection in new patch. Like bellowing:
>> #+begin_src emacs-lisp
>> ...
>> ((use-region-p)
>>     (if (seq-contains-p
>>          (mapcar
>>           (lambda (ov)
>>             (plist-get (overlay-properties ov) 'org-image-overlay))
>>           (overlays-in beg end))
>>          t)
> You can just use `org--inline-image-overlays'.

Aha, I forget this API function, I applied in new patch.

>>> And there is no clean way to allow INCLUDE-LINKED while keeping
>>> consistency with latex preview commands.
>> About the INCLUDE-LINKED argument, I don't know how to process it. In
>> theory, it should be handled by function org-display-inline-images
>> instead of org-toggle-inline-images. If you have improvements on it, can
>> you add code on my patch?
> The problem here is backwards compatibility. `org-toggle-inline-images'
> is bound to C-c C-x C-v and people may be used to C-u C-c C-x C-v
> displaying linked images like
> [[https://orgmode.org/resources/img/org-mode-unicorn.svg][description]]
> I will need to think more how to approach this.


>>> What we might do here is making a new defcustom that will control
>>> whether linked images should be displayed. Then, something like C-1
>>> org-toggle-inline-images could toggle that defcustom and refresh all the
>>> image previews in buffer (if any).
>>> WDYT?
>> Refreshing all image previews in buffer is same as old behavior.
> Sure. But the idea of this specific C-1 prefix argument is to toggle the
> hypothetical defcustom `org-inline-images-include-linked'. If we flip it
> we may need to remove/add linked image previews or otherwise risk users
> being confused by the defcustom not taking effect.

I checked source code, don't know where to insert this functionality.
Is it be in `org-display-inline-images` or somewhere else?
I will find time to checking code whether can add this in another patch.
If you have plan for this, let me know.

I think current patch is ready for merging now. WDYT?

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: 0001-org-Improve-inline-images-displaying-like-LaTeX-prev.patch --]
[-- Type: text/x-patch, Size: 5168 bytes --]

From 2f68f0172dc5e452c05a9d254eab8ae797bcd15b Mon Sep 17 00:00:00 2001
From: stardiviner <numbchild@gmail.com>
Date: Mon, 22 May 2023 16:25:33 +0800
Subject: [PATCH] org: Improve inline images displaying like LaTeX previewing

* lisp/org.el (org-toggle-inline-images): Implement LaTeX previewing
same logic in inline images toggle displaying.
 lisp/org.el | 89 ++++++++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 74 insertions(+), 15 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index e72cf056a..04f713d26 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -16160,22 +16160,81 @@ SNIPPETS-P indicates if this is run to create snippet images for HTML."
       (when (memq ov org-inline-image-overlays)
         (push ov result)))))
-(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'."
+(defun org-toggle-inline-images (&optional arg include-linked beg end)
+  "Toggle the display of inline images at point.
+INCLUDE-LINKED is passed to `org-display-inline-images'.
+If cursor is on an inline image link, display the inline image.
+If there is none, remove it otherwise.
+If there is no inline image link at point, display all inline images in the current section.
+With an active region, display inline images in the region.
+With a `\\[universal-argument]' prefix argument ARG, clear inline
+images in the current section.
+With a `\\[universal-argument] \\[universal-argument]' prefix
+ argument ARG, display all inline images in the buffer.
+With a `\\[universal-argument] \\[universal-argument] \
+\\[universal-argument]' prefix argument ARG, clear all inline
+images in the buffer."
   (interactive "P")
-  (if (org--inline-image-overlays beg end)
-      (progn
-        (org-remove-inline-images beg end)
-        (when (called-interactively-p 'interactive)
-	  (message "Inline image display turned off")))
-    (org-display-inline-images include-linked nil beg end)
-    (when (called-interactively-p 'interactive)
-      (let ((new (org--inline-image-overlays beg end)))
-        (message (if new
-		     (format "%d images displayed inline"
-			     (length new))
-		   "No images to display inline"))))))
+  (cond
+   ((not (display-graphic-p)) nil)
+   ;; Clear whole buffer inline images.
+   ((equal arg '(64))
+    (org-remove-inline-images (point-min) (point-max))
+    (message "Inline images preview disabled in buffer."))
+   ;; Display whole buffer inline images.
+   ((equal arg '(16))
+    (message "Displaying all inline images in buffer...")
+    (org-display-inline-images include-linked nil (point-min) (point-max))
+    (message "Displaying all inline images in buffer... done."))
+   ;; Clear current section.
+   ((equal arg '(4))
+    (let* ((beg (if (use-region-p)
+                    (region-beginning)
+                  (if (org-before-first-heading-p) (point-min)
+                    (save-excursion
+	              (org-with-limited-levels (org-back-to-heading t) (point))))))
+           (end (if (use-region-p)
+                    (region-end)
+                  (org-with-limited-levels (org-entry-end-position))))
+           (inline-images (org--inline-image-overlays beg end)))
+      (org-remove-inline-images beg end)
+      (message "%d inline images display removed." (length inline-images))))
+   ;; Display region selected inline images.
+   ((use-region-p)
+    (let ((beg (region-beginning))
+          (end (region-end)))
+      (if (org--inline-image-overlays beg end)
+          (progn
+            (org-remove-inline-images beg end)
+            (message "Inline images in region removed."))
+        (message "Displaying inline images in region...")
+        (org-display-inline-images include-linked t beg end)
+        (message "Displaying inline images in region... done."))))
+   ;; Toggle display of inline image link at point.
+   ((let ((context (org-element-context)))
+      (and (memq (org-element-type context) '(link))
+	   (let ((beg (org-element-property :begin context))
+		 (end (org-element-property :end context)))
+	     (if (org--inline-image-overlays beg end)
+                 (progn
+                   (org-remove-inline-images beg end)
+	           (message "Display inline image at point removed."))
+	       (org-display-inline-images include-linked t beg end)
+	       (message "Displaying inline image at point ... done."))
+	     t))))
+   ;; Display inline images under current section.
+   (t
+    (let ((beg (if (org-before-first-heading-p) (point-min)
+		 (save-excursion
+		   (org-with-limited-levels (org-back-to-heading t) (point)))))
+	  (end (org-with-limited-levels (org-entry-end-position))))
+      (message "Displaying inline images in section...")
+      (org-display-inline-images include-linked t beg end)
+      (message "Displaying inline images in section... done.")))))
 (defun org-redisplay-inline-images ()
   "Assure display of inline images and refresh them."
2.39.2 (Apple Git-143)

[-- Attachment #1.3: Type: text/plain, Size: 267 bytes --]


[ stardiviner ]
I try to make every word tell the meaning that I want to express without misunderstanding.

Blog: https://stardiviner.github.io/
IRC(libera.chat, freenode): stardiviner, Matrix: stardiviner
GPG: F09F650D7D674819892591401B5DF1C95AE89AC3

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]

  reply	other threads:[~2023-08-01 13:18 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-15  3:28 [PATCH] add a function to only refresh inline images under current headline instead of global buffer Christopher M. Miles
2023-05-15 11:08 ` Ihor Radchenko
2023-05-15 13:01   ` Christopher M. Miles
2023-05-15 14:00   ` [PATCH v2] " Christopher M. Miles
2023-05-16  9:17     ` Ihor Radchenko
2023-05-16 12:18       ` Christopher M. Miles
2023-07-24 11:25         ` Ihor Radchenko
2023-08-01  4:40           ` [PATCH v3] " Christopher M. Miles
2023-08-01  8:04             ` Ihor Radchenko
2023-08-01 12:17               ` Christopher M. Miles [this message]
2023-08-01 14:09                 ` [PATCH v3.1] " Ihor Radchenko
2023-08-01 15:22                   ` Christopher M. Miles
2023-08-01 15:46                   ` Christopher M. Miles
2023-08-02 16:08                     ` Ihor Radchenko
2023-08-04  6:30                       ` Christopher M. Miles
2023-08-02  7:26                 ` Ihor Radchenko
2023-08-02 15:44                   ` Christopher M. Miles
2023-08-04  8:20                     ` Ihor Radchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=64c905d7.170a0220.f434a.fddb@mx.google.com \
    --to=numbchild@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=yantar92@posteo.net \


* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).