Skip to content

Commit

Permalink
org-agenda-skip: Improve performance
Browse files Browse the repository at this point in the history
* lisp/org-agenda.el: Remove unnecessary variable assignment.  Prefer
checking ELEMENT type over regexp match when checking if we are inside
comment.  Postpone let-binding until it is strictly necessary.
  • Loading branch information
yantar92 committed Sep 22, 2022
1 parent 95df82c commit 3e3588d
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions lisp/org-agenda.el
Original file line number Diff line number Diff line change
Expand Up @@ -4212,22 +4212,25 @@ Also moves point to the end of the skipped region, so that search can
continue from there.

Optional argument ELEMENT contains element at point."
(let ((p (line-beginning-position)) to)
(when (or
(save-excursion (goto-char p) (looking-at comment-start-skip))
(and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
(or (and (save-match-data (org-in-archived-heading-p nil element))
(org-end-of-subtree t element))
(and (member org-archive-tag org-file-tags)
(goto-char (point-max)))))
(and org-agenda-skip-comment-trees
(org-in-commented-heading-p nil element)
(org-end-of-subtree t element))
(and (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
(org-agenda-skip-eval org-agenda-skip-function)))
(goto-char to))
(org-in-src-block-p t element))
(throw :skip t))))
(when (or
(if element
(eq (org-element-type element) 'comment)
(save-excursion
(goto-char (line-beginning-position))
(looking-at comment-start-skip)))
(and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
(or (and (save-match-data (org-in-archived-heading-p nil element))
(org-end-of-subtree t element))
(and (member org-archive-tag org-file-tags)
(goto-char (point-max)))))
(and org-agenda-skip-comment-trees
(org-in-commented-heading-p nil element)
(org-end-of-subtree t element))
(let ((to (or (org-agenda-skip-eval org-agenda-skip-function-global)
(org-agenda-skip-eval org-agenda-skip-function))))
(and to (goto-char to)))
(org-in-src-block-p t element))
(throw :skip t)))

(defun org-agenda-skip-eval (form)
"If FORM is a function or a list, call (or eval) it and return the result.
Expand Down

0 comments on commit 3e3588d

Please sign in to comment.