Last active
February 12, 2017 14:10
-
-
Save sonota88/a04c5e37b390ea3c9a64 to your computer and use it in GitHub Desktop.
Windows7+NTEmacs 2015/04
This file contains hidden or 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
; ################################ | |
; HOME | |
C:\Users\{user} | |
; ################################ | |
; %HOME%/.emacs | |
(add-to-list 'load-path (expand-file-name "~/emacs_d")) | |
(load (expand-file-name "~/emacs_d/__emacs.el")) | |
; ################################ | |
; ~/emacs_d/__emacs.el | |
;; -------------------------------- | |
;; フォント | |
(set-frame-font "MS Gothic 10") | |
;; -------------------------------- | |
;; 基本 | |
(tool-bar-mode 0) ; ツールバーを表示しない(v24) | |
(setq inhibit-startup-message t) ; 起動時にメッセージを出さない | |
(setq default-tab-width 4) ; タブ幅 | |
(setq js-indent-level 2) | |
(setq-default line-spacing 0.2) ; ピクセル or 相対指定 | |
;; 1行ずつスクロールさせる | |
(setq scroll-conservatively 35 | |
scroll-margin 0 | |
scroll-step 1) | |
;; マウスホイールによるスクロール加速を無効に | |
(setq mouse-wheel-progressive-speed nil) | |
;; マウスホイールによるスクロール量を指定 | |
(global-set-key [mouse-4] '(lambda () "" (interactive) (scroll-down 2))) | |
(global-set-key [mouse-5] '(lambda () "" (interactive) (scroll-up 2))) | |
;; または (kbd "<wheel-up>") / (kbd "<wheel-down>") | |
;; ウィンドウタイトルにバッファ名を表示(通常・最小化時) | |
(setq frame-title-format "%b") | |
(setq icon-title-format "%b") | |
;; 整形時にタブではなくスペースを使う | |
(setq-default indent-tabs-mode nil) | |
(fset 'yes-or-no-p 'y-or-n-p) | |
;; ファイル末尾に自動で改行追加 | |
(setq require-final-newline nil) | |
;; 末尾が改行でない場合ユーザに問い合わせ | |
(setq mode-require-final-newline 0) | |
;; -------------------------------- | |
;; キー | |
(global-set-key (kbd "C-h") 'backward-delete-char) | |
;; ウィンドウ切り替え | |
(global-set-key (kbd "C-t") 'other-window) | |
;; C-z のキーバインドを開放 | |
(global-unset-key "\C-z") | |
;; 折り返し | |
(global-set-key (kbd "C-M-y") 'toggle-truncate-lines) | |
;; 自動補完 | |
;; 効かない場合は SCIM の設定を確認 | |
(global-set-key (kbd "S-SPC") 'dabbrev-expand) | |
;; バッファ切り替え | |
;;(define-key global-map (kbd "C-<previous>") 'previous-buffer) ; PageUp | |
(define-key global-map (kbd "C-<prior>") 'previous-buffer) ; PageUp | |
;; または <prior> | |
(define-key global-map (kbd "C-<next>") 'next-buffer) ; PageDown | |
(define-key global-map (kbd "C-.") 'previous-buffer) | |
(define-key global-map (kbd "C-,") 'next-buffer) | |
(global-set-key (kbd "C-S-v") 'scroll-down) ; M-v の代わり | |
(define-key global-map (kbd "M-h") 'backward-kill-word) | |
(define-key global-map (kbd "M-p") 'scroll-down) | |
(define-key global-map (kbd "M-n") 'scroll-up) | |
;; -------------------------------- | |
;; 色 | |
(global-font-lock-mode t) ; 強調表示を有効に | |
(setq default-frame-alist | |
(append (list | |
'(foreground-color . "#FFFFFF") ; 文字 | |
'(background-color . "#282828") ; 背景 | |
'(cursor-color . "#666666")) ; カーソル | |
default-frame-alist)) | |
(add-hook | |
'font-lock-mode-hook | |
'(lambda () | |
(set-face-foreground 'font-lock-builtin-face "spring green") | |
(set-face-foreground 'font-lock-comment-face "#808080") | |
(set-face-foreground 'font-lock-string-face "#44ee66") | |
(set-face-foreground 'font-lock-keyword-face "#ff8800") | |
(set-face-foreground 'font-lock-constant-face "violet") | |
(set-face-foreground 'font-lock-function-name-face "hot pink") | |
(set-face-foreground 'font-lock-variable-name-face "hot pink") | |
(set-face-foreground 'font-lock-type-face "cyan") | |
(set-face-foreground 'font-lock-warning-face "magenta") | |
(set-face-bold-p 'font-lock-function-name-face t) | |
(set-face-bold-p 'font-lock-warning-face nil) | |
)) | |
(transient-mark-mode 1) ; 選択範囲をハイライト | |
(set-face-background 'region "#005566") | |
(show-paren-mode t) ; 対応する括弧をハイライト | |
;; マッチした場合の色 | |
(set-face-background 'show-paren-match-face "#008844") | |
(set-face-foreground 'show-paren-match-face "#ffffff") | |
;; マッチしていない(括弧の対応に不整合がある)場合の色 | |
(set-face-background 'show-paren-mismatch-face "#880000") | |
(set-face-foreground 'show-paren-mismatch-face "#ffff00") | |
;; -------------------------------- | |
;; shell-mode のエンコーディングを変更 | |
(cond ((win?) | |
(add-hook | |
'shell-mode-hook | |
'(lambda () | |
(set-buffer-process-coding-system 'sjis 'sjis))))) | |
;; ---------------- | |
;; 現在の日付と時刻を挿入 | |
(defun insert-current-datetime () | |
"Insert current date and time." | |
(interactive) | |
(insert (format-time-string "%Y-%m-%d %T" (current-time)))) | |
(global-set-key (kbd "C-M-t") 'insert-current-datetime) | |
;; ---------------- | |
;; *shell* バッファで直前に実行したコマンドを実行 | |
;; これとは別に M-x compile / M-x next-error も便利 | |
(defun run-previous-command () | |
"Run the previous command in the *shell* buffer." | |
(interactive) | |
(save-buffer) | |
(with-current-buffer "*shell*" | |
(comint-show-maximum-output) ; プロンプトの位置に移動 | |
(comint-previous-input 1) ; コマンド履歴を1つ遡る | |
(comint-send-input) ; コマンド実行 | |
)) | |
(global-set-key (kbd "C-<f5>") 'run-previous-command) | |
(defun send-string-to-shell-buffer (str) | |
(with-current-buffer "*shell*" | |
(comint-show-maximum-output) | |
(insert str) | |
(comint-send-input))) | |
(defun send-region-to-shell-buffer (begin end) | |
"リージョンを *shell* バッファに送って実行する" | |
;; todo: *shell* バッファの存在チェック | |
(interactive "r") | |
(if mark-active | |
(send-string-to-shell-buffer | |
(buffer-substring begin end)))) | |
(global-set-key (kbd "C-1") 'send-region-to-shell-buffer) | |
;; ---------------- | |
;; transient-mark-mode + リージョン設定 + SPC or S-SPC でインデント増減 | |
;; 「リージョン設定の有無で処理を切り替える」 | |
;; 「バッファに変更を加えてもリージョンが解除されないようにする」 | |
;; のサンプルとしても。 | |
(defun my-space-indent (arg normal-proc) | |
(interactive) | |
(if (and transient-mark-mode mark-active) | |
(save-excursion | |
(let ((deactivate-mark nil)) | |
(if (> (point) (mark)) | |
(exchange-point-and-mark)) | |
(beginning-of-line) | |
(indent-rigidly (region-beginning) (region-end) arg))) | |
(funcall normal-proc))) | |
(global-set-key (kbd "SPC") | |
(lambda () (interactive) | |
(my-space-indent 1 | |
(lambda () (insert " "))))) | |
(global-set-key (kbd "S-SPC") | |
(lambda () (interactive) | |
(my-space-indent -1 | |
(lambda () (dabbrev-expand nil))))) | |
;; ---------------- | |
;; C-<f3> で | |
;; リージョンがアクティブな場合: 選択した文字列(正規表現)をハイライト | |
;; リージョンがアクティブでない場合: ハイライトを取り消し | |
(defface my-temp-highlight-face | |
'((((type x)) | |
(:background "#008" | |
:foreground "#f0f" | |
)) | |
(t (:background "red" | |
:foreground "black"))) | |
nil) | |
(defvar my-temp-highlight-pattern nil) | |
(defun my-temp-highlight () | |
"選択した文字列をハイライト" | |
(interactive) | |
(if mark-active | |
;; 選択範囲の文字列をハイライト | |
(progn | |
(when my-temp-highlight-pattern | |
(unhighlight-regexp my-temp-highlight-pattern)) | |
(setq my-temp-highlight-pattern | |
(buffer-substring (region-beginning) (region-end))) | |
(highlight-regexp my-temp-highlight-pattern | |
'my-temp-highlight-face) | |
(deactivate-mark) | |
) | |
;; ハイライトを解除 | |
(unhighlight-regexp my-temp-highlight-pattern))) | |
(global-set-key (kbd "C-<f3>") 'my-temp-highlight) | |
;; ---------------- | |
;; F9 でメモ用のファイルを開いて日時挿入 | |
(global-set-key | |
(kbd "<f9>") | |
'(lambda () (interactive) | |
(find-file "/path/to/memo.txt") | |
(goto-char (point-min)) | |
(search-forward "\n__BODY__\n") | |
(insert "\n") | |
(insert-current-datetime) | |
(insert "\n\n\n") | |
(backward-char 2))) | |
;; -------------------------------- | |
;; その他 | |
;; 行番号表示 | |
(require 'linum) | |
(global-linum-mode t) | |
;; (setq linum-format "%4d") | |
;; 最近開いたファイルを表示 | |
;; (anything.el でも表示されるようになる) | |
(require 'recentf) | |
(recentf-mode 1) | |
;; ファイルを開いたときに、前回編集した場所に移動 | |
(load "saveplace") | |
(setq-default save-place t) | |
;; カーソル箇所の単語を foo→Foo→FOO→foo とローテーション | |
;; http://www.emacswiki.org/emacs/RotateWordCapitalization | |
(require 'fdlcap) | |
(global-set-key (kbd "M-l") 'fdlcap-change-case-current-word) | |
;; session.el: Session Management for Emacs | |
;; http://emacs-session.sourceforge.net/ | |
;; ミニバッファの履歴(M-x 〜 で使ったもの)を保存 | |
(when (require 'session nil t) | |
(add-hook 'after-init-hook 'session-initialize)) | |
;; EmacsWiki: Toggle Window Split | |
;; http://www.emacswiki.org/emacs/ToggleWindowSplit | |
;; 縦2分割と横2分割を切り替え | |
;; ※本体は割愛 | |
(define-key global-map (kbd "C-x 4") 'toggle-window-split) | |
(require 'undo-tree) | |
(global-undo-tree-mode) | |
(global-set-key (kbd "C-\\") 'undo-tree-redo) | |
(require 'shell-pop) | |
(global-set-key (kbd "<f4>") 'shell-pop) | |
;; ---------------- | |
;; js2-mode | |
(add-to-list 'load-path "C:/Users/{user}/emacs_d/js2_mooz_20140927") | |
;; (autoload 'js2-mode "js2" nil t) | |
(autoload 'js2-mode "js2-mode" nil t) | |
(add-to-list 'auto-mode-alist '("\\.js$" . js2-mode)) | |
(setq js2-basic-offset 2) | |
;; ---------------- | |
;; helm | |
;; auto-complete | |
;; flycheck |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment