[O] [PATCH] Caching latex preview images

2012-12-25 Thread Abdó Roig-Maranges

Hi,

Org mode lost the ability to reuse already generated latex preview
images in commit 27101a3e0ee7. Now it just regenerates all of them every
time.

I don't see a reason for removing this feature (am I missing
something?), so here is a little patch reintroducing that feature. I'm
also mailing the author of that commit.

Abdó Roig-Maranges.

From cd284a858a653c28e42b09fa07f172172ceba510 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Abd=C3=B3=20Roig-Maranges?= abdo.r...@gmail.com
Date: Tue, 23 Oct 2012 18:44:24 +0200
Subject: [PATCH] org.el: Don't re-generate latex previews if already present

* org.el (org-format-latex): Do not re-generate a latex preview if the
  image already exists. This feature was lost in commit 27101a3e0ee7
---
 lisp/org.el | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index ee4c70e..3ba1ab8 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -17636,8 +17636,9 @@ Some of the options can be changed using the variable
 	  (unless checkdir ; make sure the directory exists
 		(setq checkdir t)
 		(or (file-directory-p todir) (make-directory todir t)))
-	  (org-create-formula-image
-	   txt movefile optnew forbuffer processing-type)
+	  (unless (file-exists-p movefile)
+		(org-create-formula-image
+		 txt movefile optnew forbuffer processing-type))
 	  (if overlays
 		  (progn
 		(mapc (lambda (o)
-- 
1.8.0.2



Re: [O] Dramatic slowdown in org mode

2012-12-18 Thread Abdó Roig-Maranges


Hi

 sometime between last week and today, there has been a dramatic
 slowdown in the generation of an agenda view.

I tracked it back to commit a7afe7d, but haven't had the time to
investigate it further. On my case the slowdown is not as dramatic as
Eric's, though.

Abdo.



Re: [O] Dramatic slowdown in org mode

2012-12-18 Thread Abdó Roig-Maranges

Hi,

 My guess is commit 980e522 -- can you confirm this?

I don't think it is 980e522. Here are my timings

a7afe7d:10.6 s
c4bf1ee:3.86 s

980e522:3.8  s
08e4111:3.88 s

that point to a7afe7d. It reads the files all right in about 4s, and on
the extra 6 seconds it just keeps thinking hard, until it displays the agenda.

Abdo.



[O] display outline headings up to certain level in search-view

2012-12-14 Thread Abdó Roig-Maranges

Hi,

Let's say I have an org file structured like this

* Project 1
** Tasks
   foo
** Ideas

* Project 2
** Tasks
   bar

When I search 'foo' I'd like the agenda search-view to display 'Project
1' instead of the closer, but less informative 'Tasks'

The attached patch solves this by adding a configuration parameter that
sets the maximum outline level for the headings displayed in the results
of a search-view. This way, I can have a custom search on the above org
file with org-agenda-search-view-max-outline-level set to 1.

Abdó Roig.

From 830acc3fe6e7235618df080f7b6878234cb831c7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Abd=C3=B3=20Roig-Maranges?= abdo.r...@gmail.com
Date: Wed, 12 Dec 2012 20:52:40 +0100
Subject: [PATCH] set max level to display in search-view results

* lisp/org-agenda.el (org-search-view) Adds the config setting
  org-agenda-search-view-max-outline-level that limits the depth of
  items on an agenda-search-view results. When a match is found,
  displays the innermost outline heading containing the match such
  that its level does not exceed
  org-agenda-search-view-max-outline-level.
---
 lisp/org-agenda.el | 20 +++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index 5343887..0b85b9c 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -1320,6 +1320,12 @@ When nil, they may also match part of a word.
   :version 24.1
   :type 'boolean)
 
+(defcustom org-agenda-search-view-max-outline-level nil
+  Maximum outline level to display in search view.
+  :group 'org-agenda-search-view
+  :version 24.3
+  :type 'integer)
+
 (defgroup org-agenda-time-grid nil
   Options concerning the time grid in the Org-mode Agenda.
   :tag Org Agenda Time Grid
@@ -4397,10 +4403,22 @@ in `org-agenda-text-search-extra-files'.
 		(goto-char (max (point-min) (1- (point
 		(while (re-search-forward regexp nil t)
 		  (org-back-to-heading t)
+		  (while (and org-agenda-search-view-max-outline-level
+			( (org-reduced-level (org-outline-level)) org-agenda-search-view-max-outline-level)
+			(forward-line -1)
+			(outline-back-to-heading t)))
+
 		  (skip-chars-forward * )
 		  (setq beg (point-at-bol)
 			beg1 (point)
-			end (progn (outline-next-heading) (point)))
+			end (progn
+			  (outline-next-heading)
+			  (while (and org-agenda-search-view-max-outline-level
+			( (org-reduced-level (org-outline-level)) org-agenda-search-view-max-outline-level)
+(forward-line 1)
+(outline-next-heading)))
+			  (point)))
+
 		  (catch :skip
 			(goto-char beg)
 			(org-agenda-skip)
-- 
1.8.0.2



Re: [O] Question on latex source block

2012-09-13 Thread Abdó Roig-Maranges

Hi,

Here is a patch. Sorry for the bug!

Abdó.

Eric Schulte eric.schu...@gmx.com writes:

 Seems to be caused by 149cc04782651e74764eb3188f6a6f178fe25f64, which is
 unfortunate since that fixes (at least I *think* it fixes) some problems
 when no default fore/background is defined (e.g. when emacs is run in
 batch mode). It would be nice if this could be fixed without reverting
 that commit completely.

 I'm CC'ing Abdó (the author of that commit).  Hopefully he can take a
 shot at solving this.

 -- 
 Eric Schulte
 http://cs.unm.edu/~eschulte

From a48efe084848aa1de8ad4abc5780d49b424a3980 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Abd=C3=B3=20Roig-Maranges?= abdo.r...@gmail.com
Date: Thu, 13 Sep 2012 20:13:37 +0200
Subject: [PATCH] fix dvipng latex export with Transparent background

* org.el (org-create-formula-image-with-dvipng): Fixes a bug
introduced in 149cc04782651e74764eb3188f6a6f178fe25f64 that made it
fail with no :foreground and :background attributes set, due to bad
handling of Transparent color.
---
 lisp/org.el | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index 881dbd5..1c18d70 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -17612,9 +17612,9 @@ share a good deal of logic.
 	 (bg (or (plist-get options (if buffer :background :html-background))
 		 Transparent)))
 (if (eq fg 'default) (setq fg (org-dvipng-color :foreground))
-  (setq fg (org-dvipng-color-format fg)))
+  (unless (string= fg Transparent) (setq fg (org-dvipng-color-format fg
 (if (eq bg 'default) (setq bg (org-dvipng-color :background))
-  (setq bg (org-dvipng-color-format bg)))
+  (unless (string= bg Transparent) (setq bg (org-dvipng-color-format bg
 (with-temp-file texfile
   (insert (org-splice-latex-header
 	   org-format-latex-header
-- 
1.7.12



[O] Problem with ltxpng path for html and odt exports

2012-09-13 Thread Abdó Roig-Maranges

Here is a patch fixing a bug introduced in commit
8474115b20ff2ac907d62f30a0f543064318f47d. That commit added a config
variable with the path for the ltxpng directory (latex images) but
didn't take into account html and odt exports.

Abdó Roig.

From 02435c7ac59611278d49b8499ce117033b415d86 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Abd=C3=B3=20Roig-Maranges?= abdo.r...@gmail.com
Date: Thu, 13 Sep 2012 22:35:44 +0200
Subject: [PATCH] Fixes ltxpng path for html and odt exports

Commit 8474115b20ff2ac907d62f30a0f543064318f47d breaks latex image
exports as html and odt. This fixes it.

* org-html.el (org-export-html-preprocess): replaces explicit ltxpng/
(org-export-html-format-image): replaces ^ltxpng/ regexp.

* org-odt.el (org-export-odt-do-preprocess-latex-fragments):
replaces ltxpng/
---
 lisp/org-html.el | 4 ++--
 lisp/org-odt.el  | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/lisp/org-html.el b/lisp/org-html.el
index 209e3ec..79b0286 100644
--- a/lisp/org-html.el
+++ b/lisp/org-html.el
@@ -763,7 +763,7 @@ The default is an extended format of the ISO 8601 specification.
   (when (and org-current-export-file
 	 (plist-get parameters :LaTeX-fragments))
 (org-format-latex
- (concat ltxpng/ (file-name-sans-extension
+ (concat org-latex-preview-ltxpng-directory (file-name-sans-extension
 			(file-name-nondirectory
 			 org-current-export-file)))
  org-current-export-dir nil Creating LaTeX image %s
@@ -2031,7 +2031,7 @@ PUB-DIR is set, use this as the publishing directory.
 (defun org-export-html-format-image (src par-open)
   Create image tag with source and attributes.
   (save-match-data
-(if (string-match ^ltxpng/ src)
+(if (string-match (regexp-quote org-latex-preview-ltxpng-directory) src)
 	(format img src=\%s\ alt=\%s\/
 src (org-find-text-property-in-string 'org-latex-src src))
   (let* ((caption (org-find-text-property-in-string 'org-caption src))
diff --git a/lisp/org-odt.el b/lisp/org-odt.el
index c3fc325..e7d4e31 100644
--- a/lisp/org-odt.el
+++ b/lisp/org-odt.el
@@ -2658,7 +2658,7 @@ using `org-open-file'.
 	 cache-dir display-msg)
 (cond
  ((eq latex-frag-opt 'dvipng)
-  (setq cache-dir ltxpng/)
+  (setq cache-dir org-latex-preview-ltxpng-directory)
   (setq display-msg Creating LaTeX image %s))
  ((member latex-frag-opt '(mathjax t))
   (setq latex-frag-opt 'mathml)
-- 
1.7.12



[O] Chose where latex preview images are placed

2012-08-03 Thread Abdó Roig-Maranges

Hi,

I'm a regular org-mode user. I have made a couple of small tweaks to
org-mode that may be useful to someone else.

In this mail I attach a patch for the first one. It adds a configuration
variable to chose where latex preview stores the little png images of
formulas. I prefer having all of them together rather than scattered all
over the place.

Abdó Roig.

From bacccfc3d2050df281ec620e761465719606fdb3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Abd=C3=B3=20Roig-Maranges?= abdo.r...@gmail.com
Date: Wed, 1 Aug 2012 19:24:50 +0200
Subject: [PATCH] Option to chose directory for latex preview images

* org.el (org-latex-preview-ltxpng-directory): new config variable.
(org-preview-latex-fragment): store latex preview images in
org-latex-preview-ltxpng-directory.

Added a variable org-latex-preview-ltxpng-directory with a path
where the preview images will be stored. The default does not
change (small little ltxpng scattered all over the place) but now
the user can chose an absolute path and put all the images on a
single place.
---
 lisp/org.el | 12 ++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index 8e0f987..f49a9ac 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -3413,6 +3413,14 @@ imagemagick Convert the LaTeX fragments to pdf files and use imagemagick
 	  (const :tag dvipng dvipng)
 	  (const :tag imagemagick imagemagick)))
 
+(defcustom org-latex-preview-ltxpng-directory ltxpng/
+  Path to store latex preview images. A relative path here creates many
+   directories relative to the processed org files paths. An absolute path
+   puts all preview images at the same place.
+  :group 'org-latex
+  :version 24.2
+  :type 'string)
+
 (defun org-format-latex-mathml-available-p ()
   Return t if `org-latex-to-mathml-convert-command' is usable.
   (save-match-data
@@ -17131,8 +17139,8 @@ The images can be removed again with \\[org-ctrl-c-ctrl-c].
 	(narrow-to-region beg end)
 	(goto-char beg)
 	(org-format-latex
-	 (concat ltxpng/ (file-name-sans-extension
-			(file-name-nondirectory
+	 (concat org-latex-preview-ltxpng-directory (file-name-sans-extension
+			 (file-name-nondirectory
 			 buffer-file-name)))
 	 default-directory 'overlays msg at 'forbuffer
 	 org-latex-create-formula-image-program)
-- 
1.7.11.3



[O] Make latex preview formulas the same color as text face

2012-08-03 Thread Abdó Roig-Maranges

Hi

I attach a patch with an enhancement to the latex preview code. When
:foreground or :background colors are set to auto, it choses the
appropriate color according to the properties of the actual text face.

Abdó Roig.

From f6ede272f226fbeb2cf43fb747ae75be911ad3ce Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Abd=C3=B3=20Roig-Maranges?= abdo.r...@gmail.com
Date: Thu, 2 Aug 2012 00:50:24 +0200
Subject: [PATCH] Option to get latex preview in the same color as text face

* org.el (org-format-latex-options): added `auto' to docstring.
(org-format-latex): Get face colors at point and put them
inside opt.
(org-create-formula-image-with-dvipng): Corrected bug when colors
are not `default'.
(org-create-formula-image-with-imagemagick): Corrected bug in
the handling of Transparent bg color.
(org-dvipng-color-format): Same as org-latex-color-format for
dvipng-style color specification.

If `auto' is used for the :foreground or :background value in
org-format-latex-options, the the appropriate color is chosen
from the face in which the formula is displayed.
---
 lisp/org.el | 38 +++---
 1 file changed, 31 insertions(+), 7 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index f49a9ac..2cc137d 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -3346,8 +3346,10 @@ points to a file, `org-agenda-diary-entry' will be used instead.
 This is a property list with the following properties:
 :foreground  the foreground color for images embedded in Emacs, e.g. \Black\.
  `default' means use the foreground of the default face.
+ `auto' means use the foreground from the text face.
 :background  the background color, or \Transparent\.
  `default' means use the background of the default face.
+ `auto' means use the background from the text face.
 :scale   a scaling factor for the size of the images, to get more pixels
 :html-foreground, :html-background, :html-scale
  the same numbers for HTML export.
@@ -17168,6 +17170,7 @@ Some of the options can be changed using the variable
 	 (absprefix (expand-file-name prefix dir))
 	 (todir (file-name-directory absprefix))
 	 (opt org-format-latex-options)
+	 (optnew org-format-latex-options)
 	 (matchers (plist-get opt :matchers))
 	 (re-list org-latex-regexps)
 	 (org-format-latex-header-extra
@@ -17213,14 +17216,27 @@ Some of the options can be changed using the variable
 	  (setq txt (match-string n)
 		beg (match-beginning n) end (match-end n)
 		cnt (1+ cnt))
-	  (let (print-length print-level) ; make sure full list is printed
+	  (let ((face (face-at-point))
+		(fg (plist-get opt :foreground))
+		(bg (plist-get opt :background))
+		print-length print-level) ; make sure full list is printed
+		(when forbuffer
+	  ; Get the colors from the face at point
+		  (goto-char beg)
+		  (when (eq fg 'auto)
+		(setq fg (face-attribute face :foreground nil 'default)))
+		  (when (eq bg 'auto)
+		(setq bg (face-attribute face :background nil 'default)))
+		  (setq optnew (copy-sequence opt))
+		  (plist-put optnew :foreground fg)
+		  (plist-put optnew :background bg))
 		(setq hash (sha1 (prin1-to-string
   (list org-format-latex-header
 	org-format-latex-header-extra
 	org-export-latex-default-packages-alist
 	org-export-latex-packages-alist
 	org-format-latex-options
-	forbuffer txt)))
+	forbuffer txt fg bg)))
 		  linkfile (format %s_%s.png prefix hash)
 		  movefile (format %s_%s.png absprefix hash)))
 	  (setq link (concat block [[file: linkfile ]] block))
@@ -17239,7 +17255,7 @@ Some of the options can be changed using the variable
 		  (setq executables-checked t))
 		(unless (file-exists-p movefile)
 		  (org-create-formula-image-with-dvipng
-		   txt movefile opt forbuffer)))
+		   txt movefile optnew forbuffer)))
 	   ((eq processing-type 'imagemagick)
 		(unless executables-checked
 		  (org-check-external-command
@@ -17247,7 +17263,7 @@ Some of the options can be changed using the variable
 		  (setq executables-checked t))
 		(unless (file-exists-p movefile)
 		  (org-create-formula-image-with-imagemagick
-		   txt movefile opt forbuffer
+		   txt movefile optnew forbuffer
 	  (if overlays
 		  (progn
 		(mapc (lambda (o)
@@ -17403,8 +17419,10 @@ inspection.
 		 Black))
 	 (bg (or (plist-get options (if buffer :background :html-background))
 		 Transparent)))
-(if (eq fg 'default) (setq fg (org-dvipng-color :foreground)))
-(if (eq bg 'default) (setq bg (org-dvipng-color :background)))
+(if (eq fg 'default) (setq fg (org-dvipng-color :foreground))
+  (setq fg (org-dvipng-color-format fg)))
+(if (eq bg 'default) (setq bg (org-dvipng-color :background))
+  (setq bg (org-dvipng-color-format bg)))
 (with-temp-file texfile
   (insert (org-splice-latex-header
 	   org-format-latex-header
@@ -17475,7 +17493,7 @@ inspection.
   (setq fg