|
33 | 33 | (require 'dash) |
34 | 34 | (require 'eieio) |
35 | 35 | (require 'org) |
| 36 | +(require 'org-agenda) |
36 | 37 | (require 'org-category-capture) |
37 | 38 | (require 'org-project-capture-backend) |
38 | 39 | (require 's) |
@@ -425,6 +426,35 @@ ARGS are passed to `completing-read'." |
425 | 426 | (apply 'completing-read prompt (occ-get-categories org-project-capture-strategy) |
426 | 427 | args)) |
427 | 428 |
|
| 429 | +(defun org-project-capture-current-project-context () |
| 430 | + "Build an `occ-context' for the current project." |
| 431 | + (let* ((backend (org-project-capture-strategy-get-backend |
| 432 | + org-project-capture-strategy)) |
| 433 | + (project-name (org-project-capture-current-project backend))) |
| 434 | + (unless project-name |
| 435 | + (user-error "Current buffer is not in a recognized project")) |
| 436 | + (make-instance 'occ-context |
| 437 | + :category project-name |
| 438 | + :template org-project-capture-capture-template |
| 439 | + :strategy org-project-capture-strategy |
| 440 | + :options nil))) |
| 441 | + |
| 442 | +(defun org-project-capture-current-project-agenda-settings () |
| 443 | + "Return agenda settings for the current project. |
| 444 | +The return value is a list of the form (PROJECT-NAME CAPTURE-FILE MATCHER)." |
| 445 | + (let* ((context (org-project-capture-current-project-context)) |
| 446 | + (category (oref context category)) |
| 447 | + (strategy (if (object-of-class-p org-project-capture-strategy |
| 448 | + 'org-project-capture-combine-strategies) |
| 449 | + (org-project-capture-select-strategy-from-context |
| 450 | + org-project-capture-strategy context) |
| 451 | + org-project-capture-strategy)) |
| 452 | + (capture-file (occ-get-capture-file strategy category)) |
| 453 | + (matcher (when (object-of-class-p strategy |
| 454 | + 'org-project-capture-single-file-strategy) |
| 455 | + (format "CATEGORY=%S" category)))) |
| 456 | + (list category capture-file matcher))) |
| 457 | + |
428 | 458 | ;;;###autoload |
429 | 459 | (defun org-project-capture-goto-location-for-project (project) |
430 | 460 | "Goto the location at which TODOs for PROJECT are stored." |
@@ -494,5 +524,23 @@ were part of the capture template definition." |
494 | 524 | (error (format "%s is not a recognized project." |
495 | 525 | project-name))))) |
496 | 526 |
|
| 527 | +;;;###autoload |
| 528 | +(defun org-project-capture-agenda-for-current-project (&optional arg) |
| 529 | + "Show an agenda view restricted to the current project. |
| 530 | +
|
| 531 | +With prefix ARG, pass it through to `org-todo-list' when the current |
| 532 | +project uses per-project storage." |
| 533 | + (interactive "P") |
| 534 | + (pcase-let ((`(,project-name ,capture-file ,matcher) |
| 535 | + (org-project-capture-current-project-agenda-settings))) |
| 536 | + (unless (file-exists-p capture-file) |
| 537 | + (user-error "No TODO file exists for current project: %s" project-name)) |
| 538 | + (let ((org-agenda-files (list capture-file)) |
| 539 | + (org-agenda-overriding-header |
| 540 | + (format "Project TODOs: %s" project-name))) |
| 541 | + (if matcher |
| 542 | + (org-tags-view t matcher) |
| 543 | + (org-todo-list arg))))) |
| 544 | + |
497 | 545 | (provide 'org-project-capture) |
498 | 546 | ;;; org-project-capture.el ends here |
0 commit comments