;;; init-org.el --- Initialize Org mode -*- lexical-binding: t -*- ;;; Commentary: ;; https://orgmode.org/ ;;; Code: (require 'org) (require 'ox-html) (global-set-key (kbd "C-S-a") #'org-agenda-list) (define-key org-mode-map (kbd "C-c RET") #'org-meta-return) (define-key org-mode-map (kbd "C-v") #'org-yank) (define-key org-mode-map (kbd "C-y") #'undo-redo) (setq org-agenda-custom-commands '(("|" "Agenda without preset filters" agenda "" ((org-agenda-tag-filter-preset nil))))) (setq org-agenda-deadline-leaders '(nil "+%dd" "-%dd")) (setq org-agenda-files '("~/main/t/tasks")) (setq org-agenda-format-date "%a, %b %d") ; https://www.gnu.org/software/emacs/manual/html_node/elisp/Time-Parsing.html (setq org-agenda-overriding-header "") (setq org-agenda-prefix-format '((agenda . " %?-6t%?-4s[%c] "))) (setq org-agenda-scheduled-leaders '(nil "-%dd")) (setq org-agenda-span 8) (setq org-agenda-start-day "-1d") (setq org-agenda-tag-filter-preset '("-hide")) (setq org-agenda-time-grid '((daily today require-timed) () nil nil)) (setq org-agenda-time-leading-zero t) (setq org-agenda-todo-keyword-format "") (setq org-agenda-use-time-grid nil) (setq org-agenda-window-setup 'current-window) (setq org-blank-before-new-entry nil) (setq org-deadline-warning-days 9) ; More space is needed for earlier warnings. (setq org-export-with-author nil) (setq org-export-with-broken-links t) (setq org-export-with-creator nil) (setq org-export-with-date nil) (setq org-export-with-email nil) (setq org-export-with-section-numbers nil) (setq org-export-with-smart-quotes nil) (setq org-export-with-sub-superscripts nil) (setq org-export-time-stamp-file nil) (setq org-export-with-toc nil) (setq org-fontify-done-headline nil) (setq org-footnote-auto-adjust t) (setq org-footnote-section nil) (setq org-html-doctype "html5") (setq org-html-head-include-default-style nil) (setq org-html-postamble nil) (setq org-html-preamble nil) (setq org-html-xml-declaration nil) (setq org-link-frame-setup '((file . find-file))) (setq org-log-repeat nil) (setq org-priority-default 2) (setq org-priority-highest 1) (setq org-priority-lowest 3) (setq org-publish-use-timestamps-flag nil) (setq org-startup-folded nil) (setq org-startup-indented t) (setq org-tags-column 0) ;; Remove punctuation marks from emphasis prematch and postmatch because they ;; cause too many problems. For example: ;; https://example.com/-/this-slug-was-italicized/ ;; https://example.com/?q="phrase"+"this+phrase+was+struckthrough"+"phrase" (setq org-emphasis-regexp-components '("[:space:]" "[:space:]" "[:space:]" "." 1)) (setq org-html-head (concat "")) (setq org-link-abbrev-alist '(("aliexpress" . "https://www.aliexpress.us/wholesale?sortType=total_tranpro_desc&SearchText=") ("amazon" . "https://www.amazon.com/s?k=") ("amazonbooks" . "https://www.amazon.com/s?i=stripbooks&k=") ("amazontechbooks" . "https://www.amazon.com/s?rh=n%3A5&k=") ("archforums" . "https://www.google.com/search?nfpr=1&num=100&q=site:bbs.archlinux.org+|+site:lists.archlinux.org+|+site:www.reddit.com/r/archlinux+") ("archpackages" . "https://archlinux.org/packages/?q=") ("bestbuy" . "https://www.bestbuy.com/site/searchpage.jsp?st==") ("bestpractices" . "https://www.google.com/search?nfpr=1&num=100&q=\"best+practices\"+|+\"conventions\"+|+\"style\"+") ("bgg" . "https://boardgamegeek.com/search/boardgame?q=") ("boardgameforums" . "https://www.google.com/search?nfpr=1&num=100&q=site:boardgamegeek.com/thread+|+site:www.reddit.com/r/boardgames+") ("boardgameoracle" . "https://www.boardgameoracle.com/boardgame/search?q=") ("camelcamelcamel" . "http://camelcamelcamel.com/products?sq=") ("chewy" . "https://www.chewy.com/s?query=") ("chromewebstore" . "https://www.google.com/search?nfpr=1&num=100&q=site:chrome.google.com/webstore+") ("costco" . "https://www.costco.com/CatalogSearch?keyword=") ("coupons" . "https://www.google.com/search?nfpr=1&num=100&q=coupon+|+coupons+") ("crates" . "https://crates.io/search?sort=recent-downloads&q=") ("dbmigrations" . "https://www.google.com/search?nfpr=1&num=100&q=\"manage.py+migrate\"+|+\"rails+db:migrate\"+|+\"prisma+migrate\"+|+\"artisan+migrate\"+") ("debianforums" . "https://www.google.com/search?nfpr=1&num=100&q=site:lists.debian.org+|+site:forums.debian.net+|+site:reddit.com/r/debian+") ("debianman" . "https://dyn.manpages.debian.org/jump?suite=unstable&q=") ("debianpackages" . "https://packages.debian.org/search?keywords=") ("debianpackagesall" . "https://packages.debian.org/search?&searchon=all&exact=1&keywords=") ("ebay" . "https://www.ebay.com/sch/i.html?_nkw=") ("ebayprice" . "https://www.ebay.com/sch/i.html?_sop=15&_nkw=") ("emacsforums" . "https://www.google.com/search?nfpr=1&num=100&q=site:www.reddit.com/r/emacs+|+site:emacs.stackexchange.com+") ("emacsmailinglists" . "https://www.google.com/search?nfpr=1&num=100&q=site:lists.gnu.org/archive/html/help-gnu-emacs+|+site:lists.gnu.org/archive/html/emacs+") ("etsy" . "https://www.etsy.com/search?q=") ("ewg" . "https://www.ewg.org/skindeep/search/?search=") ("fedorapackages" . "https://packages.fedoraproject.org/search?query=") ("flashlightforums" . "https://www.google.com/search?nfpr=1&num=100&q=site:budgetlightforum.com+|+site:candlepowerforums.com+|+site:www.reddit.com/r/flashlight+") ("fdroid" . "https://search.f-droid.org/?q=") ("firefoxaddons" . "https://addons.mozilla.org/en-US/firefox/search/?type=extension&q=") ("footguns" . "https://www.google.com/search?nfpr=1&num=100&q=\"footgun\"+|+\"footguns\"+|+\"mistake\"+|+\"mistakes\"+") ("github" . "https://github.com/search?type=Repositories&s=stars&q=") ("githubcode" . "https://github.com/search?type=code&auto_enroll=true&q=") ("githubgoogle" . "https://www.google.com/search?nfpr=1&num=100&q=site:github.com+") ("githublanguage" . "https://github.com/search?q=stars%3A%3E1&s=stars&l=") ("goodreads" . "https://www.goodreads.com/search?q=") ("google" . "https://www.google.com/search?nfpr=1&num=100&q=") ("googlebooks" . "https://www.google.com/search?nfpr=1&num=100&tbm=bks&q=") ("googlecloud" . "https://www.google.com/search?nfpr=1&num=100&q=site:cloud.google.com+") ("googleimages" . "https://www.google.com/search?nfpr=1&num=100&tbm=isch&q=") ("googlemaps" . "https://www.google.com/maps/search/") ("googleplay" . "https://play.google.com/store/search?c=apps&q=") ("googleyear" . "https://www.google.com/search?nfpr=1&num=100&tbs=qdr:y&q=") ("hn" . "https://hn.algolia.com/?type=comment&sort=byDate&query=-remote+") ("hntitles" . "https://hn.algolia.com/?type=story&query=") ("homedepot" . "https://www.homedepot.com/s/") ("indeed" . "https://www.indeed.com/jobs?l=Remote&q=") ("leanpub" . "https://leanpub.com/bookstore?search=") ("linux" . "https://www.google.com/search?nfpr=1&num=100&q=Linux+|+CentOS+|+Debian+|+Fedora+|+RHEL+|+Ubuntu+") ("linkedin" . "https://www.linkedin.com/jobs/search/?f_WT=2&keywords=") ("lobsters" . "https://lobste.rs/search?what=comments&q=") ("lobsterstitles" . "https://lobste.rs/search?what=stories&order=relevance&q=") ("lowes" . "http://www.lowes.com/search?searchTerm=") ("lwn" . "https://www.google.com/search?nfpr=1&num=100&tbs=qdr:y&q=site:lwn.net+") ("mdn" . "https://www.google.com/search?nfpr=1&num=100&q=site:developer.mozilla.org/en+") ("melpa" . "https://melpa.org/#/?sort=downloads&asc=false&q=") ("npm" . "https://www.npmjs.com/search?ranking=popularity&q=") ("onelook" . "https://www.onelook.com/?w=") ("oreilly" . "https://www.oreilly.com/search/?formats=book&rows=100&query=") ("pypi" . "https://pypi.org/search/?q=") ("reddit" . "https://www.google.com/search?nfpr=1&num=100&q=site:www.reddit.com+") ("repology" . "https://repology.org/projects/?search=") ("slickdeals" . "https://slickdeals.net/newsearch.php?rating=1&sort=newest&q=") ("target" . "https://www.target.com/s?searchTerm=") ("walgreens" . "https://www.walgreens.com/search/results.jsp?Ntt=") ("walmart" . "https://www.walmart.com/search?query=") ("walmartpetrx" . "https://www.walmartpetrx.com/search.aspx?SearchTerm=") ("wikipedia" . "https://www.google.com/search?nfpr=1&num=100&q=site:en.wikipedia.org+") ("x" . "https://x.com/search?src=typed_query&f=live&q=lang:en+") ("youtube" . "https://www.youtube.com/results?search_query="))) (add-hook 'org-mode-hook (lambda () (auto-fill-mode 1) (electric-indent-local-mode -1) (setq comment-start nil) (add-to-list 'fill-nobreak-predicate #'my-org-fill-link-nobreak-p) (add-to-list 'org-file-apps '("\\.pdf\\'" . "evince %s")) (add-hook 'before-save-hook #'my-org-list-renumber nil t) (add-hook 'before-save-hook #'my-org-table-recalculate nil t) (add-hook 'before-save-hook #'org-footnote-normalize nil t) ;; Run `org-fill-paragraph' after `org-footnote-normalize', ;; not before, or else footnotes may wrap unnecessarily. (add-hook 'before-save-hook #'org-fill-paragraph nil t) (add-hook 'after-save-hook #'my-org-export-html-on-save nil t))) (defvar my-org-export-html-on-save nil) (defun my-org-at-table-header-p () "Return t if the cursor is inside a table header." (when (org-at-table-p) (or (save-excursion (forward-line -1) (not (org-at-table-p))) (save-excursion (forward-line) (org-at-table-hline-p))))) (defun my-org-export-html-on-save () "Export current buffer to HTML on save. The `my-org-export-html-on-save' variable must set to true (e.g., in .dir-locals.el)." (when (eq my-org-export-html-on-save t) (org-html-export-to-html))) (defun my-org-fill-link-nobreak-p () "Don't break a line in a bracketed link. Also, don't break a line at the beginning of a list item that starts with a bracketed link." (or (looking-back "\\[\\[[^]]*\\]\\[[^]]*" nil) ; Link. (looking-back "^[ ]*[-+][ []*" nil) ; Unordered list item. (looking-back "^[ ]*[0-9]+[.) []*" nil))) ; Ordered list item. (defun my-org-insert-line-break () "Insert '\\' at the end of the current line to enforce a line break. https://orgmode.org/manual/Paragraphs.html" (interactive) (move-end-of-line nil) (insert "\\\\")) (defun my-org-list-renumber () "Renumber the current list." (when (and (org-at-item-p) (not (org-at-item-checkbox-p))) (save-excursion (org-beginning-of-item-list) (org-ctrl-c-ctrl-c)))) (defun my-org-table-recalculate () "Recalculate the current table line. If the line is a table header line, don't recalculate the line; only align the table." (when (org-at-table-p) (if (my-org-at-table-header-p) (org-table-align) (org-table-recalculate)))) (defalias 'my-org-export #'org-export-dispatch) (defalias 'my-org-footnote-new #'org-footnote-new) (defalias 'my-org-sort-list #'org-sort-list) (defalias 'my-org-table-insert-hline #'org-table-insert-hline) (defalias 'my-org-table-sort-lines #'org-table-sort-lines) (defalias 'my-org-table-sum #'org-table-sum) (put 'my-org-export-html-on-save 'safe-local-variable #'booleanp) (put 'org-html-head 'safe-local-variable #'stringp) (put 'org-html-postamble 'safe-local-variable #'stringp) (put 'org-html-preamble 'safe-local-variable #'stringp) (provide 'init-org) ;;; init-org.el ends here