diff options
| author | Mountain Man <43313373+MountainMan1312@users.noreply.github.com> | 2023-05-12 23:45:21 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-05-12 23:45:21 -0400 |
| commit | ffa8e0693ddf12a57dcd9c2b3dd6fb1d1e11f807 (patch) | |
| tree | c8d9547701b2c0cf7aec69824988f8d22f70b8a5 | |
| parent | PR #19: Merge `temporary-theme` branch to `stable` branch (diff) | |
| parent | Bulk org/org-roam PKMS overhaul (diff) | |
| download | mmosmacs-ffa8e0693ddf12a57dcd9c2b3dd6fb1d1e11f807.tar.gz mmosmacs-ffa8e0693ddf12a57dcd9c2b3dd6fb1d1e11f807.tar.bz2 mmosmacs-ffa8e0693ddf12a57dcd9c2b3dd6fb1d1e11f807.zip | |
PR #23: Merge `rfc/21/pkms` branch to `stable` branch
| -rw-r--r-- | .gitignore | 2 | ||||
| -rw-r--r-- | init.el | 300 |
2 files changed, 302 insertions, 0 deletions
| @@ -1,2 +1,4 @@ | |||
| 1 | auto-save-list/ | ||
| 1 | eln-cache/ | 2 | eln-cache/ |
| 2 | straight/ | 3 | straight/ |
| 4 | .org-id-locations | ||
| @@ -116,6 +116,19 @@ | |||
| 116 | 116 | ||
| 117 | (load-theme 'jazz t) | 117 | (load-theme 'jazz t) |
| 118 | 118 | ||
| 119 | (set-background-color "black") | ||
| 120 | |||
| 121 | |||
| 122 | ;; --------------------------------- | ||
| 123 | ;; Fonts | ||
| 124 | ;; ----- | ||
| 125 | ;; For now I use Iosevka and Exo | ||
| 126 | ;; --------------------------------- | ||
| 127 | |||
| 128 | (set-face-attribute 'default nil :font "Iosevka" :height 120) | ||
| 129 | (set-face-attribute 'fixed-pitch nil :font "Iosevka" :height 120) | ||
| 130 | ;;(set-face-attribute 'variable-pitch nil :font "Exo" :height 120 :weight 'regular) | ||
| 131 | (set-face-attribute 'variable-pitch nil :font "-UKWN-Exo 2-normal-normal-normal-*-*-*-*-*-*-0-iso10646-1" :height 120) | ||
| 119 | 132 | ||
| 120 | 133 | ||
| 121 | 134 | ||
| @@ -214,9 +227,15 @@ | |||
| 214 | ;; It helps to know where you are | 227 | ;; It helps to know where you are |
| 215 | ;; --------------------------------- | 228 | ;; --------------------------------- |
| 216 | 229 | ||
| 230 | ;; Display line/column numbers | ||
| 217 | (column-number-mode) | 231 | (column-number-mode) |
| 218 | (global-display-line-numbers-mode t) | 232 | (global-display-line-numbers-mode t) |
| 219 | 233 | ||
| 234 | ;; Disable line numbers in specific modes | ||
| 235 | (dolist (mode '(org-mode-hook | ||
| 236 | org-agenda-mode-hook)) | ||
| 237 | (add-hook mode (lambda () (display-line-numbers-mode 0)))) | ||
| 238 | |||
| 220 | 239 | ||
| 221 | ;; --------------------------------- | 240 | ;; --------------------------------- |
| 222 | ;; Highlight stuff | 241 | ;; Highlight stuff |
| @@ -351,6 +370,287 @@ | |||
| 351 | 370 | ||
| 352 | 371 | ||
| 353 | ;; --------------------------------------------------------------------- | 372 | ;; --------------------------------------------------------------------- |
| 373 | ;;; Personal Knowledge Management System (PKMS) | ||
| 374 | ;; -------------------------------------------- | ||
| 375 | ;; Using `org', `org-roam', and a note-hierarchy I've developed over | ||
| 376 | ;; several years of trial-and-error, I keep all my notes in a logical | ||
| 377 | ;; organized collection. I feel this knowledgebase system can handle | ||
| 378 | ;; almost any bit of information I can throw at it, and it is flexible | ||
| 379 | ;; enough to adapt when I find new things it can't handle. | ||
| 380 | ;; --------------------------------------------------------------------- | ||
| 381 | |||
| 382 | ;; --------------------------------- | ||
| 383 | ;; `org' | ||
| 384 | ;; ----- | ||
| 385 | ;; `org' is a versatile format for | ||
| 386 | ;; note-taking and other stuff. It | ||
| 387 | ;; is the core of my PKMS system. | ||
| 388 | ;; --------------------------------- | ||
| 389 | |||
| 390 | ;; Setup run every time a buffer | ||
| 391 | ;; is opened. | ||
| 392 | (defun mm/org-mode-setup () | ||
| 393 | (org-indent-mode) | ||
| 394 | (visual-line-mode) | ||
| 395 | (variable-pitch-mode)) | ||
| 396 | |||
| 397 | |||
| 398 | ;; Org font stuff | ||
| 399 | (defun mm/org-font-setup () | ||
| 400 | ;; Replace hyphens in lists with dots | ||
| 401 | (font-lock-add-keywords 'org-mode | ||
| 402 | '(("^ *\\([-]\\) " | ||
| 403 | (0 (prog1 () (compose-region (match-beginning 1) (match-end 1) "•")))))) | ||
| 404 | ;; Set font sizes | ||
| 405 | (dolist (face '((org-level-1 . 1.5) | ||
| 406 | (org-level-2 . 1.4) | ||
| 407 | (org-level-3 . 1.3) | ||
| 408 | (org-level-4 . 1.2) | ||
| 409 | (org-level-5 . 1.1) | ||
| 410 | (org-level-6 . 1.1) | ||
| 411 | (org-level-7 . 1.1) | ||
| 412 | (org-level-8 . 1.1))) | ||
| 413 | (set-face-attribute (car face) nil | ||
| 414 | :font "-UKWN-Exo 2-normal-normal-normal-*-*-*-*-*-*-0-iso10646-1" | ||
| 415 | :weight 'regular | ||
| 416 | :height (cdr face)) | ||
| 417 | ;; Ensure anything that should be | ||
| 418 | ;; fixed-pitch actually is. | ||
| 419 | (set-face-attribute 'org-block nil :foreground nil :inherit 'fixed-pitch) | ||
| 420 | (set-face-attribute 'org-table nil :inherit 'fixed-pitch) | ||
| 421 | (set-face-attribute 'org-formula nil :inherit 'fixed-pitch) | ||
| 422 | (set-face-attribute 'org-code nil :inherit '(shadow fixed-pitch)) | ||
| 423 | (set-face-attribute 'org-table nil :inherit '(shadow fixed-pitch)) | ||
| 424 | (set-face-attribute 'org-verbatim nil :inherit '(shadow fixed-pitch)) | ||
| 425 | (set-face-attribute 'org-special-keyword nil :inherit '(font-lock-comment-face fixed-pitch)) | ||
| 426 | (set-face-attribute 'org-meta-line nil :inherit '(font-lock-comment-face fixed-pitch)) | ||
| 427 | (set-face-attribute 'org-checkbox nil :inherit 'fixed-pitch) | ||
| 428 | (set-face-attribute 'org-time-grid nil :inherit 'fixed-pitch) | ||
| 429 | (set-face-attribute 'org-scheduled nil :inherit 'fixed-pitch) | ||
| 430 | (set-face-attribute 'org-agenda-structure nil :inherit 'fixed-pitch) | ||
| 431 | (set-face-attribute 'org-agenda-date nil :inherit 'fixed-pitch) | ||
| 432 | (set-face-attribute 'org-agenda-date-today nil :inherit 'fixed-pitch) | ||
| 433 | (set-face-attribute 'org-agenda-current-time nil :inherit 'fixed-pitch) | ||
| 434 | (set-face-attribute 'org-agenda-calendar-event nil :inherit 'fixed-pitch))) | ||
| 435 | |||
| 436 | |||
| 437 | ;; `org' configuration | ||
| 438 | (use-package org | ||
| 439 | :straight t | ||
| 440 | :hook (org-mode . mm/org-mode-setup) | ||
| 441 | :config | ||
| 442 | (mm/org-font-setup) | ||
| 443 | (setq org-ellipsis " ►" | ||
| 444 | org-hide-leading-stars t | ||
| 445 | org-adapt-indentation t | ||
| 446 | org-support-shift-select 'always | ||
| 447 | org-return-follows-link t) | ||
| 448 | (advice-add 'org-refile :after 'org-save-all-org-buffers) | ||
| 449 | :bind | ||
| 450 | ("C-c t l" . org-toggle-link-display)) | ||
| 451 | |||
| 452 | |||
| 453 | ;; Make org heading bullets look nicer | ||
| 454 | (use-package org-bullets | ||
| 455 | :straight t | ||
| 456 | :hook (org-mode . org-bullets-mode) | ||
| 457 | :custom | ||
| 458 | (org-bullets-bullet-list '("•"))) | ||
| 459 | |||
| 460 | |||
| 461 | ;; Auto-show emphasis markers on hover | ||
| 462 | (use-package org-appear | ||
| 463 | :straight t | ||
| 464 | :hook (org-mode . org-appear-mode) | ||
| 465 | :config | ||
| 466 | (setq org-hide-emphasis-markers t | ||
| 467 | org-appear-autolinks t | ||
| 468 | org-appear-autosubmarkers t)) | ||
| 469 | |||
| 470 | |||
| 471 | ;; Show link hints to make following links easier | ||
| 472 | (use-package link-hint | ||
| 473 | :straight t | ||
| 474 | :bind | ||
| 475 | ("C-c l o" . link-hint-open-link) | ||
| 476 | ("C-c l c" . link-hint-copy-link)) | ||
| 477 | |||
| 478 | |||
| 479 | ;; --------------------------------- | ||
| 480 | ;; `org-roam' | ||
| 481 | ;; ---------- | ||
| 482 | ;; Org roam adds a ton of PKMS | ||
| 483 | ;; functionality to org. | ||
| 484 | ;; --------------------------------- | ||
| 485 | |||
| 486 | ;; Define function to insert a link to a node without opening it | ||
| 487 | (defun mm/org-roam-node-insert-immediate (arg &rest args) | ||
| 488 | "This version of `org-roam-node-insert' inserts a node without opening it." | ||
| 489 | (interactive "P") | ||
| 490 | (let ((args (cons arg args)) | ||
| 491 | (org-roam-capture-templates (list (append (car org-roam-capture-templates) | ||
| 492 | '(:immediate-finish))))) | ||
| 493 | (apply #'org-roam-node-insert args))) | ||
| 494 | |||
| 495 | |||
| 496 | ;; Add Dendron-like note refactoring functionality | ||
| 497 | ;; This was taken from https://github.com/vicrdguez/dendroam | ||
| 498 | (cl-defmethod mm/org-roam-node-current-file (node) | ||
| 499 | (file-name-base (org-roam-node-file node))) | ||
| 500 | |||
| 501 | (cl-defmethod mm/org-roam-node-hierarchy-title (node) | ||
| 502 | (capitalize (car (last (split-string (org-roam-node-title node) | ||
| 503 | "\\."))))) | ||
| 504 | |||
| 505 | (defun mm/org-roam-refactor-file () | ||
| 506 | (interactive) | ||
| 507 | (let* ((initial-file (buffer-file-name)) | ||
| 508 | (initial-slug (file-name-base initial-file)) | ||
| 509 | (new-slug (read-string "Refactor: " initial-slug)) | ||
| 510 | (new-file (concat | ||
| 511 | (expand-file-name new-slug org-roam-directory) | ||
| 512 | ".org"))) | ||
| 513 | (rename-file initial-file new-file) | ||
| 514 | (kill-current-buffer) | ||
| 515 | (find-file new-file))) | ||
| 516 | |||
| 517 | (cl-defmethod mm/org-roam-node-hierarchy (node) | ||
| 518 | (funcall 'mm/org-roam-format-hierarchy (org-roam-node-file node))) | ||
| 519 | |||
| 520 | (cl-defmethod mm/org-roam-node-current-file (node) | ||
| 521 | (file-name-base (buffer-file-name))) | ||
| 522 | |||
| 523 | (defun mm/org-roam-get-same-hierarchy-files (hierarchy) | ||
| 524 | "Gets all the nodes that share the same HIERARCHY totally or partially" | ||
| 525 | (let ((files (mapcar #'car (org-roam-db-query [:select [file] | ||
| 526 | :from nodes | ||
| 527 | :where (like file $r1)] | ||
| 528 | (concat "%" hierarchy "%"))))) files)) | ||
| 529 | |||
| 530 | (defun mm/org-roam-refactor-hierarchy (&optional current) | ||
| 531 | (interactive) | ||
| 532 | (let* | ||
| 533 | ((initial-file (file-name-nondirectory (buffer-file-name))) | ||
| 534 | (initial-slug (file-name-base initial-file)) | ||
| 535 | (new-slug (file-name-base (read-string "Refactor: " initial-slug))) | ||
| 536 | (initial-slug-no-title | ||
| 537 | (file-name-base initial-slug)) | ||
| 538 | (files-to-upd (if current `(,initial-file) | ||
| 539 | (mm/org-roam-get-same-hierarchy-files | ||
| 540 | initial-slug-no-title)))) | ||
| 541 | (dolist (file files-to-upd) | ||
| 542 | (let ((new-file | ||
| 543 | (replace-regexp-in-string initial-slug-no-title new-slug file))) | ||
| 544 | (rename-file file new-file) | ||
| 545 | (if (equal buffer-file-name file) | ||
| 546 | (progn | ||
| 547 | (kill-current-buffer) | ||
| 548 | (find-file new-file))))))) | ||
| 549 | |||
| 550 | |||
| 551 | ;; `org-roam' configuration | ||
| 552 | (use-package org-roam | ||
| 553 | :straight t | ||
| 554 | :custom | ||
| 555 | (org-roam-directory (file-truename "~/kb")) | ||
| 556 | (make-directory org-roam-directory 'parents) | ||
| 557 | (org-roam-db-location (concat org-roam-directory "/org-roam.db")) | ||
| 558 | (org-roam-capture-templates | ||
| 559 | '(("d" "default" plain "%?" | ||
| 560 | :unnarrowed t | ||
| 561 | :if-new (file+head "${title}.org" | ||
| 562 | "#+TITLE:")))) | ||
| 563 | (org-roam-dailies-capture-templates | ||
| 564 | '(("d" "default" plain "%?" | ||
| 565 | :unnarrowed t | ||
| 566 | :if-new (file+head "daily.%<%Y.%m.%d>.org" | ||
| 567 | "#+TITLE: Daily Log for %<%Y-%m-%d>\n")))) | ||
| 568 | (org-roam-complete-everywhere t) | ||
| 569 | :config | ||
| 570 | (org-roam-setup) | ||
| 571 | (org-roam-db-autosync-mode) | ||
| 572 | (require 'org-roam-dailies) | ||
| 573 | (setq org-roam-dailies-directory "") | ||
| 574 | :bind (("C-c n f" . org-roam-node-find) | ||
| 575 | ("C-c n c" . org-roam-capture) | ||
| 576 | ("C-c n d t" . org-roam-dailies-goto-today) | ||
| 577 | ("C-c n d y" . org-roam-dailies-goto-yesterday) | ||
| 578 | ("C-c n i" . mm/org-roam-node-insert-immediate) | ||
| 579 | ("C-c n I" . org-roam-node-insert) | ||
| 580 | ("C-c n u" . org-roam-update-org-id-locations) | ||
| 581 | ("C-c n r h" . mm/org-roam-refactor-hierarchy) | ||
| 582 | ("C-c n r f" . mm/org-roam-refactor-file))) | ||
| 583 | |||
| 584 | |||
| 585 | ;; --------------------------------- | ||
| 586 | ;; Task / Time Management | ||
| 587 | ;; ---------------------- | ||
| 588 | ;; I track everything in org. It | ||
| 589 | ;; makes it easier to remember | ||
| 590 | ;; things, which is handy because I | ||
| 591 | ;; am quite forgetful. | ||
| 592 | ;; --------------------------------- | ||
| 593 | |||
| 594 | ;; Agenda configuration | ||
| 595 | (use-package org | ||
| 596 | :config | ||
| 597 | (setq org-agenda-start-with-log-mode t | ||
| 598 | org-agenda-files '("~/kb/agenda.org") | ||
| 599 | org-todo-keywords'((sequence "TODO(t)" "IN-PROGRESS(i)" "WAITING(w)" "HOLD(h)" "REVIEW(re)" "|" "DONE(d)" "CANCELED(c)") | ||
| 600 | (sequence "EVENT(e)" "|" "MISSED_EVENT(me)" "ATTENDED_EVENT(ae)") | ||
| 601 | (sequence "APPT(ap)" "|" "MISSED_APPT(ma)" "ATTENDED_APPT(aa)") | ||
| 602 | (sequence "REMINDER(rm)")) | ||
| 603 | org-agenda-span 7 | ||
| 604 | org-agenda-start-day "0d" | ||
| 605 | org-agenda-start-on-weekday nil | ||
| 606 | org-agenda-use-time-grid t | ||
| 607 | org-agenda-time-grid (quote ((daily today remove-match) | ||
| 608 | (0 100 200 300 400 500 600 700 800 900 | ||
| 609 | 1000 1100 1200 1300 1400 1500 1600 | ||
| 610 | 1700 1800 1900 2000 2100 2200 2300) | ||
| 611 | "......." ".")) | ||
| 612 | org-agenda-include-diary t | ||
| 613 | org-agenda-show-future-repeats nil | ||
| 614 | org-agenda-repeating-timestamp-show-all nil | ||
| 615 | org-agenda-skip-scheduled-if-done t | ||
| 616 | org-agenda-skip-deadline-if-done t | ||
| 617 | org-agenda-show-done-always-green nil | ||
| 618 | org-agenda-compact-blocks t | ||
| 619 | org-log-done 'time | ||
| 620 | org-log-into-drawer t) | ||
| 621 | (require 'org-habit) | ||
| 622 | (add-to-list 'org-modules 'org-habit) | ||
| 623 | (setq org-habit-show-habits t | ||
| 624 | org-habit-show-habits-only-for-today nil | ||
| 625 | org-habit-show-all-today nil | ||
| 626 | org-habit-graph-column 60 | ||
| 627 | org-habit-following-days 1 | ||
| 628 | org-habit-preceding-days 21) | ||
| 629 | :bind (("C-c a" . org-agenda-list))) | ||
| 630 | |||
| 631 | |||
| 632 | ;; Update agenda periodically every `mm/refresh-agenda-time-seconds' seconds. | ||
| 633 | ;; This was taken from https://emacs.stackexchange.com/a/68767/38877 | ||
| 634 | (defvar mm/refresh-agenda-time-seconds 15) | ||
| 635 | (defvar mm/refresh-agenda-timer nil | ||
| 636 | "Timer for `mm/refresh-agenda-timer-function' to reschedule itself, or NIL") | ||
| 637 | (defun mm/refresh-agenda-timer-function () | ||
| 638 | "If the user types a command while `mm/refresh-agenda-timer' is active, the next time this function is called from it's main idle timer, deactivate `mm/refresh-agenda-timer'." | ||
| 639 | (when mm/refresh-agenda-timer | ||
| 640 | (cancel-timer mm/refresh-agenda-timer)) | ||
| 641 | ;;(lambda () (save-window-excursion (org-agenda nil "a"))) | ||
| 642 | (save-window-excursion (org-agenda nil "a")) | ||
| 643 | (setq mm/refresh-agenda-timer | ||
| 644 | (run-with-idle-timer | ||
| 645 | (time-add (current-idle-time) mm/refresh-agenda-time-seconds) | ||
| 646 | nil | ||
| 647 | 'mm/refresh-agenda-timer-function))) | ||
| 648 | (run-with-idle-timer mm/refresh-agenda-time-seconds t 'mm/refresh-agenda-timer-function) | ||
| 649 | |||
| 650 | |||
| 651 | |||
| 652 | |||
| 653 | ;; --------------------------------------------------------------------- | ||
| 354 | ;;; Keybinds | 654 | ;;; Keybinds |
| 355 | ;; --------- | 655 | ;; --------- |
| 356 | ;; For now, just a few simple changes. | 656 | ;; For now, just a few simple changes. |