Created
November 4, 2008 15:04
-
-
Save yaotti/22143 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; cf.http://d.hatena.ne.jp/rubikitch/20081104/1225745862 | |
(setq view-read-only t) | |
(defvar pager-keybind | |
`( ;; vi-like | |
("h" . backward-word) | |
("l" . forward-word) | |
("j" . next-line) | |
("k" . previous-line) | |
;;(";" . gene-word) | |
("b" . scroll-down) | |
(" " . scroll-up) | |
;; w3m-like | |
;;("m" . gene-word) | |
;;("i" . win-delete-current-window-and-squeeze) | |
("w" . forward-word) | |
("e" . backward-word) | |
;;("(" . point-undo) | |
;;(")" . point-redo) | |
("J" . ,(lambda () (interactive) (scroll-up 1))) | |
("K" . ,(lambda () (interactive) (scroll-down 1))) | |
("[" . forward-sexp) | |
("]" . backward-sexp) | |
;; | |
("." anything-c-moccur-occur-by-moccur) | |
;;("<" . ) | |
;;(">" . ) | |
;; elscreen | |
("o" . elscreen-toggle) | |
;; langhelp-like | |
("c" . scroll-other-window-down) | |
("v" . scroll-other-window) | |
)) | |
(defun define-many-keys (keymap key-table &optional includes) | |
(let (key cmd) | |
(dolist (key-cmd key-table) | |
(setq key (car key-cmd) | |
cmd (cdr key-cmd)) | |
(if (or (not includes) (member key includes)) | |
(define-key keymap key cmd)))) | |
keymap) | |
(defun view-mode-hook0 () | |
(define-many-keys view-mode-map pager-keybind) | |
(hl-line-mode 1) | |
(define-key view-mode-map " " 'scroll-up)) | |
(add-hook 'view-mode-hook 'view-mode-hook0) | |
;; 書き込み不能なファイルはview-modeで開くように | |
(defadvice find-file | |
(around find-file-switch-to-view-file (file &optional wild) activate) | |
(if (and (not (file-writable-p file)) | |
(not (file-directory-p file))) | |
(view-file file) | |
ad-do-it)) | |
;; 書き込み不能な場合はview-modeを抜けないように | |
(defvar view-mode-force-exit nil) | |
(defmacro do-not-exit-view-mode-unless-writable-advice (f) | |
`(defadvice ,f (around do-not-exit-view-mode-unless-writable activate) | |
(if (and (buffer-file-name) | |
(not view-mode-force-exit) | |
(not (file-writable-p (buffer-file-name)))) | |
(message "File is unwritable, so stay in view-mode.") | |
ad-do-it))) | |
(do-not-exit-view-mode-unless-writable-advice view-mode-exit) | |
(do-not-exit-view-mode-unless-writable-advice view-mode-disable) | |
(provide 'view-support) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment