Skip to content

Commit

Permalink
Fix scroll other windows with pdf-tools and org-noter
Browse files Browse the repository at this point in the history
  • Loading branch information
chuxubank committed Dec 1, 2021
1 parent 232e8ee commit 2cf7a99
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 12 deletions.
20 changes: 13 additions & 7 deletions cats/+org-notes.el
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,19 @@
(use-package org-noter
:defer t
:config
(defun org-noter-update-precise-page-info ()
(interactive)
(org-entry-put nil
org-noter-property-note-location
(org-noter--pretty-print-location
(org-noter--doc-approx-location (org-noter--get-precise-info)))))
(define-key org-noter-notes-mode-map (kbd "M-i") #'org-noter-update-precise-page-info))
(require 'scroll-other-window)
(add-hook 'org-noter-notes-mode-hook #'sow-mode)
(setq org-noter--inhibit-location-change-handler t))

(defun +org-noter-update-precise-page-info ()
(interactive)
(org-entry-put nil
org-noter-property-note-location
(org-noter--pretty-print-location
(org-noter--doc-approx-location (org-noter--get-precise-info)))))

(with-eval-after-load 'org-noter
(define-key org-noter-notes-mode-map (kbd "M-i") #'+org-noter-update-precise-page-info))

(with-eval-after-load 'org
(define-key org-mode-map (kbd "C-c n m") #'org-media-note-hydra/body)
Expand Down
9 changes: 4 additions & 5 deletions cats/+pdf.el
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@
:init
(setq pdf-view-use-scaling t)
:config
(pdf-tools-install))

(add-hook 'pdf-view-mode-hook #'pdf-view-themed-minor-mode)
(pdf-tools-install)
(add-hook 'pdf-view-mode-hook #'pdf-view-themed-minor-mode))

(use-package org-pdftools
:hook (org-mode . org-pdftools-setup-link)
:custom
(org-pdftools-use-isearch-link t))

(defun pdf-keyboard-select-region (&optional all-pages-p)
(defun +pdf-keyboard-select-region (&optional all-pages-p)
"Ref: https://github.com/dalanicolai/dala-emacs-lisp/blob/9662aa2ab993157e6e7587385d27c48ed50a1a50/pdf-keyboard-highlight.el#L79
TODO: Fix all-pages search"
(interactive "P")
Expand All @@ -32,4 +31,4 @@ TODO: Fix all-pages search"
(pdf-view-display-region)))

(with-eval-after-load 'pdf-view
(define-key pdf-view-mode-map (kbd "v") #'pdf-keyboard-select-region))
(define-key pdf-view-mode-map (kbd "v") #'+pdf-keyboard-select-region))
87 changes: 87 additions & 0 deletions elisp/scroll-other-window.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
;;; sow.el --- Variable commands for scrolling the other window.

;; Copyright (C) 2016 Andreas Politz

;; Author: Andreas Politz <politza@fh-trier.de>
;; Keywords: extensions, frames

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.

;;; Commentary:

;;

;;; Code:


(defvar-local sow-scroll-up-command nil)

(defvar-local sow-scroll-down-command nil)

(defvar sow-mode-map
(let ((km (make-sparse-keymap)))
(define-key km [remap scroll-other-window] 'sow-scroll-other-window)
(define-key km [remap scroll-other-window-down] 'sow-scroll-other-window-down)
km)
"Keymap used for `sow-mode'")

(define-minor-mode sow-mode
"FIXME: Not documented."
nil nil nil
:global t)

(defun sow-scroll-other-window (&optional arg)
(interactive "P")
(sow--scroll-other-window-1 arg))

(defun sow-scroll-other-window-down (&optional arg)
(interactive "P")
(sow--scroll-other-window-1 arg t))

(defun sow--scroll-other-window-1 (n &optional down-p)
(let* ((win (other-window-for-scrolling))
(cmd (with-current-buffer (window-buffer win)
(if down-p
(or sow-scroll-down-command #'scroll-up-command)
(or sow-scroll-up-command #'scroll-down-command)))))
(with-current-buffer (window-buffer win)
(save-excursion
(goto-char (window-point win))
(with-selected-window win
(funcall cmd n))
(set-window-point win (point))))))

(add-hook 'Info-mode-hook
(lambda nil
(setq sow-scroll-up-command
(lambda (_) (Info-scroll-up))
sow-scroll-down-command
(lambda (_) (Info-scroll-down)))))

(add-hook 'doc-view-mode-hook
(lambda nil
(setq sow-scroll-up-command
'doc-view-scroll-up-or-next-page
sow-scroll-down-command
'doc-view-scroll-down-or-previous-page)))

(add-hook 'pdf-view-mode-hook
(lambda nil
(setq sow-scroll-up-command
'pdf-view-scroll-up-or-next-page
sow-scroll-down-command
'pdf-view-scroll-down-or-previous-page)))

(provide 'scroll-other-window)
;;; scroll-other-window.el ends here
3 changes: 3 additions & 0 deletions init.el
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
(setq custom-file (expand-file-name "custom.el" user-emacs-directory))
(load custom-file)

;;; packages
(add-to-list 'load-path (expand-file-name "elisp" user-emacs-directory))

;;; modules
(defmacro cat! (filename &optional path noerror)
"Load a module in cats by default"
Expand Down

0 comments on commit 2cf7a99

Please sign in to comment.