home

My NixOS systems configurations.
Log | Files | Refs | LICENSE

config-org.el (35230B)


      1 ;;; config-org.el --- -*- lexical-binding: t; -*-
      2 ;;; Commentary:
      3 ;;; Configuration of orgmode.
      4 ;;; Code:
      5 
      6 (use-package s)
      7 (use-package dash)
      8 
      9 (defconst org-directory "~/desktop/org/"
     10   "org-mode directory, where most of the org-mode file lives")
     11 ;; P.A.R.A. setup
     12 (defconst org-inbox-file (expand-file-name "20231120T124316--inbox__inbox.org" org-directory)
     13   "New stuff collected in this file.")
     14 
     15 (defconst org-archive-dir (expand-file-name "archive" org-directory)
     16   "Directory of archived files.")
     17 
     18 (defconst org-projects-dir (expand-file-name "projects" org-directory)
     19   "Project files directory.")
     20 (defconst org-projects-completed-dir (expand-file-name "projects" org-archive-dir)
     21   "Directory of completed project files.")
     22 (defconst org-projects-future-file (expand-file-name "20231120T124316--future-projects-incubation__project_future.org" org-projects-dir)
     23   "Future projects are collected in this file.")
     24 
     25 (defconst org-areas-dir (expand-file-name "areas" org-directory)
     26   "Area files directory.")
     27 
     28 (defconst org-resources-dir (expand-file-name "resources" org-directory)
     29   "Resource files directory.")
     30 (defconst org-resources-articles-dir (expand-file-name "articles" org-resources-dir)
     31   "Article resource files directory.")
     32 (defconst org-resources-books-dir (expand-file-name "books" org-resources-dir)
     33   "Book resource files directory.")
     34 (defconst org-people-dir (expand-file-name "people" org-directory)
     35   "People files directory.")
     36 (defconst org-journal-dir (expand-file-name "journal" org-directory)
     37   "Journal files directory")
     38 
     39 (defconst src-home-dir (expand-file-name "~/src/home" org-directory)
     40   "Directory of my home monorepository, can contain todos there.")
     41 ;; 2024-06-11: Should it be in home ? I've been going back and forth on this
     42 (defconst src-www-dir (expand-file-name "~/src/www" org-directory)
     43   "Directory of my www repository, can contain todos there.")
     44 
     45 (defconst org-babel-library-file (expand-file-name "org_library_of_babel.org" org-directory)
     46   "Org babel library.")
     47 
     48 (set-register ?i `(file . ,org-inbox-file))
     49 (set-register ?f `(file . ,org-projects-future-file))
     50 (set-register ?p `(file . ,org-projects-dir))
     51 (set-register ?a `(file . ,org-areas-dir))
     52 (set-register ?r `(file . ,org-resources-dir))
     53 (set-register ?P `(file . ,org-people-dir))
     54 (set-register ?j `(file . ,org-journal-dir))
     55 
     56 (defun vde/agenda-goto-view ()
     57   "Jump to the task narrowed but in view mode only to get a glance."
     58   (interactive)
     59   (org-agenda-goto)
     60   (org-narrow-to-subtree)
     61   (view-mode t))
     62 
     63 (defun vde/org-mode-hook ()
     64   "Org-mode hook"
     65   (setq show-trailing-whitespace t)
     66   (when (not (eq major-mode 'org-agenda-mode))
     67     (setq fill-column 90)
     68     (auto-revert-mode 1)
     69     (auto-fill-mode 1)
     70     (org-indent-mode 1)
     71     (visual-line-mode 1)
     72     (add-hook 'before-save-hook 'org-update-all-dblocks)
     73     (add-hook 'auto-save-hook 'org-update-all-dblocks)
     74     (add-hook 'before-save-hook #'save-and-update-includes nil 'make-it-local)))
     75 
     76 (use-package org
     77   :mode (("\\.org$" . org-mode)
     78          ("\\.org.draft$" . org-mode))
     79   :commands (org-agenda org-capture)
     80   :bind (("C-c o l" . org-store-link)
     81          ("C-c o r r" . org-refile)
     82 	 ("C-c o r R" . vde/reload-org-refile-targets)
     83          ("C-c o a a" . org-agenda)
     84 	 ("C-c o a r" . vde/reload-org-agenda-files)
     85          ("C-c o s" . org-sort)
     86          ("<f12>" . org-agenda))
     87   :hook (org-mode . vde/org-mode-hook)
     88   :custom
     89   ;; (org-reverse-note-order '((org-inbox-file . t) ;; Insert items on top of inbox
     90   ;;                           (".*" . nil)))    ;; On any other file, insert at the bottom
     91   (org-archive-location (concat org-archive-dir "/%s::datetree/"))
     92   (org-agenda-file-regexp "^[a-zA-Z0-9-_]+.org$")
     93   (org-use-speed-commands t)
     94   (org-special-ctrl-a/e t)
     95   (org-special-ctrl-k t)
     96   (org-hide-emphasis-markers t)
     97   (org-pretty-entities t)
     98   (org-ellipsis "โ€ฆ")
     99   (org-todo-keywords '((sequence "TODO(t)" "NEXT(n)" "STARTED(s)" "IN-REVIEW(r)" "|" "DONE(d!)" "CANCELED(c@/!)")
    100                        (sequence "WAITING(w@/!)" "SOMEDAY(s)" "|" "CANCELED(c@/!)")
    101                        (sequence "IDEA(i)" "|" "CANCELED(c@/!)")))
    102   (org-todo-state-tags-triggers '(("CANCELLED" ("CANCELLED" . t))
    103                                   ("WAITING" ("WAITING" . t))
    104                                   (done ("WAITING"))
    105                                   ("TODO" ("WAITING") ("CANCELLED"))
    106                                   ("NEXT" ("WAITING") ("CANCELLED"))
    107                                   ("DONE" ("WAITING") ("CANCELLED"))))
    108   (org-log-done 'time)
    109   (org-log-redeadline 'time)
    110   (org-log-reschedule 'time)
    111   (org-log-into-drawer t)
    112   (org-refile-use-outline-path 'file)
    113   (org-refile-allow-creating-parent-nodes 'confirm)
    114   (org-list-demote-modify-bullet '(("+" . "-") ("-" . "+")))
    115   (org-agenda-span 'day)
    116   (org-agenda-start-on-weekday 1)
    117   (org-agenda-window-setup 'current-window)
    118   (org-agenda-skip-scheduled-if-deadline-is-shown t)
    119   (org-agenda-skip-timestamp-if-deadline-is-shown t)
    120   (org-agenda-skip-scheduled-if-done nil)
    121   (org-agenda-current-time-string "")
    122   (org-agenda-time-grid '((daily) () "" ""))
    123   ;; ((agenda . " %i %-12:c%?-12t% s")
    124   ;;  (todo . " %i %-12:c")
    125   ;;  (tags . " %i %-12:c")
    126   ;;  (search . " %i %-12:c"))
    127   ;; (org-agenda-prefix-format "   %i %?-2 t%s")
    128   (org-agenda-prefix-format '((agenda . " %i %?-12t% s")
    129    (todo . " %i")
    130    (tags . " %i")
    131    (search . " %i")))
    132   (org-insert-heading-respect-content t)
    133 
    134   (org-goto-interface 'outline-path-completion)
    135   (org-outline-path-complete-in-steps nil)
    136   (org-goto-max-level 2)
    137 
    138   (org-agenda-category-icon-alist `(("journal"  ,(list (propertize "๐Ÿ“")))
    139 				    ("project--" ,(list (propertize "๐Ÿ’ผ" )))
    140 				    ("tekton-", (list (propertize "๐Ÿ˜ผ")))
    141 				    ("area--"  ,(list (propertize"๐Ÿข" )))
    142 				    ("area--home"  ,(list (propertize"๐Ÿก" )))
    143 				    ("home"  ,(list (propertize"๐Ÿก" )))
    144 				    (".*" '(space . (:width (16))))))
    145 ;;         (org-agenda-compact-blocks t)
    146         (org-agenda-sticky t)
    147 ;;         (org-agenda-include-diary t)
    148   :config
    149 
    150   ;; Org Babel configurations
    151   (when (file-exists-p org-babel-library-file)
    152     (org-babel-lob-ingest org-babel-library-file))
    153   (defun vde/org-agenda-files ()
    154     (apply 'append
    155 		   (mapcar
    156 			(lambda (directory)
    157 			  (directory-files-recursively
    158 			   directory org-agenda-file-regexp))
    159 			`(,org-projects-dir ,org-areas-dir ,org-resources-dir ,org-journal-dir ,src-home-dir ,(expand-file-name "~/src/osp/tasks")))))
    160   (defun vde/reload-org-agenda-files ()
    161     "Reload org-agenda-files variables with up-to-date org files"
    162     (interactive)
    163     (setq org-agenda-files (vde/org-agenda-files)))
    164   (defun vde/reload-org-refile-targets ()
    165     "Reload org-refile-targets variables with up-to-date org files"
    166     (interactive)
    167     (setq org-refile-targets (vde/org-refile-targets)))
    168   (defun vde/org-refile-targets ()
    169     (append '((org-inbox-file :level . 0))
    170 				   (->>
    171 				    (directory-files org-projects-dir nil ".org$")
    172 				    (--remove (s-starts-with? "." it))
    173 				    (--map (format "%s/%s" org-projects-dir it))
    174 				    (--map `(,it :maxlevel . 3)))
    175 				   (->>
    176 				    (directory-files org-areas-dir nil ".org$")
    177 				    (--remove (s-starts-with? "." it))
    178 				    (--map (format "%s/%s" org-areas-dir it))
    179 				    (--map `(,it :maxlevel . 3)))
    180 				   (->>
    181 				    (directory-files-recursively src-home-dir ".org$")
    182 				    (--remove (s-starts-with? "." it))
    183 				    (--map (format "%s" it))
    184 				    (--map `(,it :maxlevel . 2)))
    185 				   ;; (->>
    186 				   ;;  (directory-files-recursively src-www-dir ".org$")
    187 				   ;;  (--remove (s-starts-with? "." it))
    188 				   ;;  (--map (format "%s" it))
    189 				   ;;  (--map `(,it :maxlevel . 2)))
    190 				   (->>
    191 				    (directory-files-recursively org-resources-dir ".org$")
    192 				    (--remove (s-starts-with? (format "%s/legacy" org-resources-dir) it))
    193 				    (--map (format "%s" it))
    194 				    (--map `(,it :maxlevel . 3)))))
    195   (setq org-agenda-files (vde/org-agenda-files)
    196 	;; TODO: extract org-refile-targets into a function
    197 	org-refile-targets (vde/org-refile-targets))
    198   (setq org-agenda-custom-commands
    199 	'(("d" "Daily Agenda"
    200 	   ((agenda ""
    201 		    ((org-agenda-span 'day)
    202 		     (org-deadline-warning-days 5)))
    203 	    (tags-todo "+PRIORITY=\"A\""
    204 		       ((org-agenda-overriding-header "High Priority Tasks")))
    205 	    (todo "NEXT"
    206 		       ((org-agenda-overriding-header "Next Tasks")))))
    207 	  ("i" "Inbox (triage)"
    208 	   ((tags-todo ".*"
    209 		  ((org-agenda-files '("~/desktop/org/20231120T124316--inbox__inbox.org"))
    210 		   (org-agenda-overriding-header "Unprocessed Inbox Item")))))
    211 	  ("u" "Untagged Tasks"
    212 	   ((tags-todo "-{.*}"
    213 		       ((org-agenda-overriding-header "Untagged tasks")))))
    214 	  ("w" "Weekly Review"
    215 	   ((agenda ""
    216 		    ((org-agenda-overriding-header "Completed Tasks")
    217 		     (org-agenda-skip-function '(org-agenda-skip-entry-if 'nottodo 'done))
    218 		     (org-agenda-span 'week)))
    219 	    (agenda ""
    220 		    ((org-agenda-overriding-header "Unfinished Scheduled Tasks")
    221 		     (org-agenda-skip-function '(org-agenda-skip-entry-if 'todo 'done))
    222 		     (org-agenda-span 'week))))))))
    223 
    224 ;; Make sure we load org-protocol
    225 (use-package org-protocol
    226   :after org)
    227 
    228 (use-package org-tempo
    229   :after (org)
    230   :custom
    231   (org-structure-template-alist '(("a" . "aside")
    232 				  ("c" . "center")
    233 				  ("C" . "comment")
    234 				  ("e" . "example")
    235 				  ("E" . "export")
    236 				  ("Ea" . "export ascii")
    237 				  ("Eh" . "export html")
    238 				  ("El" . "export latex")
    239 				  ("q" . "quote")
    240 				  ("s" . "src")
    241 				  ("se" . "src emacs-lisp")
    242 				  ("sE" . "src emacs-lisp :results value code :lexical t")
    243 				  ("sg" . "src go")
    244 				  ("sr" . "src rust")
    245 				  ("sp" . "src python")
    246 				  ("v" . "verse"))))
    247 
    248 (use-package org-id
    249   :after org
    250   :commands contrib/org-id-headlines
    251   :init
    252   (defun contrib/org-id-headlines ()
    253     "Add CUSTOM_ID properties to all headlines in the current
    254 file which do not already have one."
    255     (interactive)
    256     (org-map-entries
    257      (funcall 'contrib/org-get-id (point) 'create)))
    258   :config
    259   (setq org-id-link-to-org-use-id
    260         'create-if-interactive-and-no-custom-id))
    261 
    262 (use-package org-modern
    263   ;; :if window-system
    264   :hook (org-mode . org-modern-mode))
    265 
    266 (use-package org-capture
    267   :after org
    268   :commands (org-capture)
    269   :config
    270 
    271   ;; TODO: refine this, create a function that reset this
    272   (add-to-list 'org-capture-templates
    273                `("l" "Link" entry
    274                  (file ,org-inbox-file)
    275                  "* %a\n%U\n%?\n%i"
    276                  :empty-lines 1))
    277   (add-to-list 'org-capture-templates
    278 	       `("d" "daily entry" entry
    279 		 (file ,(car (denote-journal-extras--entry-today)))
    280                  "* %a\n%U\n%?\n%i"
    281                  :empty-lines 1))
    282   (add-to-list 'org-capture-templates
    283                `("t" "Tasks"))
    284   (add-to-list 'org-capture-templates
    285                `("tt" "New task" entry
    286                  (file ,org-inbox-file)
    287                  "* %?\n:PROPERTIES:\n:CREATED:\t%U\n:END:\n\n%i\n\nFrom: %a"
    288                  :empty-lines 1))
    289   (add-to-list 'org-capture-templates
    290                `("tr" "PR Review" entry
    291                  (file ,org-inbox-file)
    292                  "* TODO review gh:%^{issue} :review:\n:PROPERTIES:\n:CREATED:%U\n:END:\n\n%i\n%?\nFrom: %a"
    293                  :empty-lines 1))
    294 
    295   ;; (add-to-list 'org-capture-templates
    296   ;;              `("m" "Meeting notes" entry
    297   ;;                (file+datetree ,org-meeting-notes-file)
    298   ;;                (file ,(concat user-emacs-directory "/etc/orgmode/meeting-notes.org"))))
    299 
    300   (add-to-list 'org-capture-templates
    301                `("w" "Writing"))
    302   :bind (("C-c o c" . org-capture)))
    303 
    304 (defun vde/dired-notes ()
    305   "Open a dired buffer with all my notes"
    306   (interactive)
    307   (find-dired org-directory "-type f -not -path '*/archive/*'"))
    308 
    309 ;; Using denote as the "source" of my second brain *in* org-mode.
    310 (use-package denote
    311   :bind (("C-c n n" . vde/dired-notes)
    312 	 ("C-c n N" . denote)
    313 	 ("C-c n c" . denote-region)
    314 	 ("C-c n N" . denote-type)
    315 	 ("C-c n d" . denote-date)
    316 	 ("C-c n z" . denote-signature)
    317 	 ("C-c n s" . denote-subdirectory)
    318 	 ("C-c n t" . denote-template)
    319 	 ;; Links
    320 	 ("C-c n i" . denote-link)
    321 	 ("C-c n I" . denote-add-links)
    322 	 ("C-c n b" . denote-backlinks)
    323 	 ("C-c n f f" . denote-find-link)
    324 	 ("C-c n f b" . denote-find-backlink)
    325 	 ;; Renaming
    326 	 ("C-c n r" . denote-rename-file)
    327 	 ("C-c n R" . denote-rename-file-using-front-matter)
    328 	 ;; Journal
    329 	 ("C-c n j j" . denote-journal-extras-new-or-existing-entry)
    330 	 ;; Dired
    331 	 (:map dired-mode-map
    332 	       ("C-c C-d C-i" . denote-link-dired-marked-notes)))
    333   :custom
    334   (denote-directory org-directory)
    335   (denote-rename-buffer-format "๐Ÿ“ %t")
    336   (denote-date-prompt-denote-date-prompt-use-org-read-date t)
    337   (denote-prompts '(subdirectory title keyword))
    338   :hook (dired-mode . denote-dired-mode)
    339   :init
    340   (require 'denote-rename-buffer)
    341   (require 'denote-org-extras)
    342   (require 'denote-journal-extras)
    343   :config
    344   (denote-rename-buffer-mode 1)
    345   (setq denote-journal-extras-directory org-journal-dir
    346 	denote-journal-extras-title-format 'day-date-month-year)
    347   (with-eval-after-load 'org-capture
    348   (setq denote-org-capture-specifiers "%l\n%i\n%?")
    349   (add-to-list 'org-capture-templates
    350                '("n" "New note (with denote.el)" plain
    351                  (file denote-last-path)
    352                  #'denote-org-capture
    353                  :no-save t
    354                  :immediate-finish nil
    355                  :kill-buffer t
    356                  :jump-to-captured t)))
    357   (defun vde/org-category-from-buffer ()
    358     "Get the org category (#+category:) value from the buffer"
    359   (cond
    360    ((string-match (format "^%s.*$" org-journal-dir) (buffer-file-name))
    361     "journal")
    362    (t
    363     (denote-sluggify (denote--retrieve-title-or-filename (buffer-file-name) 'org))))))
    364 
    365 (use-package consult-notes
    366   :commands (consult-notes
    367              consult-notes-search-in-all-notes
    368 	     consult-notes-denote-mode)
    369   :bind (("C-c n F" . consult-notes)
    370 	 ("C-c n S" . consult-notes-search-in-all-notes))
    371   :config
    372   (when (locate-library "denote")
    373     (consult-notes-denote-mode)))
    374 
    375 (use-package orgit)
    376 
    377 (use-package ob-async
    378   :after org
    379   :commands (ob-async-org-babel-execute-src-block))
    380 (use-package ob-emacs-lisp
    381   :after org
    382   :commands (org-babel-execute:emacs-lisp org-babel-execute:elisp))
    383 (use-package ob-go
    384   :after org
    385   :commands (org-babel-execute:go))
    386 (use-package ob-python
    387   :after org
    388   :commands (org-babel-execute:python))
    389 (use-package ob-shell
    390   :after org
    391   :commands (org-babel-execute:ash
    392              org-babel-execute:bash
    393              org-babel-execute:csh
    394              org-babel-execute:dash
    395              org-babel-execute:fish
    396              org-babel-execute:ksh
    397              org-babel-execute:mksh
    398              org-babel-execute:posh
    399              org-babel-execute:sh
    400              org-babel-execute:shell
    401              org-babel-execute:zsh))
    402 ;; my personal
    403 (use-package ol-github
    404   :after (org))
    405 (use-package ol-gitlab
    406   :after (org))
    407 (use-package ol-ripgrep
    408   :after (org))
    409 (use-package ol-rg
    410   :disabled
    411   :after (org))
    412 (use-package ol-grep
    413   :after (org))
    414 
    415 ;; built-in org-mode
    416 (use-package ol-eshell
    417   :after (org))
    418 (use-package ol-git-link
    419   :defer 2
    420   :after (org))
    421 (use-package ol-gnus
    422   :defer 2
    423   :after (org))
    424 (use-package ol-irc
    425   :defer 2
    426   :after (org))
    427 (use-package ol-info
    428   :defer 2
    429   :after (org))
    430 (use-package ol-man
    431   :defer 2
    432   :after (org))
    433 ;; (use-package ol-notmuch
    434 ;;   :defer 2
    435 ;;   :after (org))
    436 ;; (use-package ob-dot
    437 ;;   :after org
    438 ;;   :commands (org-babel-execute:dot))
    439 ;; (use-package ob-ditaa
    440 ;;   :after org
    441 ;;   :commands (org-babel-execute:ditaa)
    442 ;;   :config
    443 ;;   (setq org-ditaa-jar-path "/home/vincent/.nix-profile/lib/ditaa.jar"))
    444 ;; (use-package ob-doc-makefile
    445 ;;   :after org
    446 ;;   :commands (org-babel-execute:makefile))
    447 
    448 (use-package org-nix-shell
    449   :hook (org-mode . org-nix-shell-mode))
    450 
    451 (use-package org-rich-yank
    452   :after org
    453   :bind (:map org-mode-map
    454               ("C-M-y" . org-rich-yank)))
    455 
    456 ;; (use-package org
    457 ;;   ;; :ensure org-plus-contrib ;; load from the package instead of internal
    458 ;;   :mode (("\\.org$" . org-mode)
    459 ;;          ("\\.org.draft$" . org-mode))
    460 ;;   :commands (org-agenda org-capture)
    461 ;;   :bind (("C-c o l" . org-store-link)
    462 ;;          ("C-c o r r" . org-refile)
    463 ;;          ("C-c o a a" . org-agenda)
    464 ;;          ("C-c o a r" . my/reload-org-agenda-files)
    465 ;;          ("C-c o s" . org-sort)
    466 ;;          ("<f12>" . org-agenda)
    467 ;;          ("C-c o c" . org-capture)
    468 ;;          ;; Skeletons
    469 ;;          ("C-c o i p" . vde/org-project)
    470 ;;          ("C-c o i n" . vde/org-www-post))
    471 ;;   :config
    472 ;;   (define-skeleton vde/org-project
    473 ;;     "new org-mode project"
    474 ;;     nil
    475 ;;     > "#+TITLE: " (skeleton-read "Title: ") \n
    476 ;;     > "#+FILETAGS: " (skeleton-read "Tags: ") \n
    477 ;;     > "#+CATEGORY: " (skeleton-read "Category: ") \n
    478 ;;     > _ \n
    479 ;;     > _ \n)
    480 ;;   (define-auto-insert '("/projects/.*\\.org\\'" . "projects org files") [vde/org-project])
    481 ;;   (define-skeleton vde/org-www-post
    482 ;;     "new www post"
    483 ;;     nil
    484 ;;     > "#+title: " (skeleton-read "Title: ") \n
    485 ;;     > "#+date: " (format-time-string "<%Y-%m-%d %a>") \n
    486 ;;     > "#+filetags: " (skeleton-read "Tags: ") \n
    487 ;;     > "#+setupfile: " (skeleton-read "Template (default ../templates/2022.org): ") \n
    488 ;;     > _ \n
    489 ;;     > "* Introduction"
    490 ;;     )
    491 ;;   (define-auto-insert '("/content/.*\\.org\\'" . "blog post org files") [vde/org-www-post])
    492 ;;   (define-auto-insert '("/content/.*\\.draft\\'" . "blog post draft files") [vde/org-www-post])
    493 ;;   ;; Org Babel configurations
    494 ;;   (when (file-exists-p org-babel-library-file)
    495 ;;     (org-babel-lob-ingest org-babel-library-file))
    496 ;;   (setq org-tag-alist '(("linux") ("nixos") ("emacs") ("org")
    497 ;;                         ("openshift") ("redhat") ("tektoncd") ("kubernetes") ("knative" ) ("docker")
    498 ;;                         ("docs") ("code") ("review")
    499 ;;                         (:startgroup . nil)
    500 ;;                         ("#home" . ?h) ("#work" . ?w) ("#errand" . ?e) ("#health" . ?l)
    501 ;;                         (:endgroup . nil)
    502 ;;                         (:startgroup . nil)
    503 ;;                         ("#link" . ?i) ("#read" . ?r) ("#project" . ?p)
    504 ;;                         (:endgroup . nil))
    505 ;;         org-enforce-todo-dependencies t
    506 ;;         org-outline-path-complete-in-steps nil
    507 ;;         org-columns-default-format "%80ITEM(Task) %TODO %3PRIORITY %10Effort(Effort){:} %10CLOCKSUM"
    508 ;;         org-fontify-whole-heading-line t
    509 ;;         org-pretty-entities t
    510 ;;         org-ellipsis " โคต"
    511 ;;         org-archive-location (concat org-completed-dir "/%s::datetree/")
    512 ;;         org-use-property-inheritance t
    513 ;;         org-priority 67
    514 ;;         org-priority-faces '((?A . "#ff2600")
    515 ;;                              (?B . "#ff5900")
    516 ;;                              (?C . "#ff9200")
    517 ;;                              (?D . "#747474"))
    518 ;;         org-global-properties (quote (("EFFORT_ALL" . "0:15 0:30 0:45 1:00 2:00 3:00 4:00 5:00 6:00 0:00")
    519 ;;                                       ("STYLE_ALL" . "habit")))
    520 ;;         org-blank-before-new-entry '((heading . t)
    521 ;;                                      (plain-list-item . nil))
    522 ;;         org-insert-heading-respect-content t
    523 ;;         org-yank-adjusted-subtrees t
    524 ;;         org-image-actual-width nil
    525 ;;         org-startup-with-inline-images nil
    526 ;;         org-catch-invisible-edits 'error
    527 ;;         ;; Put theses into a minor mode
    528 ;;         org-indent-indentation-per-level 1
    529 ;;         org-cycle-separator-lines 1
    530 ;;         org-adapt-indentation nil
    531 ;;         org-hide-leading-stars t
    532 ;;         org-hide-emphasis-markers nil
    533 ;;         org-link-file-path-type 'relative)
    534 ;;   (setcar (nthcdr 4 org-emphasis-regexp-components) 10)
    535 ;;   :hook (org-mode . vde/org-mode-hook))
    536 ;; 
    537 ;; (defun vde/org-mode-hook ()
    538 ;;   "Org-mode hook"
    539 ;;   (setq show-trailing-whitespace t)
    540 ;;   (when (not (eq major-mode 'org-agenda-mode))
    541 ;;     (setq fill-column 90)
    542 ;;     (auto-revert-mode)
    543 ;;     (auto-fill-mode)
    544 ;;     (org-indent-mode)
    545 ;;     (add-hook 'before-save-hook #'save-and-update-includes nil 'make-it-local)))
    546 ;; (use-package org-agenda
    547 ;;   :after org
    548 ;;   :commands (org-agenda)
    549 ;;   :bind (("C-c o a a" . org-agenda)
    550 ;;          ("<f12>" . org-agenda)
    551 ;;          ("C-c o r a" . org-agenda-refile))
    552 ;;   :config
    553 ;;   (use-package org-super-agenda
    554 ;;     :config (org-super-agenda-mode))
    555 ;;   (setq org-agenda-span 'day
    556 ;;         org-agenda-start-on-weekday 1
    557 ;;         org-agenda-include-diary t
    558 ;;         org-agenda-window-setup 'current-window
    559 ;;         org-agenda-skip-scheduled-if-done nil
    560 ;;         org-agenda-compact-blocks t
    561 ;;         org-agenda-sticky t
    562 ;;         org-super-agenda-header-separator ""
    563 ;;         org-agenda-custom-commands
    564 ;;         `(("l" "Links"
    565 ;;            tags "+#link")
    566 ;;           ("w" "Agenda"
    567 ;;            ((agenda "")
    568 ;;             (tags-todo "-goals-incubate-inbox+TODO=\"STARTED\""
    569 ;;                        ((org-agenda-overriding-header "Ongoing")))
    570 ;;             (tags-todo "-goals-incubate-inbox+TODO=\"NEXT\""
    571 ;;                        ((org-agenda-overriding-header "Next"))))
    572 ;;            ((org-super-agenda-groups
    573 ;;              '((:name "Important" :priority "A")
    574 ;;                (:name "Scheduled" :time-grid t)
    575 ;;                (:habit t))))
    576 ;;            (org-agenda-list)))))
    577 
    578 
    579 ;; (use-package org-clock
    580 ;;   :after org
    581 ;;   :commands (org-clock-in org-clock-out org-clock-goto)
    582 ;;   :config
    583 ;;   ;; Setup hooks for clock persistance
    584 ;;   (org-clock-persistence-insinuate)
    585 ;;   (setq org-clock-clocked-in-display nil
    586 ;;         ;; Show lot of clocking history so it's easy to pick items off the C-F11 list
    587 ;;         org-clock-history-length 23
    588 ;;         ;; Change tasks to STARTED when clocking in
    589 ;;         org-clock-in-switch-to-state 'vde/clock-in-to-started
    590 ;;         ;; Clock out when moving task to a done state
    591 ;;         org-clock-out-when-done t
    592 ;;         ;; Save the running clock and all clock history when exiting Emacs, load it on startup
    593 ;;         org-clock-persist t)
    594 ;;   (use-package find-lisp)
    595 ;;   (defun vde/is-project-p ()
    596 ;;     "Any task with a todo keyword subtask"
    597 ;;     (save-restriction
    598 ;;       (widen)
    599 ;;       (let ((has-subtask)
    600 ;;             (subtree-end (save-excursion (org-end-of-subtree t)))
    601 ;;             (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
    602 ;;         (save-excursion
    603 ;;           (forward-line 1)
    604 ;;           (while (and (not has-subtask)
    605 ;;                       (< (point) subtree-end)
    606 ;;                       (re-search-forward "^\*+ " subtree-end t))
    607 ;;             (when (member (org-get-todo-state) org-todo-keywords-1)
    608 ;;               (setq has-subtask t))))
    609 ;;         (and is-a-task has-subtask))))
    610 ;; 
    611 ;;   (defun vde/is-project-subtree-p ()
    612 ;;     "Any task with a todo keyword that is in a project subtree.
    613 ;; Callers of this function already widen the buffer view."
    614 ;;     (let ((task (save-excursion (org-back-to-heading 'invisible-ok)
    615 ;;                                 (point))))
    616 ;;       (save-excursion
    617 ;;         (vde/find-project-task)
    618 ;;         (if (equal (point) task)
    619 ;;             nil
    620 ;;           t))))
    621 ;; 
    622 ;;   (defun vde/find-project-task ()
    623 ;;     "Move point to the parent (project) task if any"
    624 ;;     (save-restriction
    625 ;;       (widen)
    626 ;;       (let ((parent-task (save-excursion (org-back-to-heading 'invisible-ok) (point))))
    627 ;;         (while (org-up-heading-safe)
    628 ;;           (when (member (nth 2 (org-heading-components)) org-todo-keywords-1)
    629 ;;             (setq parent-task (point))))
    630 ;;         (goto-char parent-task)
    631 ;;         parent-task)))
    632 ;; 
    633 ;;   (defun vde/is-task-p ()
    634 ;;     "Any task with a todo keyword and no subtask"
    635 ;;     (save-restriction
    636 ;;       (widen)
    637 ;;       (let ((has-subtask)
    638 ;;             (subtree-end (save-excursion (org-end-of-subtree t)))
    639 ;;             (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
    640 ;;         (save-excursion
    641 ;;           (forward-line 1)
    642 ;;           (while (and (not has-subtask)
    643 ;;                       (< (point) subtree-end)
    644 ;;                       (re-search-forward "^\*+ " subtree-end t))
    645 ;;             (when (member (org-get-todo-state) org-todo-keywords-1)
    646 ;;               (setq has-subtask t))))
    647 ;;         (and is-a-task (not has-subtask)))))
    648 ;; 
    649 ;;   (defun vde/is-subproject-p ()
    650 ;;     "Any task which is a subtask of another project"
    651 ;;     (let ((is-subproject)
    652 ;;           (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
    653 ;;       (save-excursion
    654 ;;         (while (and (not is-subproject) (org-up-heading-safe))
    655 ;;           (when (member (nth 2 (org-heading-components)) org-todo-keywords-1)
    656 ;;             (setq is-subproject t))))
    657 ;;       (and is-a-task is-subproject)))
    658 ;; 
    659 ;;   (defun vde/clock-in-to-started (kw)
    660 ;;     "Switch a task from TODO to STARTED when clocking in.
    661 ;; Skips capture tasks, projects, and subprojects.
    662 ;; Switch projects and subprojects from STARTED back to TODO"
    663 ;;     (when (not (and (boundp 'org-capture-mode) org-capture-mode))
    664 ;;       (cond
    665 ;;        ((and (member (org-get-todo-state) (list "TODO" "NEXT"))
    666 ;;              (vde/is-task-p))
    667 ;;         "STARTED")
    668 ;;        ((and (member (org-get-todo-state) (list "STARTED"))
    669 ;;              (vde/is-project-p))
    670 ;;         "TODO"))))
    671 ;;   :bind (("<f11>" . org-clock-goto)))
    672 ;; (use-package org-habit
    673 ;;   :after (org)
    674 ;;   :config
    675 ;;   (setq org-habit-show-habits-only-for-today nil
    676 ;;         org-habit-graph-column 80))
    677 ;; (use-package org-src
    678 ;;   :after (org)
    679 ;;   :config
    680 ;;   (setq org-src-fontify-natively t
    681 ;;         org-src-tab-acts-natively t
    682 ;;         org-src-window-setup 'current-window
    683 ;;         org-edit-src-content-indentation 0))
    684 ;; (use-package org
    685 ;;   :defer 2
    686 ;;   :config
    687 ;;   (defun vde/tangle-all-notes ()
    688 ;;     "Produce files from my notes folder.
    689 ;; This function will attempt to tangle all org files from `org-notes-dir'. The
    690 ;; assumption is that those will generate configuration file (in `~/src/home'),
    691 ;; and thus keeping the configuration source up-to-date"
    692 ;;     (mapc (lambda (x) (org-babel-tangle-file x))
    693 ;;           (ignore-errors
    694 ;;             (append (directory-files-recursively org-notes-dir "\.org$")
    695 ;;                     (directory-files-recursively src-home-dir "\.org$"))))))
    696 ;; (use-package org-journal
    697 ;;   :commands (org-journal-new-entry org-capture)
    698 ;;   :after org
    699 ;;   :bind
    700 ;;   (("C-c n j" . org-journal-new-entry)
    701 ;;    ("C-c o j" . org-journal-new-entry))
    702 ;;   :config
    703 ;;   (defun org-journal-find-location ()
    704 ;;     "Go to the beginning of the today's journal file.
    705 ;; 
    706 ;; This can be used for an org-capture template to create an entry in the journal."
    707 ;;     ;; Open today's journal, but specify a non-nil prefix argument in order to
    708 ;;     ;; inhibit inserting the heading; org-capture will insert the heading.
    709 ;;     (org-journal-new-entry t)
    710 ;;     ;; Position point on the journal's top-level heading so that org-capture
    711 ;;     ;; will add the new entry as a child entry.
    712 ;;     (widen)
    713 ;;     (goto-char (point-min))
    714 ;;     (org-show-entry))
    715 ;;   (add-to-list 'org-capture-templates
    716 ;;                `("j" "Journal"))
    717 ;;   (add-to-list 'org-capture-templates
    718 ;;                `("jj" "Journal entry" entry (function org-journal-find-location)
    719 ;;                  "** %(format-time-string org-journal-time-format)%^{Title}\n%i%?"
    720 ;;                  :empty-lines 1))
    721 ;;   (add-to-list 'org-capture-templates
    722 ;;                `("je" "Weekly review" entry (function org-journal-find-location)
    723 ;;                  (file ,(expand-file-name "etc/orgmode/weekly.org" user-emacs-directory))
    724 ;;                  :empty-lines 1 :clock-in t :clock-resume t))
    725 ;;   :custom
    726 ;;   (org-journal-date-prefix "* ")
    727 ;;   (org-journal-file-header "#+TITLE: %Y-%m Journal\n\n")
    728 ;;   (org-journal-file-format "%Y-%m.private.org")
    729 ;;   (org-journal-file-type 'monthly)
    730 ;;   (org-journal-dir org-private-notes-dir)
    731 ;;   (org-journal-date-format "%A, %d %B %Y")
    732 ;;   (org-journal-enable-agenda-integration nil))
    733 ;; 
    734 ;;   (defun contrib/org-get-id (&optional pom create prefix)
    735 ;;     "Get the CUSTOM_ID property of the entry at point-or-marker
    736 ;; POM. If POM is nil, refer to the entry at point. If the entry
    737 ;; does not have an CUSTOM_ID, the function returns nil. However,
    738 ;; when CREATE is non nil, create a CUSTOM_ID if none is present
    739 ;; already. PREFIX will be passed through to `org-id-new'. In any
    740 ;; case, the CUSTOM_ID of the entry is returned."
    741 ;;     (org-with-point-at pom
    742 ;;       (let ((id (org-entry-get nil "CUSTOM_ID")))
    743 ;;         (cond
    744 ;;          ((and id (stringp id) (string-match "\\S-" id))
    745 ;;           id)
    746 ;;          (create
    747 ;;           (setq id (org-id-new (concat prefix "h")))
    748 ;;           (org-entry-put pom "CUSTOM_ID" id)
    749 ;;           (org-id-add-location id (buffer-file-name (buffer-base-buffer)))
    750 ;;           id)))))
    751 ;; )
    752 ;; (use-package org-crypt
    753 ;;   :after (org)
    754 ;;   :config
    755 ;;   (org-crypt-use-before-save-magic)
    756 ;;   (setq org-tags-exclude-from-inheritance '("crypt")))
    757 ;; (use-package org-attach
    758 ;;   :after org
    759 ;;   :config
    760 ;;   (setq org-link-abbrev-alist '(("att" . org-attach-expand-link))))
    761 ;; (use-package ox-publish
    762 ;;   :after org
    763 ;;   :commands (org-publish org-publish-all org-publish-project org-publish-current-project org-publish-current-file)
    764 ;;   :config
    765 ;;   (setq org-html-coding-system 'utf-8-unix))
    766 ;; (use-package diary-lib
    767 ;;   :after (org)
    768 ;;   :config
    769 ;;   (setq diary-entry-marker "diary")
    770 ;;   (setq diary-show-holidays-flag t)
    771 ;;   (setq diary-header-line-flag nil)
    772 ;;   (setq diary-mail-days 3)
    773 ;;   (setq diary-number-of-entries 3)
    774 ;;   (setq diary-comment-start ";")
    775 ;;   (setq diary-comment-end "")
    776 ;;   (setq diary-date-forms
    777 ;;         '((day "/" month "[^/0-9]")
    778 ;;           (day "/" month "/" year "[^0-9]")
    779 ;;           (day " *" monthname " *" year "[^0-9]")
    780 ;;           (monthname " *" day "[^,0-9]")
    781 ;;           (monthname " *" day ", *" year "[^0-9]")
    782 ;;           (year "[-/]" month "[-/]" day "[^0-9]")
    783 ;;           (dayname "\\W"))))
    784 ;; 
    785 ;; (use-package org
    786 ;;   :defer t
    787 ;;   :config
    788 ;; 
    789 ;;   (defvar org-capture-templates (list))
    790 ;;   (setq org-protocol-default-template-key "l")
    791 ;; 
    792 ;;   ;; images
    793 ;;   (setq org-image-actual-width nil
    794 ;;         org-startup-with-inline-images nil)
    795 ;; 
    796 ;;   ;; Tasks (-> inbox)
    797 ;; 
    798 ;;   ;; Journal
    799 ;; 
    800 ;;   (add-to-list 'ispell-skip-region-alist '(":\\(PROPERTIES\\|LOGBOOK\\):" ":END:"))
    801 ;;   (add-to-list 'ispell-skip-region-alist '("#\\+BEGIN_SRC" "#\\+END_SRC"))
    802 ;;   (add-to-list 'ispell-skip-region-alist '("#\\+BEGIN_EXAMPLE" "#\\+END_EXAMPLE"))
    803 ;; 
    804 ;;   ;; org-links
    805 ;;   ;; from http://endlessparentheses.com/use-org-mode-links-for-absolutely-anything.html
    806 ;;   (org-link-set-parameters "tag"
    807 ;;                            :follow #'endless/follow-tag-link)
    808 ;;   (defun endless/follow-tag-link (tag)
    809 ;;     "Display a list of TODO headlines with tag TAG.
    810 ;; With prefix argument, also display headlines without a TODO keyword."
    811 ;;     (org-tags-view (null current-prefix-arg) tag))
    812 ;; 
    813 ;;   (org-link-set-parameters
    814 ;;    "org"
    815 ;;    :complete (lambda () (+org-link-read-file "org" org-directory))
    816 ;;    :follow   (lambda (link) (find-file (expand-file-name link org-directory)))
    817 ;;    :face     (lambda (link)
    818 ;;                (if (file-exists-p (expand-file-name link org-directory))
    819 ;;                    'org-link
    820 ;;                  'error)))
    821 ;;   (defun +org-link-read-file (key dir)
    822 ;;     (let ((file (read-file-name (format "%s: " (capitalize key)) dir)))
    823 ;;       (format "%s:%s"
    824 ;;               key
    825 ;;               (file-relative-name file dir))))
    826 ;;   )
    827 ;; 
    828 ;; (use-package org-tree-slide
    829 ;;   :functions (org-display-inline-images
    830 ;;               org-remove-inline-images)
    831 ;;   :bind (:map org-mode-map
    832 ;;               ("s-<f7>" . org-tree-slide-mode)
    833 ;;               :map org-tree-slide-mode-map
    834 ;;               ("<left>" . org-tree-slide-move-previous-tree)
    835 ;;               ("<right>" . org-tree-slide-move-next-tree)
    836 ;;               ("S-SPC" . org-tree-slide-move-previous-tree)
    837 ;;               ("SPC" . org-tree-slide-move-next-tree))
    838 ;;   :hook ((org-tree-slide-play . (lambda ()
    839 ;;                                   (text-scale-increase 4)
    840 ;;                                   (org-display-inline-images)
    841 ;;                                   (read-only-mode 1)))
    842 ;;          (org-tree-slide-stop . (lambda ()
    843 ;;                                   (text-scale-increase 0)
    844 ;;                                   (org-remove-inline-images)
    845 ;;                                   (read-only-mode -1))))
    846 ;;   :init (setq org-tree-slide-header t
    847 ;;               org-tree-slide-slide-in-effect nil
    848 ;;               org-tree-slide-heading-emphasis nil
    849 ;;               org-tree-slide-cursor-init t
    850 ;;               org-tree-slide-modeline-display 'outside
    851 ;;               org-tree-slide-skip-done nil
    852 ;;               org-tree-slide-skip-comments t
    853 ;;               org-tree-slide-content-margin-top 1
    854 ;;               org-tree-slide-skip-outline-level 4))
    855 
    856 ;; from https://sachachua.com/blog/2024/01/using-consult-and-org-ql-to-search-my-org-mode-agenda-files-and-sort-the-results-to-prioritize-heading-matches/
    857 (defun my-consult-org-ql-agenda-jump ()
    858   "Search agenda files with preview."
    859   (interactive)
    860   (let* ((marker (consult--read
    861                   (consult--dynamic-collection
    862                    #'my-consult-org-ql-agenda-match)
    863                   :state (consult--jump-state)
    864                   :category 'consult-org-heading
    865                   :prompt "Heading: "
    866                   :sort nil
    867                   :lookup #'consult--lookup-candidate))
    868          (buffer (marker-buffer marker))
    869          (pos (marker-position marker)))
    870     ;; based on org-agenda-switch-to
    871     (unless buffer (user-error "Trying to switch to non-existent buffer"))
    872     (pop-to-buffer-same-window buffer)
    873     (goto-char pos)
    874     (when (derived-mode-p 'org-mode)
    875       (org-fold-show-context 'agenda)
    876       (run-hooks 'org-agenda-after-show-hook))))
    877 
    878 (defun my-consult-org-ql-agenda-format (o)
    879   (propertize
    880    (org-ql-view--format-element o)
    881    'consult--candidate (org-element-property :org-hd-marker o)))
    882 
    883 (defun my-consult-org-ql-agenda-match (string)
    884   "Return candidates that match STRING.
    885 Sort heading matches first, followed by other matches.
    886 Within those groups, sort by date and priority."
    887   (let* ((query (org-ql--query-string-to-sexp string))
    888          (sort '(date reverse priority))
    889          (heading-query (-tree-map (lambda (x) (if (eq x 'rifle) 'heading x)) query))
    890          (matched-heading
    891           (mapcar #'my-consult-org-ql-agenda-format
    892                   (org-ql-select 'org-agenda-files heading-query
    893                     :action 'element-with-markers
    894                     :sort sort)))
    895          (all-matches
    896           (mapcar #'my-consult-org-ql-agenda-format
    897                   (org-ql-select 'org-agenda-files query
    898                     :action 'element-with-markers
    899                     :sort sort))))
    900     (append
    901      matched-heading
    902      (seq-difference all-matches matched-heading))))
    903 
    904 (use-package org-ql
    905   :after org
    906   :bind ("M-s a" . my-consult-org-ql-agenda-jump))
    907 
    908 (use-package org-ql-view
    909   :after org-ql)
    910 
    911 (provide 'config-org)
    912 ;;; config-org.el ends here