org customizations

This commit is contained in:
Levi 2024-08-30 10:12:21 +02:00
parent f04243060a
commit a113759c6e
2 changed files with 80 additions and 45 deletions

View File

@ -10,7 +10,7 @@
'(indent-tabs-mode nil)
'(mac-option-modifier '(:ordinary meta :function meta :mouse meta))
'(package-selected-packages
'(winner-mode fzf prescient doom-modeline emms denote-explore denote multi-vterm ox-hugo plz flycheck-projectile ob-go devil realgud projectile dash async yasnippet ace-jump ace-jump-mode async-status cape corfu dired-git dired-git-info embark eshell-toggle eshell-vterm fic-mode flycheck git-lens git-link go-projectile go-scratch graphviz-dot-mode json-mode kotlin-mode lsp-mode magit mmm-mode multi-web-mode multifiles multiple-cursors multishell nerd-icons-completion nerd-icons-corfu nerd-icons-dired nerd-icons-ibuffer orderless org-ai org-context org-dashboard persistent-scratch php-mode plantuml-mode project-explorer projectile-ripgrep protobuf-mode quelpa-use-package rego-mode unicode-fonts vertico vterm-toggle wgrep which-key yaml-mode))
'(language-detection jiralib2 request ox-jira ejira jirascope winner-mode fzf prescient doom-modeline emms denote-explore denote multi-vterm ox-hugo plz flycheck-projectile ob-go devil realgud projectile dash async yasnippet ace-jump ace-jump-mode async-status cape corfu dired-git dired-git-info embark eshell-toggle eshell-vterm fic-mode flycheck git-lens git-link go-projectile go-scratch graphviz-dot-mode json-mode kotlin-mode lsp-mode magit mmm-mode multi-web-mode multifiles multiple-cursors multishell nerd-icons-completion nerd-icons-corfu nerd-icons-dired nerd-icons-ibuffer orderless org-ai org-context org-dashboard persistent-scratch php-mode plantuml-mode project-explorer projectile-ripgrep protobuf-mode quelpa-use-package rego-mode unicode-fonts vertico vterm-toggle wgrep which-key yaml-mode))
'(tab-width 4)
'(tool-bar-mode nil)
'(use-short-answers t))

View File

@ -1,3 +1,5 @@
(require 'use-package)
(use-package emacs
:init
;; package management
@ -134,59 +136,84 @@
;; org-mode
;; ===
(use-package org :ensure t
:mode (("\\.org$" . org-mode)))
;; Set up org-agenda-files to include ~/notes and its subdirectories
(setq org-agenda-files
(directory-files-recursively "~/notes" "\\.org$"))
(use-package org
:ensure t
:mode (("\\.org$" . org-mode))
:bind (("C-x O a" . org-agenda)
("C-x O c" . org-capture))
:config
(defun my/org-config ()
(setq org-todo-keywords
'((sequence "HOLD(h)" "TODO(t)" "|" "DONE(d)" "CNCL(x)")))
;; Configure org-agenda-prefix-format to show minimal information
(setq org-agenda-prefix-format
'((agenda . " %i ")
(todo . " %i ")
(tags . " %i ")
(search . " %i ")))
(setq org-todo-keyword-faces
'(("HOLD" . (:foreground "orange" :weight bold))
("TODO" . (:foreground "red" :weight bold))
("DONE" . (:foreground "green" :weight bold))
("CNCL" . (:foreground "gray" :weight bold))))
(setq org-agenda-files
(append
(list "~/TODO.org")
(directory-files-recursively "~/notes" "\\.org$")))
;; Hide the filename in the agenda view
(setq org-agenda-hide-tags-regexp ".")
(setq org-agenda-prefix-format
'((agenda . " %i ")
(todo . " %i ")
(tags . " %i ")
(search . " %i ")))
;; Remove the filename from agenda and TODO items, but keep the keyword
(defun my-org-agenda-format-item (item)
"Format an agenda or TODO item without the filename, but keep the keyword."
(let* ((marker (or (get-text-property 0 'org-marker item)
(get-text-property 0 'org-hd-marker item)))
(line (when marker
(org-with-point-at marker
(buffer-substring (line-beginning-position) (line-end-position)))))
(todo-keyword (when marker
(org-with-point-at marker
(org-get-todo-state))))
(truncated-line (when line
(replace-regexp-in-string "^\\[#[A-Z]\\] " "" line))))
(if truncated-line
(let ((clean-item (replace-regexp-in-string "^\\(\\*+ \\)" "" truncated-line)))
(if todo-keyword
(concat todo-keyword " " (replace-regexp-in-string (concat "^" todo-keyword " ?") "" clean-item))
clean-item))
item)))
(setq org-agenda-hide-tags-regexp ".")
;; Apply our custom formatting to agenda items
(advice-add 'org-agenda-format-item-line :filter-return #'my-org-agenda-format-item)
(setq org-agenda-todo-keyword-format "%s")
;; Apply our custom formatting to TODO items
(advice-add 'org-agenda-format-item :filter-return #'my-org-agenda-format-item)
(defun my-org-agenda-format-item (item)
"Format an agenda or TODO item without the filename, but keep the keyword."
(let* ((marker (or (get-text-property 0 'org-marker item)
(get-text-property 0 'org-hd-marker item)))
(line (when marker
(org-with-point-at marker
(buffer-substring (line-beginning-position) (line-end-position)))))
(todo-keyword (when marker
(org-with-point-at marker
(org-get-todo-state))))
(truncated-line (when line
(replace-regexp-in-string "^\\[#[A-Z]\\] " "" line))))
(if truncated-line
(let ((clean-item (replace-regexp-in-string "^\\(\\*+ \\)" "" truncated-line)))
(if todo-keyword
(concat todo-keyword " " (replace-regexp-in-string (concat "^" todo-keyword " ?") "" clean-item))
clean-item))
item)))
;; Keep the TODO keyword visible in the agenda
(setq org-agenda-todo-keyword-format "%s")
(advice-add 'org-agenda-format-item-line :filter-return #'my-org-agenda-format-item)
(advice-add 'org-agenda-format-item :filter-return #'my-org-agenda-format-item))
;; Ensure org-agenda is refreshed when files are added or removed
(defun refresh-org-agenda-files ()
(interactive)
(setq org-agenda-files
(directory-files-recursively "~/notes" "\\.org$")))
(defun my/org-refile-config ()
(setq org-refile-targets '((nil :maxlevel . 9)
("~/TODO.org" :maxlevel . 9)))
(setq org-refile-use-outline-path 'file)
(setq org-outline-path-complete-in-steps nil)
(setq org-refile-allow-creating-parent-nodes 'confirm))
(run-with-idle-timer 300 t 'refresh-org-agenda-files)
(defun my/org-capture-config ()
(setq org-capture-templates
'(("t" "TODO" entry (file "~/TODO.org")
"* TODO %?\n %i\n %a" :prepend t))))
(defun refresh-org-agenda-files ()
(interactive)
(setq org-agenda-files
(append
(list "~/TODO.org")
(directory-files-recursively "~/notes" "\\.org$"))))
(my/org-config)
(my/org-refile-config)
(my/org-capture-config)
(run-with-idle-timer 300 t 'refresh-org-agenda-files))
@ -491,4 +518,12 @@
(interactive)
(load-file user-init-file))
(defun reload-org-config ()
"Reload the org configuration."
(interactive)
(my/org-config)
(message "Org configuration reloaded"))
(global-set-key (kbd "C-x c O") 'reload-org-config)
(global-set-key (kbd "C-x c r") #'reload-init-file)