[PATCH] org-agenda.el: Fix clocking issues regex

2021-05-15 Thread Tim Frana

Hi,

The method org-agenda-show-clocking-issues has a faulty regex, which 
leads to false-positive

clocking issues: " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))"

There is no outer group to limit the OR-expression \\|, so the right 
half will match timestamps with

a closing parenthesis without any "Clocked" in front of it.

I added a non-capturing group in the attached patch: " Clocked: 
+(\\(?:-\\|\\([0-9]+:[0-9]+\\)\\))".



Reproduction:

Define a custom agenda:
(setq org-agenda-custom-commands '(("d" "Clock report for today" agenda ""
    ((org-agenda-span 1)
(org-agenda-start-with-clockreport-mode t)
 (org-agenda-start-with-log-mode 
'clockcheck)


Use an org file that is included in org-agenda-files, and add this 
sample headline:
Sample headline with time and closing parenthesis in it (it happened at 
12:00)


Clock in and out of the headline, make sure the clock timespan is at 
least 1 minute, and open the
agenda defined above. Observe that the headline is reported as 
overlapping with itself, as the

faulty regex will match twice on its agenda line.

Best Regards,
Tim


From ac37efa543ab5823b5f2c62336d3e36b67fe516a Mon Sep 17 00:00:00 2001
From: mosquito-magnet <24659697+mosquito-mag...@users.noreply.github.com>
Date: Sat, 15 May 2021 15:43:28 +0200
Subject: [PATCH] org-agenda.el: Fix clocking issues regex

* org-agenda.el (org-agenda-show-clocking-issues): Fix regex to prevent 
false-positive clocking
issue detection.

Regex was missing a grouping to restrict the alternative \| to the
literal parentheses.

TINYCHANGE
---
 lisp/org-agenda.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index 95848ab9b..bf917d321 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -6059,7 +6059,7 @@ (defun org-agenda-show-clocking-issues ()
   '((:background "DarkRed") (:foreground "white"
 issue face m te ts dt ov)
 (goto-char (point-min))
-(while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
+(while (re-search-forward " Clocked: +(\\(?:-\\|\\([0-9]+:[0-9]+\\)\\))" 
nil t)
   (setq issue nil face def-face)
   (catch 'next
(setq m (org-get-at-bol 'org-marker)
-- 
2.29.0



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)





Bug: missing autoload org-load-modules-maybe [9.4 (9.4-7-g3eccc5-elpaplus @ /home/standard/.emacs.d/elpa/26.3/develop/org-plus-contrib-20200921/)]

2020-09-28 Thread Tim Frana

Hello,

Reproduction:

Start emacs without loading org, call org-store-link.
Error message is displayed: "Symbol’s function definition is void: 
org-load-modules-maybe"


Expected behaviour:

Org link to the current location is stored.

I guess an autoload should be added? Manually adding one in my setup 
heals it:


(with-eval-after-load 'ol
  (when (not (fboundp 'org-load-modules-maybe))
    (autoload 'org-load-modules-maybe "org" nil nil)))

Best Regards,
Tim


Emacs  : GNU Emacs 26.3 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.22.30)
 of 2019-09-16
Distribution: Spacemacs develop
Package: Org mode version 9.4 (9.4-7-g3eccc5-elpaplus @ 
/home/standard/.emacs.d/elpa/26.3/develop/org-plus-contrib-20200921/)



current state:
==
(setq
 org-src-mode-hook '(org-src-babel-configure-edit-buffer 
org-src-mode-configure-edit-buffer)

 org-after-todo-state-change-hook '(org-expiry-insert-created)
 org-link-shell-confirm-function 'yes-or-no-p
 org-blank-before-new-entry '((heading . t) (plain-list-item))
 org-babel-after-execute-hook '(spacemacs/ob-fix-inline-images)
 org-metadown-hook '(org-babel-pop-to-session-maybe)
 org-agenda-tags-todo-honor-ignore-options t
 org-export-with-sub-superscripts '{}
 org-clock-out-hook '(org-clock-remove-empty-clock-drawer)
 org-refile-targets '((nil :maxlevel . 3) (org-agenda-files :maxlevel . 3))
 org-html-format-inlinetask-function 
'org-html-format-inlinetask-default-function

 org-enforce-todo-dependencies t
 org-edit-src-content-indentation 0
 org-odt-format-headline-function 'org-odt-format-headline-default-function
 org-imenu-depth 8
 org-agenda-files 
'("/home/standard/.spacemacs.d/private/tf-common/_todo.org")

 org-ascii-format-inlinetask-function 'org-ascii-format-inlinetask-default
 org-clock-report-include-clocking-task t
 org-modules '(org-habit ol-w3m ol-bbdb ol-bibtex ol-docview ol-gnus 
ol-info ol-irc ol-mhe ol-rmail ol-eww)

 org-startup-folded t
 org-blocker-hook '(org-depend-block-todo)
 org-archive-location "%s_archive.org::"
 org-id-link-to-org-use-id 'create-if-interactive
 org-mode-hook '((lambda nil (setq paragraph-start "\f\\|[ ]*$" 
paragraph-separate "[     \f]*$")) turn-on-auto-fill org-tempo-setup 
org-clock-load
 #[0 "\300\301\302\303\304$\207" [add-hook 
change-major-mode-hook org-show-all append local] 5] flyspell-mode 
spacemacs/org-setup-evil-surround spacemacs/load-yasnippet
 #[0 "\301\211\207" [imenu-create-index-function 
org-imenu-get-tree] 2] toc-org-enable org-superstar-mode 
org-download-enable dotspacemacs//prettify-spacemacs-docs 
spacemacs//org-babel-do-load-languages
 #[0 "\300\301\302\303\304$\207" [add-hook 
change-major-mode-hook org-babel-show-result-all append local] 5] 
org-babel-result-hide-spec org-babel-hide-all-hashes 
spacemacs//evil-org-mode org-eldoc-load

 spacemacs//init-company-org-mode company-mode)
 org-clock-persist t
 org-odt-format-drawer-function #[514 "\207" [] 3 "\n\n(fn NAME CONTENTS)"]
 org-outline-path-complete-in-steps nil
 org-archive-hook '(org-attach-archive-delete-maybe)
 org-agenda-restore-windows-after-quit t
 org-confirm-elisp-link-function 'yes-or-no-p
 org-startup-indented t
 org-startup-with-inline-images t
 org-clock-history-length 20
 org-agenda-before-write-hook '(org-agenda-add-entry-text)
 org-hide-block-startup t
 org-metaup-hook '(org-babel-load-in-session-maybe)
 org-bibtex-headline-format-function #[257 "\300\236A\207" [:title] 3 
"\n\n(fn ENTRY)"]

 org-latex-format-drawer-function #[514 "\207" [] 3 "\n\n(fn _ CONTENTS)"]
 org-expiry-handler-function 'org-toggle-archive-tag
 org-babel-pre-tangle-hook '(save-buffer)
 org-file-apps '((auto-mode . emacs) 
("\\.\\(xlsx?\\|docx?\\|pptx?\\|pdf\\|ods\\|png\\)\\'" . default))
 org-tab-first-hook '(org-babel-hide-result-toggle-maybe 
org-babel-header-arg-expand)
 org-babel-load-languages '((dot . t) (calc . t) (plantuml . t) (sql . 
t) (js . t) (shell . t) (emacs-lisp . t))

 org-log-done 'time
 org-export-backends '(confluence md ascii html icalendar latex odt)
 org-ascii-format-drawer-function #[771 "\207" [] 4 "\n\n(fn NAME 
CONTENTS WIDTH)"]

 org-trigger-hook '(org-depend-trigger-todo)
 org-priority-lowest 68
 org-agenda-loop-over-headlines-in-active-region nil
 org-src-lang-modes '(("arduino" . arduino) ("redis" . redis) ("php" . 
php) ("C" . c) ("C++" . c++) ("asymptote" . asy) ("bash" . sh) ("beamer" 
. latex) ("calc" . fundamental) ("cpp" . c++) ("ditaa" . artist) ("dot" 
. fundamental)
  ("elisp" . emacs-lisp) ("ocaml" . tuareg) 
("screen" . shell-script) ("shell" . sh) ("sqlite" . sql))

 org-fontify-done-headline nil
 org-agenda-prefix-format '((agenda . " %i %-12:c%?-12t% s") (timeline 
. "  % s") (todo . " %i %b") (tags . " %i %-12:c") (search . " %i %-12:c"))

 org-occur-hook '(org-first-headline-recenter)
 org-log-into-drawer t
 org-protocol-protocol-alist '(("capture-eww-readable" :protocol 
"capture-eww-readable" :function 

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-09-24 Thread Tim Frana

Hello,

After updating from org-plus-contrib-20200810 to 
org-plus-contrib-20200921, opening org files has become extremely slow 
for me. As a rough estimate, a 400 KB org file of mine used to take 5 
seconds on first load in a session, and after the update needed more 
than 2 minutes. This is the case both in Emacs 27.1 in Windows, and 
Emacs 26.3 in Windows WSL1 Ubuntu 20.04 LTS, using spacemacs develop.


I can narrow it down to this change:

org-font-lock-add-priority-faces used to search for this regexp: "^\\*+ 
.*?\\(\\[#\\(.\\)\\]\\)"
Now it searches for org-priority-regexp, which by default resolves to 
".*?\\(\\[#\\([A-Z0-9]+\\)\\] ?\\)".


This is much slower, and also matches more than I expected. In the 
following example, I expect only [#A], but it will match [#B] and [#C] 
too. Is this intended?


** TODO [#A] Headline [#B]
this is matched despite not being a heading: [#C] more text

It seems plausible that the slowdown comes from the regex engine now 
doing elaborate matching on all lines, instead of fast skipping over 
non-heading lines.


This version seems to resolve my problem, where the beginning "^\\*+ " 
should narrow matches to heading lines only:

(setq org-priority-regexp "^\\*+ .*?\\(\\[#\\([A-Z0-9]+\\)\\] ?\\)")

Profiler excerpt (the other 51% were mostly eaten by spell checking 
during idling, as I got distracted waiting for the loading to finish):


- set-auto-mode 5498  49%
 - set-auto-mode-0  5498  49%
  - org-mode    5498  49%
   - run-mode-hooks 5498  49%
    - apply 5497  49%
 - run-hooks    5497  49%
  - org-superstar-mode  5493  49%
   - org-superstar--fontify-buffer  5493  49%
    - font-lock-ensure  5493  49%
 - jit-lock-fontify-now 5493  49%
  - jit-lock--run-functions 5493  49%
   - run-hook-wrapped   5493  49%
    - # 5391 48%
 - font-lock-fontify-region 5391  48%
  - font-lock-default-fontify-region    5391  48%
   - font-lock-fontify-keywords-region  5391  48%
  org-font-lock-add-priority-faces  5391  48%

Best regards,
Tim






Emacs  : GNU Emacs 26.3 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.22.30)
 of 2019-09-16
Package: Org mode version 9.4 (9.4-7-g3eccc5-elpaplus @ 
/home/standard/.emacs.d/elpa/26.3/develop/org-plus-contrib-20200921/)


current state:
==
(setq
 org-src-mode-hook '(org-src-babel-configure-edit-buffer 
org-src-mode-configure-edit-buffer)

 org-after-todo-state-change-hook '(org-expiry-insert-created)
 org-link-shell-confirm-function 'yes-or-no-p
 org-blank-before-new-entry '((heading . t) (plain-list-item))
 org-babel-after-execute-hook '(spacemacs/ob-fix-inline-images)
 org-metadown-hook '(org-babel-pop-to-session-maybe)
 org-agenda-tags-todo-honor-ignore-options t
 org-export-with-sub-superscripts '{}
 org-clock-out-hook '(org-clock-remove-empty-clock-drawer)
 org-refile-targets '((nil :maxlevel . 3) (org-agenda-files :maxlevel . 3))
 org-html-format-inlinetask-function 
'org-html-format-inlinetask-default-function

 org-enforce-todo-dependencies t
 org-edit-src-content-indentation 0
 org-odt-format-headline-function 'org-odt-format-headline-default-function
 org-imenu-depth 8
 org-download-annotate-function 'org-download-annotate-default
 org-ascii-format-inlinetask-function 'org-ascii-format-inlinetask-default
 org-clock-report-include-clocking-task t
 org-modules '(org-habit ol-w3m ol-bbdb ol-bibtex ol-docview ol-gnus 
ol-info ol-irc ol-mhe ol-rmail ol-eww)
 org-blocker-hook '(org-block-todo-from-children-or-siblings-or-parent 
org-depend-block-todo)

 org-archive-location "%s_archive.org::"
 org-id-link-to-org-use-id 'create-if-interactive
 org-mode-hook '((lambda nil (setq paragraph-start "\f\\|[ ]*$" 
paragraph-separate "[     \f]*$")) turn-on-auto-fill org-tempo-setup 
org-clock-load
 #[0 "\300\301\302\303\304$\207" [add-hook 
change-major-mode-hook org-show-all append local] 5] flyspell-mode 
spacemacs/org-setup-evil-surround spacemacs/load-yasnippet
 #[0 "\301\211\207" [imenu-create-index-function 
org-imenu-get-tree] 2] toc-org-enable org-superstar-mode 
org-download-enable dotspacemacs//prettify-spacemacs-docs 
spacemacs//org-babel-do-load-languages
 #[0 "\300\301\302\303\304$\207" [add-hook 
change-major-mode-hook org-babel-show-result-all append local] 5] 
org-babel-result-hide-spec org-babel-hide-all-hashes 
spacemacs//evil-org-mode org-eldoc-load

 spacemacs//init-company-org-mode company-mode)
 org-clock-persist t