From 89d819ad7573721c647a5fc839a5a2716b869947 Mon Sep 17 00:00:00 2001 From: Peter Mao Date: Sat, 10 Jun 2023 23:22:03 -0700 Subject: [PATCH 1/5] override `C-c C-c` and `C-c C-x C-v` in pdf-view-mode Takes keybindings that would not normally be used in pdf-view-mode buffer when running org-noter and runs those keybindings in the notes buffer as if focus was there all along. `C-c C-c` is used by org-babel to run code. If user has focus on the document, then it would normally run `doc-view-toggle-display`, which takes the doc buffer out of org-noter-doc-mode. `C-c C-x C-v` is used by org-babel to toggle inline images. If user has focus on the document, then `C-c C-x` would normally run `image-toggle-hex-display`, which takes the doc buffer out of org-noter-doc-mode. --- modules/org-noter-pdf.el | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/modules/org-noter-pdf.el b/modules/org-noter-pdf.el index ecf67bc..db50d68 100644 --- a/modules/org-noter-pdf.el +++ b/modules/org-noter-pdf.el @@ -499,5 +499,20 @@ current heading inherit the COLUMN_EDGES property." (select-window (org-noter--get-notes-window)) (org-entry-put nil "COLUMN_EDGES" (format "%s" (princ edge-list))))) +;;; override some deleterious keybindings in pdf-view-mode. +(define-key org-noter-doc-mode-map (kbd "C-c C-c") + (lambda () + (interactive) + (other-window 1) + (org-ctrl-c-ctrl-c))) + +(define-prefix-command 'org-noter-pdf-view-prefix) +(define-key org-noter-doc-mode-map (kbd "C-c C-x") 'org-noter-pdf-view-prefix) +(define-key org-noter-pdf-view-prefix (kbd "C-v") + (lambda () + (interactive) + (other-window 1) + (org-toggle-inline-images))) + (provide 'org-noter-pdf) ;;; org-noter-pdf.el ends here From 73c7f5ef8ea5190e77a884ad916ff867d85d9f93 Mon Sep 17 00:00:00 2001 From: Peter Mao Date: Sun, 11 Jun 2023 09:57:25 -0700 Subject: [PATCH 2/5] Make C-c C-x ?? doc -> notes trick work for all 3-key sequences The event following `C-c C-x` is executed as a keyboard macro in the notes window. This generalized `C-c C-x C-v` (`org-toggle-inline-images`) to all 3-key sequences `C-c C-x `. --- modules/org-noter-pdf.el | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/modules/org-noter-pdf.el b/modules/org-noter-pdf.el index db50d68..669b083 100644 --- a/modules/org-noter-pdf.el +++ b/modules/org-noter-pdf.el @@ -506,13 +506,14 @@ current heading inherit the COLUMN_EDGES property." (other-window 1) (org-ctrl-c-ctrl-c))) -(define-prefix-command 'org-noter-pdf-view-prefix) -(define-key org-noter-doc-mode-map (kbd "C-c C-x") 'org-noter-pdf-view-prefix) -(define-key org-noter-pdf-view-prefix (kbd "C-v") - (lambda () - (interactive) +(defun org-noter-pdf--execute-CxCc-in-notes () + "Execute C-c C-x prefixed command in notes buffer." + (interactive) + (let ((this-CxCc-cmd (vector (read-event)))) (other-window 1) - (org-toggle-inline-images))) + (execute-kbd-macro + (vconcat (kbd "C-c C-x") this-CxCc-cmd)))) +(define-key org-noter-doc-mode-map (kbd "C-c C-x") 'org-noter-pdf--execute-CxCc-in-notes) (provide 'org-noter-pdf) ;;; org-noter-pdf.el ends here From 3d155a01ba171635df76c92634208ed47a62c62d Mon Sep 17 00:00:00 2001 From: Peter Mao Date: Sun, 11 Jun 2023 10:06:35 -0700 Subject: [PATCH 3/5] guarantee focus switch to notes window `other-window` only works if the notes window is in the same frame AND is the next window in the cycle. This works for all layouts, using `--get-notes-window` to find the notes window. --- modules/org-noter-pdf.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/org-noter-pdf.el b/modules/org-noter-pdf.el index 669b083..a15965e 100644 --- a/modules/org-noter-pdf.el +++ b/modules/org-noter-pdf.el @@ -503,14 +503,14 @@ current heading inherit the COLUMN_EDGES property." (define-key org-noter-doc-mode-map (kbd "C-c C-c") (lambda () (interactive) - (other-window 1) + (select-window (org-noter--get-notes-window)) (org-ctrl-c-ctrl-c))) (defun org-noter-pdf--execute-CxCc-in-notes () "Execute C-c C-x prefixed command in notes buffer." (interactive) (let ((this-CxCc-cmd (vector (read-event)))) - (other-window 1) + (select-window (org-noter--get-notes-window)) (execute-kbd-macro (vconcat (kbd "C-c C-x") this-CxCc-cmd)))) (define-key org-noter-doc-mode-map (kbd "C-c C-x") 'org-noter-pdf--execute-CxCc-in-notes) From 7b015ba6b29cc87fff75c68eecf7d51e19ef0d76 Mon Sep 17 00:00:00 2001 From: Peter Mao Date: Sun, 11 Jun 2023 13:05:11 -0700 Subject: [PATCH 4/5] wip: tests for pdf keybinding override feature --- tests/org-noter-pdf-tests.el | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/tests/org-noter-pdf-tests.el b/tests/org-noter-pdf-tests.el index 7de7d56..5873993 100644 --- a/tests/org-noter-pdf-tests.el +++ b/tests/org-noter-pdf-tests.el @@ -40,10 +40,30 @@ (expect (string-match "\\:HIGHLIGHT\\:" (buffer-string)) :not :to-be nil) (expect (string-match (format "%s" expected-highlight-info) (buffer-string)) :not :to-be nil) ) + ) + ) + ) + ) - )) + (describe "pdf keybinding overrides" + (it "C-c C-c called from a PDF document executes in the notes buffer" + ;; open `org-noter' session with PDF and notes - ) + ;; execute `C-c C-c' from document buffer + + ;; check that current window is notes-window, check that + ;; last command was `org-ctrl-c-ctrl-c' + ) + + (it "C-c C-x called from a PDF document executes in the notes buffer" + ;; open `org-noter' session with PDF and notes + + ;; execute `C-c C-x ' from document buffer, where + ;; \in {C-b, C-v, maybe a few others} + ;; check that current window is notes-window, check that + ;; last command corresponds to the keybinding of C-c C-x + ;; . + ) ) ) From 652521d65e7ca6b4a5f352e0e0d08b315add5c2b Mon Sep 17 00:00:00 2001 From: Peter Mao Date: Mon, 12 Jun 2023 20:14:07 -0700 Subject: [PATCH 5/5] replace lambda in `define-key' calls with named functions also, invert CxCc to CcCx. --- modules/org-noter-pdf.el | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/modules/org-noter-pdf.el b/modules/org-noter-pdf.el index a15965e..6546a38 100644 --- a/modules/org-noter-pdf.el +++ b/modules/org-noter-pdf.el @@ -501,19 +501,20 @@ current heading inherit the COLUMN_EDGES property." ;;; override some deleterious keybindings in pdf-view-mode. (define-key org-noter-doc-mode-map (kbd "C-c C-c") - (lambda () + (defun org-noter-pdf--execute-CcCc-in-notes () + "Override C-c C-c in pdf document buffer." (interactive) (select-window (org-noter--get-notes-window)) (org-ctrl-c-ctrl-c))) -(defun org-noter-pdf--execute-CxCc-in-notes () - "Execute C-c C-x prefixed command in notes buffer." - (interactive) - (let ((this-CxCc-cmd (vector (read-event)))) - (select-window (org-noter--get-notes-window)) - (execute-kbd-macro - (vconcat (kbd "C-c C-x") this-CxCc-cmd)))) -(define-key org-noter-doc-mode-map (kbd "C-c C-x") 'org-noter-pdf--execute-CxCc-in-notes) +(define-key org-noter-doc-mode-map (kbd "C-c C-x") + (defun org-noter-pdf--execute-CcCx-in-notes () + "Override C-c C-x in pdf document buffer." + (interactive) + (let ((this-CxCc-cmd (vector (read-event)))) + (select-window (org-noter--get-notes-window)) + (execute-kbd-macro + (vconcat (kbd "C-c C-x") this-CxCc-cmd))))) (provide 'org-noter-pdf) ;;; org-noter-pdf.el ends here