emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] org.el (org-latex-preview): With an active region, act on it
@ 2022-06-08 11:35 Sébastien Miquel
  2022-06-08 17:08 ` Daniel Fleischer
  0 siblings, 1 reply; 5+ messages in thread
From: Sébastien Miquel @ 2022-06-08 11:35 UTC (permalink / raw)
  To: emacs-orgmode


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

Hi,

The attached patch modifies org-latex-preview to display all images of 
latex fragments in a region, when one is active.

Using prefix arguments it is already possible to display all images in 
the buffer, or in the current section, but I find it often too slow and 
unnecessary. Regards,

-- 
Sébastien Miquel

[-- Attachment #1.2: Type: text/html, Size: 617 bytes --]

[-- Attachment #2: 0001-org.el-org-latex-preview-With-an-active-region-act-o.patch --]
[-- Type: text/x-patch, Size: 2138 bytes --]

From 2c9b72731247620dea2aed96a0a83385472e29cc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Miquel?= <sebastien.miquel@posteo.eu>
Date: Wed, 8 Jun 2022 13:11:12 +0200
Subject: [PATCH] org.el (org-latex-preview): With an active region, act on it

* lisp/org.el (org-latex-preview): With an active region, display
images for all fragments in the region. With universal prefix
argument, remove all images in the region.
---
 lisp/org.el | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index 95dff27ad..07f481647 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -15307,7 +15307,8 @@ BEG and END are buffer positions."
 If the cursor is on a LaTeX fragment, create the image and
 overlay it over the source code, if there is none.  Remove it
 otherwise.  If there is no fragment at point, display images for
-all fragments in the current section.
+all fragments in the current section.  With an active region,
+display images for all fragments in the region.

 With a `\\[universal-argument]' prefix argument ARG, clear images \
 for all fragments
@@ -15335,10 +15336,18 @@ fragments in the buffer."
    ;; Clear current section.
    ((equal arg '(4))
     (org-clear-latex-preview
-     (if (org-before-first-heading-p) (point-min)
-       (save-excursion
-	 (org-with-limited-levels (org-back-to-heading t) (point))))
-     (org-with-limited-levels (org-entry-end-position))))
+     (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)))))
+     (if (use-region-p)
+         (region-end)
+       (org-with-limited-levels (org-entry-end-position)))))
+   ((use-region-p)
+    (message "Creating LaTeX previews in region...")
+    (org--latex-preview-region (region-beginning) (region-end))
+    (message "Creating LaTeX previews in region... done."))
    ;; Toggle preview on LaTeX code at point.
    ((let ((datum (org-element-context)))
       (and (memq (org-element-type datum) '(latex-environment latex-fragment))
-- 
2.36.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] org.el (org-latex-preview): With an active region, act on it
  2022-06-08 11:35 [PATCH] org.el (org-latex-preview): With an active region, act on it Sébastien Miquel
@ 2022-06-08 17:08 ` Daniel Fleischer
  2022-06-10 14:02   ` Sébastien Miquel
  0 siblings, 1 reply; 5+ messages in thread
From: Daniel Fleischer @ 2022-06-08 17:08 UTC (permalink / raw)
  To: Sébastien Miquel; +Cc: emacs-orgmode

Sébastien Miquel [2022-06-08 Wed 11:35] wrote:

> The attached patch modifies org-latex-preview to display all images
> of latex fragments in a region, when one is active.
> Using prefix arguments it is already possible to display all images
> in the buffer, or in the current section, but I find it often too slow
> and unnecessary.

Hi Miquel, thanks for the patch! It's useful and works nicely - both in
creating and removing the previews. Let's give it a couple more days for
feedback and then feel free to merge the patch.

Thanks,

-- 

Daniel Fleischer


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] org.el (org-latex-preview): With an active region, act on it
  2022-06-08 17:08 ` Daniel Fleischer
@ 2022-06-10 14:02   ` Sébastien Miquel
  2022-06-10 14:43     ` Daniel Fleischer
  0 siblings, 1 reply; 5+ messages in thread
From: Sébastien Miquel @ 2022-06-10 14:02 UTC (permalink / raw)
  To: Daniel Fleischer; +Cc: emacs-orgmode

Hi,

Daniel Fleischer writes:
> Hi Miquel, thanks for the patch! It's useful and works nicely - both in
> creating and removing the previews. Let's give it a couple more days for
> feedback and then feel free to merge the patch.

Thanks for your comment and testing this.

Note that I do not have merge access to the repository.

Regards,

-- 
Sébastien Miquel



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] org.el (org-latex-preview): With an active region, act on it
  2022-06-10 14:02   ` Sébastien Miquel
@ 2022-06-10 14:43     ` Daniel Fleischer
  2022-07-04 12:08       ` Sébastien Miquel
  0 siblings, 1 reply; 5+ messages in thread
From: Daniel Fleischer @ 2022-06-10 14:43 UTC (permalink / raw)
  To: Sébastien Miquel; +Cc: emacs-orgmode

Sébastien Miquel <sebastien.miquel@posteo.eu> writes:

> Thanks for your comment and testing this.
>
> Note that I do not have merge access to the repository.

OK, I merged it now. Thanks for the contribution!

-- 

Daniel Fleischer


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] org.el (org-latex-preview): With an active region, act on it
  2022-06-10 14:43     ` Daniel Fleischer
@ 2022-07-04 12:08       ` Sébastien Miquel
  0 siblings, 0 replies; 5+ messages in thread
From: Sébastien Miquel @ 2022-07-04 12:08 UTC (permalink / raw)
  To: emacs-orgmode

Marking this as resolved on updates.orgmode.org.

Applied.

-- 
Sébastien Miquel



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-07-04 12:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-06-08 11:35 [PATCH] org.el (org-latex-preview): With an active region, act on it Sébastien Miquel
2022-06-08 17:08 ` Daniel Fleischer
2022-06-10 14:02   ` Sébastien Miquel
2022-06-10 14:43     ` Daniel Fleischer
2022-07-04 12:08       ` Sébastien Miquel

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).