Re: [PATCH] Adaptive Org faces in headings?

2020-10-07 Thread Kyle Meyer
Protesilaos Stavrou writes:

> Tried to format the patch.  Please see the attached file.  If it does
> not work, feel free to dismiss it and just apply the change yourself.

Looks good.  Applied (23f9415c6).

Thanks.



Bug: performance issue in org-font-lock-add-priority-faces related to org-priority-regexp [9.4 (9.4-7-g3eccc5-elpaplus @ /home/standard/.emacs.d/elpa/26.3/develop/org-plus-contrib-20200921/)]

2020-10-07 Thread Tim Frana
Apologies, the extreme slowdown for the regex in my setup is mostly 
credited to a very long line in my org file (~100k characters). I 
inserted a snippet from a log file to a quote block, without realizing 
that a large base64 string was hiding at the end of one line.
The old regex could exclude that line early on, because it wasn't a 
header line, so I didn't notice a performance hit back then.


With that line deleted (org file shrinks to ~300KB), I measured 
performance with the new and old regex (new on 1st line vs old on 2nd line):


(elp-instrument-function 'org-font-lock-add-priority-faces)
(elp-reset-all)
;; open org file
(elp-results)


 Function Name Call Count  Elapsed Time Average 
Time

new: org-font-lock-add-priority-faces  28  0.0228787000 0.0008170964
old: org-font-lock-add-priority-faces  28  0.0007937999 2.834...e-05

So the new one is still considerably slower, but probably not noticeable 
unless the file is really large and/or it contains long lines.



One last remark, my workaround from the last mail is flawed, e.g. it 
broke priority sorting in my agendas. This one worked better:


(defun adv--org-font-lock-add-priority-faces (wrapped-func  args)
  (let ((org-priority-regexp "^\\*+ .*?\\(\\[#\\([A-Z0-9]+\\)\\] ?\\)"))
    (apply wrapped-func args)))
(advice-add 'org-font-lock-add-priority-faces :around 
#'adv--org-font-lock-add-priority-faces)





[PATCH] ob-python: Rename exec tmpfile handle to prevent conflict

2020-10-07 Thread Adrian Kummerländer
Hello,

I noticed that after updating to Org 9.4 many of my Python-based Org
files fail to execute with various `io.TextIOWrapper' related error
messages. The reason for this is that opening the exec tmpfile as `f'
shadows this possibly user-defined variable.

The attached patch fixes this problem for me. As this is my first
time contributing to Org I am especially open for any suggestions!

Best wishes,
Adrian

>From 239aa9aaa8da0f98719469abdff46ecb7a3994ba Mon Sep 17 00:00:00 2001
From: Adrian Kummerlaender 
Date: Tue, 6 Oct 2020 23:06:08 +0200
Subject: [PATCH] ob-python: Rename exec tmpfile handle to prevent conflict

* lisp/ob-python.el (org-babel-python--exec-tmpfile): Rename tmpfile handle
   (org-babel-python-format-session-value): Rename tmpfile handle

Opening the exec tmpfile as a `f' variable shadows any such variable
that might by defined by the Python session context. e.g. my Org babel
files commonly pass single letter variables inside a session which is
broken by this behavior.

The new name `__org_babel_python_tmpfile' is in line with other org
mode specific Python variables set by ob-python. This is unlikely to
conflict with the user's Python code.
---
 lisp/ob-python.el | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/lisp/ob-python.el b/lisp/ob-python.el
index 785b9191b..6752adc17 100644
--- a/lisp/ob-python.el
+++ b/lisp/ob-python.el
@@ -244,8 +244,8 @@ def main():
 open('%s', 'w').write( pprint.pformat(main()) )")
 
 (defconst org-babel-python--exec-tmpfile "\
-with open('%s') as f:
-exec(compile(f.read(), f.name, 'exec'))"
+with open('%s') as __org_babel_python_tmpfile:
+exec(compile(__org_babel_python_tmpfile.read(), __org_babel_python_tmpfile.name, 'exec'))"
   "Template for Python session command with output results.
 
 Has a single %s escape, the tempfile containing the source code
@@ -256,20 +256,20 @@ to evaluate.")
   "Return Python code to evaluate SRC-FILE and write result to RESULT-FILE."
   (format "\
 import ast
-with open('%s') as f:
-__org_babel_python_ast = ast.parse(f.read())
+with open('%s') as __org_babel_python_tmpfile:
+__org_babel_python_ast = ast.parse(__org_babel_python_tmpfile.read())
 __org_babel_python_final = __org_babel_python_ast.body[-1]
 if isinstance(__org_babel_python_final, ast.Expr):
 __org_babel_python_ast.body = __org_babel_python_ast.body[:-1]
 exec(compile(__org_babel_python_ast, '', 'exec'))
 __org_babel_python_final = eval(compile(ast.Expression(
 __org_babel_python_final.value), '', 'eval'))
-with open('%s', 'w') as f:
+with open('%s', 'w') as __org_babel_python_tmpfile:
 if %s:
 import pprint
-f.write(pprint.pformat(__org_babel_python_final))
+__org_babel_python_tmpfile.write(pprint.pformat(__org_babel_python_final))
 else:
-f.write(str(__org_babel_python_final))
+__org_babel_python_tmpfile.write(str(__org_babel_python_final))
 else:
 exec(compile(__org_babel_python_ast, '', 'exec'))
 __org_babel_python_final = None"
-- 
2.25.4



[PATCH] ob-python: Rename exec tmpfile handle to prevent conflict

2020-10-07 Thread Adrian Kummerländer
Hello,

I noticed that after updating to Org 9.4 many of my Python-based Org
files fail to execute with various `io.TextIOWrapper' related error
messages. The reason for this is that opening the exec tmpfile as `f'
shadows this possibly user-defined variable.

The attached patch fixes this problem for me. As this is my first
time contributing to Org I am especially open for any suggestions!

Best regards,
Adrian

>From 239aa9aaa8da0f98719469abdff46ecb7a3994ba Mon Sep 17 00:00:00 2001
From: Adrian Kummerlaender 
Date: Tue, 6 Oct 2020 23:06:08 +0200
Subject: [PATCH] ob-python: Rename exec tmpfile handle to prevent conflict

* lisp/ob-python.el (org-babel-python--exec-tmpfile): Rename tmpfile handle
   (org-babel-python-format-session-value): Rename tmpfile handle

Opening the exec tmpfile as a `f' variable shadows any such variable
that might by defined by the Python session context. e.g. my Org babel
files commonly pass single letter variables inside a session which is
broken by this behavior.

The new name `__org_babel_python_tmpfile' is in line with other org
mode specific Python variables set by ob-python. This is unlikely to
conflict with the user's Python code.
---
 lisp/ob-python.el | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/lisp/ob-python.el b/lisp/ob-python.el
index 785b9191b..6752adc17 100644
--- a/lisp/ob-python.el
+++ b/lisp/ob-python.el
@@ -244,8 +244,8 @@ def main():
 open('%s', 'w').write( pprint.pformat(main()) )")
 
 (defconst org-babel-python--exec-tmpfile "\
-with open('%s') as f:
-exec(compile(f.read(), f.name, 'exec'))"
+with open('%s') as __org_babel_python_tmpfile:
+exec(compile(__org_babel_python_tmpfile.read(), __org_babel_python_tmpfile.name, 'exec'))"
   "Template for Python session command with output results.
 
 Has a single %s escape, the tempfile containing the source code
@@ -256,20 +256,20 @@ to evaluate.")
   "Return Python code to evaluate SRC-FILE and write result to RESULT-FILE."
   (format "\
 import ast
-with open('%s') as f:
-__org_babel_python_ast = ast.parse(f.read())
+with open('%s') as __org_babel_python_tmpfile:
+__org_babel_python_ast = ast.parse(__org_babel_python_tmpfile.read())
 __org_babel_python_final = __org_babel_python_ast.body[-1]
 if isinstance(__org_babel_python_final, ast.Expr):
 __org_babel_python_ast.body = __org_babel_python_ast.body[:-1]
 exec(compile(__org_babel_python_ast, '', 'exec'))
 __org_babel_python_final = eval(compile(ast.Expression(
 __org_babel_python_final.value), '', 'eval'))
-with open('%s', 'w') as f:
+with open('%s', 'w') as __org_babel_python_tmpfile:
 if %s:
 import pprint
-f.write(pprint.pformat(__org_babel_python_final))
+__org_babel_python_tmpfile.write(pprint.pformat(__org_babel_python_final))
 else:
-f.write(str(__org_babel_python_final))
+__org_babel_python_tmpfile.write(str(__org_babel_python_final))
 else:
 exec(compile(__org_babel_python_ast, '', 'exec'))
 __org_babel_python_final = None"
-- 
2.25.4