diff options
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/chrono-tools.el | 2 | ||||
| -rw-r--r-- | modules/org-noter-config.el | 141 | ||||
| -rw-r--r-- | modules/pdf-config.el | 33 | ||||
| -rw-r--r-- | modules/user-constants.el | 4 |
4 files changed, 128 insertions, 52 deletions
diff --git a/modules/chrono-tools.el b/modules/chrono-tools.el index ccbac5f1..37a065f2 100644 --- a/modules/chrono-tools.el +++ b/modules/chrono-tools.el @@ -106,7 +106,7 @@ Present all audio files in the sounds directory and set the chosen file as (interactive) (setq tmr-sound-file notification-sound) (message "Timer sound reset to default: %s" - (file-name-nondirectory notification-package))) + (file-name-nondirectory notification-sound))) (use-package tmr :defer 0.5 diff --git a/modules/org-noter-config.el b/modules/org-noter-config.el index fc578085..34a9a693 100644 --- a/modules/org-noter-config.el +++ b/modules/org-noter-config.el @@ -6,16 +6,20 @@ ;; ;; Workflow: ;; 1. Open a PDF (pdf-view-mode) or EPUB (nov-mode) in Emacs -;; 2. Press F6 to start org-noter session +;; 2. Press 'i' to start org-noter session and insert a note ;; 3. If new book: prompted for title, creates notes file as org-roam node ;; 4. If existing book: finds and opens associated notes file -;; 5. Window splits with document on left (2/3) and notes on right (1/3) -;; 6. Use 'i' to insert notes at current location -;; 7. Notes are saved as org-roam nodes in org-roam-directory +;; 5. Window splits with document (70%) and notes (30%) +;; Split direction chosen automatically based on frame aspect ratio +;; 6. Notes are saved as org-roam nodes in roam-dir ;; -;; Can also start from notes file: open notes via org-roam, press F6 to open document. -;; -;; See docs/org-noter-workflow-spec.org for full specification. +;; Keybindings (C-; n prefix): +;; i - insert note (starts session if needed) +;; t - toggle notes window +;; T - toggle window position (side/bottom) +;; n/p/. - sync next/prev/current note +;; s - headings from TOC +;; q - kill session ;;; Code: @@ -26,29 +30,25 @@ (declare-function nov-mode "ext:nov") (declare-function pdf-view-mode "ext:pdf-view") (defvar nov-file-name) -(defvar org-roam-directory) -(defvar org-dir) - ;;; Configuration Variables -(defvar cj/org-noter-notes-directory - (if (boundp 'org-roam-directory) - org-roam-directory - (expand-file-name "~/sync/org/roam/")) +(defvar cj/org-noter-notes-directory roam-dir "Directory where org-noter notes files are stored. -Defaults to `org-roam-directory' so notes are indexed by org-roam.") - -(defvar cj/org-noter-keybinding (kbd "<f6>") - "Keybinding to start org-noter session.") - -(defvar cj/org-noter-split-direction 'horizontal - "Direction to split window for notes. -`vertical' puts notes on the right (side-by-side). -`horizontal' puts notes on the bottom (stacked).") - -(defvar cj/org-noter-split-fraction 0.67 +Uses `roam-dir' from user-constants so notes are indexed by org-roam.") + +(defun cj/org-noter--preferred-split () + "Return preferred split direction based on frame aspect ratio. +Returns `horizontal-split' (side-by-side) if frame is wide, +`vertical-split' (stacked) otherwise." + (let ((width (frame-pixel-width)) + (height (frame-pixel-height))) + (if (> (/ (float width) height) 1.4) + 'horizontal-split + 'vertical-split))) + +(defvar cj/org-noter-split-fraction 0.70 "Fraction of window for document (notes get the remainder). -Default 0.67 means document gets 2/3, notes get 1/3.") +Default 0.70 means document gets 70%, notes get 30%.") ;;; Helper Functions @@ -182,16 +182,33 @@ When called from a notes file: (let ((notes-file (or (cj/org-noter--find-notes-file) (cj/org-noter--create-notes-file)))) (when notes-file - ;; Open notes file and call org-noter from there - (find-file notes-file) - (goto-char (point-min)) - (org-noter)))) + ;; Recalculate split direction based on current frame dimensions + (setq org-noter-notes-window-location (cj/org-noter--preferred-split)) + ;; Start org-noter from the notes buffer without leaving the document + (let ((notes-buf (find-file-noselect notes-file))) + (with-current-buffer notes-buf + (goto-char (point-min)) + (org-noter)))))) ;; In notes file without session - start session ((cj/org-noter--in-notes-file-p) (org-noter)) (t (message "Not in a document or org-noter notes file")))) +(defun cj/org-noter-insert-note-dwim () + "Insert an org-noter note, starting a session first if needed. +From a PDF/EPUB: starts org-noter session if inactive, then inserts note." + (interactive) + (unless (cj/org-noter--session-active-p) + (cj/org-noter-start) + ;; Return to the document window for the insert + (when (cj/org-noter--session-active-p) + (let ((doc-window (org-noter--get-doc-window))) + (when doc-window + (select-window doc-window))))) + (when (cj/org-noter--session-active-p) + (org-noter-insert-note))) + ;;; Package Configuration (use-package djvu @@ -201,21 +218,16 @@ When called from a notes file: :after (org pdf-tools) :hook (org-mode . org-pdftools-setup-link)) -(global-set-key (kbd "<f6>") #'cj/org-noter-start) - (use-package org-noter :after (:any org pdf-tools djvu nov) :commands org-noter :config - ;; Window layout based on cj/org-noter-split-direction - (setq org-noter-notes-window-location - (if (eq cj/org-noter-split-direction 'vertical) - 'horizontal-split ; confusingly named: horizontal-split = side-by-side - 'vertical-split)) ; vertical-split = stacked + ;; Window layout calculated dynamically at session start + (setq org-noter-notes-window-location (cj/org-noter--preferred-split)) - ;; Split ratio from configuration (first is notes, second is doc) + ;; Split ratio: document gets cj/org-noter-split-fraction, notes get the rest (setq org-noter-doc-split-fraction - (cons (- 1.0 cj/org-noter-split-fraction) + (cons cj/org-noter-split-fraction cj/org-noter-split-fraction)) ;; Basic settings @@ -246,5 +258,56 @@ When called from a notes file: (with-eval-after-load 'org-roam (org-noter-enable-org-roam-integration))) +;;; ---------------------- Notes Window Background Highlight -------------------- + +(defvar-local cj/org-noter--bg-remap-cookie nil + "Cookie for the active-window background face remapping.") + +(defun cj/org-noter--update-active-bg (&rest _) + "Toggle notes buffer background based on whether its window is selected." + (dolist (buf (buffer-list)) + (with-current-buffer buf + (when (bound-and-true-p org-noter-notes-mode) + (let ((active (eq buf (window-buffer (selected-window))))) + (cond + ((and active (not cj/org-noter--bg-remap-cookie)) + (setq cj/org-noter--bg-remap-cookie + (face-remap-add-relative 'default :background "#1d1b19"))) + ((and (not active) cj/org-noter--bg-remap-cookie) + (face-remap-remove-relative cj/org-noter--bg-remap-cookie) + (setq cj/org-noter--bg-remap-cookie nil)))))))) + +(defun cj/org-noter--setup-notes-bg () + "Set up focus-based background tracking in the notes buffer." + (add-hook 'window-selection-change-functions #'cj/org-noter--update-active-bg nil t)) + +(add-hook 'org-noter-notes-mode-hook #'cj/org-noter--setup-notes-bg) + +;;; ----------------------------- Org-Noter Keymap ----------------------------- + +(defvar-keymap cj/org-noter-map + :doc "Keymap for org-noter operations." + "i" #'cj/org-noter-insert-note-dwim + "n" #'org-noter-sync-next-note + "p" #'org-noter-sync-prev-note + "." #'org-noter-sync-current-note + "s" #'org-noter-create-skeleton + "q" #'org-noter-kill-session + "t" #'cj/org-noter-start + "T" #'org-noter-toggle-notes-window-location) +(keymap-set cj/custom-keymap "n" cj/org-noter-map) + +(with-eval-after-load 'which-key + (which-key-add-key-based-replacements + "C-; n" "org-noter menu" + "C-; n i" "insert note" + "C-; n n" "sync next note" + "C-; n p" "sync prev note" + "C-; n ." "sync current note" + "C-; n s" "headings from TOC" + "C-; n q" "kill session" + "C-; n t" "toggle window" + "C-; n T" "toggle window position")) + (provide 'org-noter-config) ;;; org-noter-config.el ends here diff --git a/modules/pdf-config.el b/modules/pdf-config.el index c89295bc..3d952fb5 100644 --- a/modules/pdf-config.el +++ b/modules/pdf-config.el @@ -21,19 +21,32 @@ (pdf-view-use-unicode-ligther nil) ;; Enable HiDPI support, at the cost of memory. (pdf-view-use-scaling t) - :bind - (:map pdf-view-mode-map - ("M" . pdf-view-midnight-minor-mode) - ("m" . bookmark-set) - ("C-=" . pdf-view-enlarge) - ("C--" . pdf-view-shrink) - ("C-c l" . org-store-link) - ("z" . (lambda () (interactive) (cj/open-file-with-command "zathura"))) - ("j" . pdf-view-next-line-or-next-page) - ("k" . pdf-view-previous-line-or-previous-page)) :config (pdf-tools-install :no-query)) ;; automatically compile on first launch +;; Keybindings via eval-after-load on 'pdf-view (not 'pdf-tools), because +;; opening a PDF loads pdf-view.el which provides 'pdf-view — it never +;; loads pdf-tools.el, so use-package :config for pdf-tools won't run. +(with-eval-after-load 'pdf-view + (define-key pdf-view-mode-map "M" #'pdf-view-midnight-minor-mode) + (define-key pdf-view-mode-map "m" #'bookmark-set) + (define-key pdf-view-mode-map (kbd "C-=") #'pdf-view-enlarge) + (define-key pdf-view-mode-map (kbd "C--") #'pdf-view-shrink) + (define-key pdf-view-mode-map (kbd "C-c l") #'org-store-link) + (define-key pdf-view-mode-map "z" (lambda () (interactive) (cj/open-file-with-command "zathura"))) + ;; Arrow keys / j,k: scroll within page only (no page change) + (define-key pdf-view-mode-map "j" #'image-next-line) + (define-key pdf-view-mode-map "k" #'image-previous-line) + (define-key pdf-view-mode-map (kbd "<down>") #'image-next-line) + (define-key pdf-view-mode-map (kbd "<up>") #'image-previous-line) + ;; Org-noter: start session if needed, then insert note + (define-key pdf-view-mode-map "i" #'cj/org-noter-insert-note-dwim) + ;; Page change: C-up/C-down go to top of prev/next page + (define-key pdf-view-mode-map (kbd "C-<down>") + (lambda () (interactive) (pdf-view-next-page-command) (image-bob))) + (define-key pdf-view-mode-map (kbd "C-<up>") + (lambda () (interactive) (pdf-view-previous-page-command) (image-eob)))) + ;; ------------------------------ PDF View Restore ----------------------------- ;; restores the last known position on opening a pdf file. diff --git a/modules/user-constants.el b/modules/user-constants.el index bae34bfe..717e179e 100644 --- a/modules/user-constants.el +++ b/modules/user-constants.el @@ -104,8 +104,8 @@ Used by transcription module and other audio-related functionality.") (defconst drill-dir (expand-file-name "drill/" org-dir) "The location of org-drill org files.") -(defconst snippets-dir (expand-file-name "snippets/" org-dir) - "The location of ya-snippet snippets.") +(defconst snippets-dir (expand-file-name "snippets/" user-emacs-directory) + "The location of yasnippet snippets.") (defvar sounds-dir (expand-file-name "assets/sounds/" user-emacs-directory) "Directory containing sound files for notifications and timers.") |
