Created
May 28, 2010 07:53
-
-
Save valvallow/416891 to your computer and use it in GitHub Desktop.
emacs, view-mode, find-file-hook
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
(add-hook 'find-file-hook | |
'(lambda () | |
(interactive) | |
(view-mode))) |
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
(global-set-key [f7] '(lambda () | |
(interactive) | |
(find-file "~/.emacs") | |
(view-mode))) |
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
;; view-mode | |
(setq view-read-only t) | |
(defvar pager-keybind | |
`( ;; vi-like | |
;; ("h" . backward-word) | |
;; ("l" . forward-word) | |
;; ("j" . next-window-line) | |
;; ("k" . previous-window-line) | |
("h" . backward-char) | |
("l" . forward-char) | |
("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))) | |
("n" . ,(lambda () (interactive) (scroll-up 1))) | |
("p" . ,(lambda () (interactive) (scroll-down 1))) | |
;; bm-easy | |
;; ("." . bm-toggle) | |
;; ("[" . bm-previous) | |
;; ("]" . bm-next) | |
;; 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) | |
(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)) | |
(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) | |
(require 'key-chord) | |
(setq key-chord-two-keys-delay 0.04) | |
(key-chord-mode 1) | |
(key-chord-define-global "jk" 'view-mode) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment