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.2] Re: [PATCH] add a function to only refresh inline images under current headline instead of global buffer
Date: Sat, 05 Aug 2023 13:28:34 +0800 [thread overview]
Message-ID: <669882e5.050a0220.8ff6d.33c6@mx.google.com> (raw)
In-Reply-To: <87msz7kym0.fsf@localhost>
[-- Attachment #1.1: Type: text/plain, Size: 3247 bytes --]
Ihor Radchenko <yantar92@posteo.net> writes:
> "Christopher M. Miles" <numbchild@gmail.com> writes:
>
>>> I think that instead of changing the existing function, we can convert
>>> your patch into a new function `org-toggle-inline-images-command' that
>>> will be free to alter the argument order. We can then re-bind that
>>> function in org-keys to make it used by default, but only interactively.
>>>
>> I don't think so, the patch main purpose is for improve image refreshing
>> after babel result image displaying. Because the function is hooked by
>> other ob-* packages. Another purpose is headline level images displaying.
>> So modifying this function is the only way.
>
> Fair point.
> Then, for backward compatibility, we may treat any non-nil, non-list
> (like '(4), '(16), '(64)), non-number (like 1, 11) value as
> INCLUDE-LINKED. This way, the existing calls like
> (org-toggle-inline-images t) will not be broken.
>
> Also, the signature should be
>
> (defun org-toggle-inline-images (&optional arg beg end include-linked)
>
> So that the meaning of the second and third argument is unchanged.
>
I prefer this compromise result.
I updated the patch, Please review it whether it's correct.
>>> As for displaying linked images, what about something like
>>>
>>>
>>> C-1 C-c C-x C-v being equivalent of
>>> C-c C-x C-v + INCLUDE-LINKED=t
>>> (display in current section/region, with linked)
>>>
>>> and
>>>
>>> C-11 C-c C-x C-v being equivalent of
>>> C-u C-u C-c C-x C-v + INCLUDE-LINKED=t
>>> (display in the whole buffer, with linked)
>>>
>> Don't know, I have not use it this way. I think INCLUDE-LINKED is just a
>> option argument for function org-display-inline-images. No need to be
>> available for toggle in interactive command. An option like
>> org-inline-images-include-linked is enough.
>
> Sorry, but ignoring backwards compatibility is not an option.
> If you personally haven't used some feature, it does not mean that
> others also didn't.
>
> We can make limited compromises, but should try our best not to break
> things that were working before.
> See https://bzg.fr/en/the-software-maintainers-pledge/
>
I agree with backward compatibility is very important.
I did a source code statistics researching of using the function org-toggle-inline-images at two places:
- GitHub: https://github.com/search?q=org-toggle-inline-images&ref=opensearch&type=code&p=3
(Only package scimax incoke this function with INCLUDE-LINKED argument t)
- My installed Emacs packages, NO package invoke this function with argument INCLUDE-LINKED.
So lucky this change will not affect lot.
>>>> +If cursor is on an inline image link, display the inline image.
>>>> +If there is none, remove it otherwise.
>>>
>>> I do not quite understand what the last line is trying to say.
>>
>> Emmm, I forget the meaning of it. I read the docstring again, seems it
>> can be deleted. I will delete it in my patch.
>
>> After yesterday night studying source code, I still can't figure out
>> solution. So I pass this patch to you. Wait you to finish the unfinished
>> part of path.
>
> I hope that now you have enough information to update the patch.
> Let me know if not.
If this patch is still not ok, really hope you can edit my patch.
[-- 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: 6281 bytes --]
From a2707a0f92c76188c3ebb412fe2b57788b50ca9a 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-keys.el | 2 +-
lisp/org.el | 95 ++++++++++++++++++++++++++++++++++++++++--------
2 files changed, 81 insertions(+), 16 deletions(-)
diff --git a/lisp/org-keys.el b/lisp/org-keys.el
index 38fac57d8..7b3b84af4 100644
--- a/lisp/org-keys.el
+++ b/lisp/org-keys.el
@@ -204,7 +204,7 @@
(declare-function org-toggle-radio-button "org" (&optional arg))
(declare-function org-toggle-comment "org" ())
(declare-function org-toggle-fixed-width "org" ())
-(declare-function org-toggle-inline-images "org" (&optional include-linked beg end))
+(declare-function org-toggle-inline-images "org" (&optional arg beg end include-linked))
(declare-function org-latex-preview "org" (&optional arg))
(declare-function org-toggle-narrow-to-subtree "org" ())
(declare-function org-toggle-ordered-property "org" ())
diff --git a/lisp/org.el b/lisp/org.el
index e72cf056a..c01952b97 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -16160,22 +16160,87 @@ 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 beg end include-linked)
+ "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 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...")
+ (let ((include-linked t)) ; assume INCLUDE-LINKED be t here for backward compatibility.
+ (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))))
+ ;; [M-1] / [C-1] argument for linked images like:
+ ;; [[https://orgmode.org/resources/img/org-mode-unicorn.svg][description]]
+ ((equal arg 1)
+ (let ((current-prefix-arg nil)
+ (include-linked t)) ; assume INCLUDE-LINKED be t here for backward compatibility.
+ (org-toggle-inline-images nil nil nil include-linked)))
+ ;; 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 --]
next prev parent reply other threads:[~2024-07-18 2:51 UTC|newest]
Thread overview: 40+ 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 ` [PATCH v3.1] " Christopher M. Miles
2023-08-01 14:09 ` 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
2023-08-05 5:28 ` Christopher M. Miles [this message]
2024-07-22 10:46 ` [PATCH v3.2] " Ihor Radchenko
2024-08-01 22:58 ` [PATCH v4.0] " stardiviner
[not found] ` <66a8b73b.170a0220.383476.996e@mx.google.com>
2024-08-12 10:18 ` Ihor Radchenko
2024-08-14 2:04 ` stardiviner
2024-08-18 10:27 ` Ihor Radchenko
2024-08-20 2:02 ` Karthik Chikmagalur
2024-08-20 15:43 ` Karthik Chikmagalur
2024-08-20 18:19 ` Ihor Radchenko
2024-08-20 19:46 ` Karthik Chikmagalur
2024-08-22 13:19 ` Ihor Radchenko
2024-08-23 6:04 ` Karthik Chikmagalur
2024-08-23 23:36 ` [PATCH v1] Inline image display as part of a new org-link-preview system Karthik Chikmagalur
2024-08-24 1:00 ` Karthik Chikmagalur
2024-08-31 14:22 ` Ihor Radchenko
2024-08-31 16:41 ` Karthik Chikmagalur
2024-08-31 16:53 ` Ihor Radchenko
2024-08-31 22:37 ` [PATCH v2] " Karthik Chikmagalur
2024-09-01 13:06 ` Ihor Radchenko
2024-09-02 20:13 ` [PATCH v3] " Karthik Chikmagalur
2024-08-18 10:34 ` [FR] Automatically display images in resutls of evaluation (was: [PATCH v4.0] Re: [PATCH] add a function to only refresh inline images under current headline instead of global buffer) Ihor Radchenko
[not found] ` <66c54dfc.a70a0220.3c823a.2899@mx.google.com>
2024-08-22 13:06 ` [FR] Automatically display images in resutls of evaluation 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:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
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=669882e5.050a0220.8ff6d.33c6@mx.google.com \
--to=numbchild@gmail.com \
--cc=emacs-orgmode@gnu.org \
--cc=yantar92@posteo.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* 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
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
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).