Skip to content

Instantly share code, notes, and snippets.

@politza
Created July 3, 2016 08:22
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save politza/3f46785742e6e12ba0d1a849f853d0b9 to your computer and use it in GitHub Desktop.
Save politza/3f46785742e6e12ba0d1a849f853d0b9 to your computer and use it in GitHub Desktop.
scroll-other-window.el
;;; 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
@federkamm
Copy link

Is there a reason that sow--scroll-other-window-1 reads

(if down-p
    (or sow-scroll-down-command #'scroll-up-command)
  (or sow-scroll-up-command #'scroll-down-command))

instead of

(if down-p
    (or sow-scroll-down-command #'scroll-down-command)
  (or sow-scroll-up-command #'scroll-up-command))

i.e., that #'scroll-up-command and #'scroll-down-command are swapped?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment