Last active
December 12, 2015 02:58
-
-
Save hiroina/4702961 to your computer and use it in GitHub Desktop.
.emacs for windows
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
;; Hiro Inaba | |
;;------------------------------------------------------------ | |
;; Help | |
;;------------------------------------------------------------ | |
; | |
; M-x occur list lines that contains a keyword in the buffer | |
; M-x multi-occur list lines that contains a keyword in multiple buffer | |
; | |
;;------------------------------------------------------------ | |
;; dired | |
;;------------------------------------------------------------ | |
; | |
; ^ Goto parent directory | |
; | |
;;------------------------------------------------------------ | |
;; Customization | |
;;------------------------------------------------------------ | |
;; C style | |
(add-hook 'c-mode-common-hook | |
'(lambda () | |
(c-set-style "stroustrup") | |
(setq indent-tabs-mode nil) | |
(setq c-basic-offset 4) | |
)) | |
;; C++ style | |
(add-hook 'c++-mode-common-hook | |
'(lambda () | |
(c-set-style "stroustrup") | |
(setq indent-tabs-mode nil) | |
(setq c-basic-offset 4) | |
)) | |
;; UTF-8 support | |
;(require 'un-define) | |
;(require 'jisx0213) | |
;; Enable Wind Move | |
;; Shift+[arrow-key] to move cursor to other window | |
(when (fboundp 'windmove-default-keybindings) | |
(windmove-default-keybindings)) | |
;; Remove menu bar and tool bar | |
(menu-bar-mode -1) | |
(tool-bar-mode -1) | |
;; Initial Window Size | |
(setq initial-frame-alist | |
(append (list | |
'(width . 100) | |
'(height . 55) | |
) | |
initial-frame-alist)) | |
(setq default-frame-alist initial-frame-alist) | |
;; Use clipboard | |
(setq x-select-enable-clipboard t) | |
;(global-set-key "\C-y" 'x-clipboard-yank) | |
;; Key binding | |
(global-set-key "\M-g" 'goto-line) | |
(global-set-key "\M-r" 'replace-string) | |
;; load path | |
(setq load-path (cons "~/elisp" load-path)) | |
;(set-default-coding-systems 'sjis-dos') | |
(set-language-environment "Japanese") | |
;;------------------------------------------------------------ | |
;; Dired settings | |
;;------------------------------------------------------------ | |
;; Setting for dired | |
(add-hook 'dired-load-hook | |
'(lambda () | |
(load-library "ls-lisp") | |
(setq ls-lisp-dirs-first t) ; Display directories first | |
(setq dired-listing-switches "-alG") | |
(setq find-ls-option '("-exec ls -AFGl {} \\;" . "-AFGl")) | |
(setq grep-find-command "find . -type f -print0 | xargs -0 -e grep -ns ") | |
(require 'wdired) | |
)) | |
;; 'r' to enter wdired | |
;; 'C-c C-c' to save the change | |
;; 'C-c ESC' to abort change | |
(add-hook 'dired-mode-hook | |
(lambda () | |
(define-key dired-mode-map "r" 'wdired-change-to-wdired-mode))) | |
;; 'E' to launch windows - explorer | |
(add-hook 'dired-mode-hook | |
(lambda () | |
(local-set-key "E" 'dired-exec-explorer))) | |
(defun dired-exec-explorer () | |
"In dired, execute Explorer" | |
(interactive) | |
(let (path) | |
(setq path (dired-file-name-at-point)) | |
(setq path (replace-regexp-in-string "~" "c:/home" path)) | |
(setq path (replace-regexp-in-string "/" "\\\\" path)) | |
(message path) | |
;(kill-new path) | |
(start-process "explorer" nil "explorer" (concat "/select," path)) | |
) | |
) | |
;; 'z' to copy file path to kill-buffer | |
(add-hook 'dired-mode-hook | |
(lambda () | |
(local-set-key "z" 'dired-copy-path))) | |
(defun dired-copy-path () | |
"In dired, copy file path to kill-buffer. At 2nd time it copy current directory to kill-buffer." | |
(interactive) | |
(let (path) | |
(setq path (dired-file-name-at-point)) | |
(if (string= path (current-kill 0 1)) (setq path (dired-current-directory))) | |
(message path) | |
(kill-new path) | |
) | |
) | |
;; 'b' to make a backup of file | |
(add-hook 'dired-mode-hook | |
(lambda () | |
(local-set-key "b" 'dired-backup-file))) | |
(defun dired-backup-file () | |
"In dired, make a backup file" | |
(interactive) | |
(let (from to) | |
(setq from (dired-file-name-at-point)) | |
(setq to (read-string "backup: filename" from)) | |
(message to) | |
(dired-copy-file from to nil) | |
(revert-buffer) | |
) | |
) | |
;; ############################################################## | |
;; # "*..*"の形式の名前を持つバッファを削除する, except *shell* | |
;; ############################################################## | |
(defun hi-kill-junk-buffer() | |
"Kill all junk buffer which name is \*.*\*" | |
(interactive) | |
(save-excursion | |
(let ((blist (buffer-list)) b_obj b_name) ; 全バッファリスト | |
(while blist | |
(setq b_obj (car blist)) | |
(setq b_name (buffer-name b_obj)) | |
(if (and (string-match "\*.*\*" b_name) (not (string-equal "*shell*" b_name))) ; バッファ名が"*...*"の形式かチェック | |
(kill-buffer b_obj)) | |
(setq blist (cdr blist)))))) | |
(global-set-key "\M-k" 'hi-kill-junk-buffer) | |
;; ############################################################## | |
;; # 現在カーソルのある行をウィンドウのトップに持ってくる | |
;; ############################################################## | |
(defun hi-top-line () | |
"Scroll window to be cursor to top line." | |
(interactive) | |
(save-excursion | |
(save-restriction | |
(scroll-up (1- (hi-what-line-in-window))) | |
))) | |
(global-set-key "\M-t" 'hi-top-line) | |
;; ############################################################## | |
;; # 現在のカーソル位置がウィンドウのトップから何行目かを求める | |
;; ############################################################## | |
(defun hi-what-line-in-window () | |
"Get current line number of a point in the window." | |
(let ((opoint (point)) start) | |
(save-excursion | |
(save-restriction | |
(move-to-window-line 0) ; ウィンドウ内のトップ行の先頭に移動し、 | |
(beginning-of-line) | |
(setq start (point)) ; そのポイント位置をstartに保存 | |
(goto-char opoint) ; 元ポイントがいた行の先頭に移動 | |
(beginning-of-line) | |
(1+ (count-lines start (point))) | |
)))) | |
;;------------------------------------------------------------ | |
;; shell-toggle | |
;;------------------------------------------------------------ | |
(autoload 'shell-toggle "shell-toggle" | |
"Toggles between the *shell* buffer and whatever buffer you are editing." | |
t) | |
(autoload 'shell-toggle-cd "shell-toggle" | |
"Pops up a shell-buffer and insert a \"cd \" command." t) | |
(global-set-key [C-f1] 'shell-toggle-cd) | |
;;------------------------------------------------------------ | |
;; Custom | |
;;------------------------------------------------------------ | |
(custom-set-variables | |
;; custom-set-variables was added by Custom. | |
;; If you edit it by hand, you could mess it up, so be careful. | |
;; Your init file should contain only one such instance. | |
;; If there is more than one, they won't work right. | |
'(session-use-package t nil (session)) | |
'(tab-width 4) | |
'(truncate-lines t)) | |
(custom-set-faces | |
;; custom-set-faces was added by Custom. | |
;; If you edit it by hand, you could mess it up, so be careful. | |
;; Your init file should contain only one such instance. | |
;; If there is more than one, they won't work right. | |
) | |
;;------------------------------------------------------------ | |
;; session.el + minibuf-isearch.el | |
;;------------------------------------------------------------ | |
;; [Ref] http://openlab.dino.co.jp/2008/09/26/230919351.html | |
;; ミニバッファ履歴リストの最大長:tなら無限 | |
(setq history-length t) | |
;; session.el | |
;; kill-ringやミニバッファで過去に開いたファイルなどの履歴を保存する | |
(when (require 'session nil t) | |
(setq session-initialize '(de-saveplace session keys menus places) | |
session-globals-include '((kill-ring 50) | |
(session-file-alist 500 t) | |
(file-name-history 10000))) | |
(add-hook 'after-init-hook 'session-initialize) | |
;; 前回閉じたときの位置にカーソルを復帰 | |
(setq session-undo-check -1)) | |
;; enable isearch in minibuf | |
(require 'minibuf-isearch nil t) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment