emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Carlos Pita <carlosjosepita@gmail.com>
To: Carlos Pita <carlosjosepita@gmail.com>,
	emacs-orgmode <emacs-orgmode@gnu.org>
Subject: Re: Bug: org-toggle-latex-fragment doesn't work as documented [9.2.1 (release_9.2.1-60-gb0379f @ /home/carlos/local/stow/emacs/share/emacs/site-lisp/org/)]
Date: Wed, 13 Feb 2019 16:38:37 -0300	[thread overview]
Message-ID: <CAELgYhcnP3bO0OifTjiym1yreMPM49iFQpHbgezBBHsxXyo_Jw@mail.gmail.com> (raw)
In-Reply-To: <CAELgYhfcc+M15UiUNB0EmV9umMV-x0_45LnqCrKaDx9g+7eAcg@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 268 bytes --]

Nicolas, here is a patch implementing alternative B above with
ORG-NEWS entry and everything.

I have been playing with it and find the bindings quite handy.

Code is indeed a bit simpler.

If you like it, feel free to amend it before merging.

Best regards
--
Carlos

[-- Attachment #2: 0001-org-Make-latex-preview-toggle-more-useful-and-predic.patch --]
[-- Type: text/x-patch, Size: 4587 bytes --]

From 799ecd332e81a31b06f69ba5546db74eb9583ba7 Mon Sep 17 00:00:00 2001
From: memeplex <carlosjosepita@gmail.com>
Date: Wed, 13 Feb 2019 16:26:46 -0300
Subject: [PATCH] org: Make latex preview toggle more useful and predictable

* lisp/org.el (org-toggle-latex-fragment):
  - Avoid toggling behavior for subtree/buffer scope
  - Make common use cases simpler to type

* Detailed discussion:

  http://lists.gnu.org/archive/html/emacs-orgmode/2019-02/msg00138.html
---
 lisp/org.el | 71 ++++++++++++++++++++++++++---------------------------
 1 file changed, 35 insertions(+), 36 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index 003058434..afd3f8709 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -18057,60 +18057,59 @@ overlays were removed, nil otherwise."
     overlays))
 
 (defun org-toggle-latex-fragment (&optional arg)
-  "Preview the LaTeX fragment at point, or all locally or globally.
-
-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 all fragments in the
-current section.
-
-With prefix ARG, preview or clear image for all fragments in the
-current subtree or in the whole buffer when used before the first
-headline.  With a prefix ARG `\\[universal-argument] \
-\\[universal-argument]' preview or clear images
-for all fragments in the buffer."
+  "Toggle preview of the LaTeX fragment at point.
+
+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 image for all fragments
+in the current section.
+
+With prefix ARG, clear image for all fragments in the current
+subtree.
+
+With double prefix ARG, display image for all fragments in the
+buffer.
+
+With triple prefix ARG, clear image for all fragments in the
+buffer."
   (interactive "P")
   (when (display-graphic-p)
     (catch 'exit
       (save-excursion
 	(let (beg end msg)
 	  (cond
-	   ((or (equal arg '(16))
-		(and (equal arg '(4))
-		     (org-with-limited-levels (org-before-first-heading-p))))
-	    (if (org-remove-latex-fragment-image-overlays)
-		(progn (message "LaTeX fragments images removed from buffer")
-		       (throw 'exit nil))
-	      (setq msg "Creating images for buffer...")))
-	   ((equal arg '(4))
+	   ((member arg '((16) (64)))	; Double or triple prefix
+	    (when (org-remove-latex-fragment-image-overlays)
+	      (message "LaTeX fragments images removed from buffer"))
+	    (when (equal arg '(64)) (throw 'exit nil))
+	    (setq msg "Creating images for buffer..."))
+	   ((member arg '((4)))		; Single prefix
 	    (org-with-limited-levels (org-back-to-heading t))
 	    (setq beg (point))
 	    (setq end (progn (org-end-of-subtree t) (point)))
-	    (if (org-remove-latex-fragment-image-overlays beg end)
-		(progn
-		  (message "LaTeX fragment images removed from subtree")
-		  (throw 'exit nil))
-	      (setq msg "Creating images for subtree...")))
+	    (when (org-remove-latex-fragment-image-overlays beg end)
+	      (message "LaTeX fragment images removed from subtree"))
+	    (throw 'exit nil))
 	   ((let ((datum (org-element-context)))
 	      (when (memq (org-element-type datum)
 			  '(latex-environment latex-fragment))
 		(setq beg (org-element-property :begin datum))
 		(setq end (org-element-property :end datum))
-		(if (org-remove-latex-fragment-image-overlays beg end)
-		    (progn (message "LaTeX fragment image removed")
-			   (throw 'exit nil))
-		  (setq msg "Creating image...")))))
+		(when (org-remove-latex-fragment-image-overlays beg end)
+		  (message "LaTeX fragment image removed")
+		  (throw 'exit nil))
+		(setq msg "Creating image..."))))
 	   (t
 	    (org-with-limited-levels
 	     (setq beg (if (org-at-heading-p) (line-beginning-position)
 			 (outline-previous-heading)
-			 (point)))
-	     (setq end (progn (outline-next-heading) (point)))
-	     (if (org-remove-latex-fragment-image-overlays beg end)
-		 (progn
-		   (message "LaTeX fragment images removed from section")
-		   (throw 'exit nil))
-	       (setq msg "Creating images for section...")))))
+			 (point))
+		   end (progn (outline-next-heading) (point)))
+	     (when (org-remove-latex-fragment-image-overlays beg end)
+	       (message "LaTeX fragment images removed from section"))
+	       (setq msg "Creating images for section..."))))
 	  (let ((file (buffer-file-name (buffer-base-buffer))))
 	    (org-format-latex
 	     (concat org-preview-latex-image-directory "org-ltximg")
-- 
2.20.1


  reply	other threads:[~2019-02-13 19:38 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-11 22:30 Bug: org-toggle-latex-fragment doesn't work as documented [9.2.1 (release_9.2.1-60-gb0379f @ /home/carlos/local/stow/emacs/share/emacs/site-lisp/org/)] Carlos Pita
2019-02-11 22:33 ` Carlos Pita
2019-02-11 22:51 ` Carlos Pita
2019-02-11 23:15   ` Carlos Pita
2019-02-12 21:45     ` Nicolas Goaziou
2019-02-12 22:00       ` Carlos Pita
2019-02-12 22:43         ` Nicolas Goaziou
2019-02-12 23:23           ` Carlos Pita
2019-02-13 14:25             ` Nicolas Goaziou
2019-02-13 14:53               ` Carlos Pita
2019-02-13 15:10                 ` Carlos Pita
2019-02-13 16:24                   ` Nicolas Goaziou
2019-02-13 16:43                     ` Carlos Pita
2019-02-13 19:38                       ` Carlos Pita [this message]
2019-02-14  0:23                         ` Nicolas Goaziou
2019-02-14  1:31                           ` Carlos Pita
2019-02-14 14:52                             ` Nicolas Goaziou

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=CAELgYhcnP3bO0OifTjiym1yreMPM49iFQpHbgezBBHsxXyo_Jw@mail.gmail.com \
    --to=carlosjosepita@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /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).