Last active
September 25, 2015 10:18
-
-
Save sonota88/905708 to your computer and use it in GitHub Desktop.
.emacs.el
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
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; OS判別 | |
;; .emacs で OS の判定を関数化しよう - msshの日記 | |
;; http://d.hatena.ne.jp/mssh/20081208/1228742294 | |
;; を少し修正 | |
(defvar os-type nil) | |
(setq os-type (cond | |
((string-match "linux" system-configuration) ;; Linux | |
'linux) | |
((string-match "mingw" system-configuration) ;; Windows | |
'win))) | |
(defun linux? () (eq os-type 'linux)) | |
(defun win? () (eq os-type 'win)) | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; フォント | |
;; (set-frame-font "MS Gothic 10") | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; 基本 | |
(setq initial-scratch-message "") ; scratchバッファの初期メッセージ | |
;;(setq line-number-mode t) ; カーソルのある行番号を表示 | |
(setq-default line-spacing 0) ; 行間 | |
(tool-bar-mode nil) ; ツールバーを表示しない | |
(setq inhibit-startup-message t) ; 起動時にメッセージを出さない | |
(setq default-tab-width 4) ; タブ幅 | |
;; 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) | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; キーバインド | |
(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 | |
;; または <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) | |
;; anything | |
(global-set-key (kbd "C-S-a") 'anything) | |
(global-set-key (kbd "C-a") 'move-beginning-of-line) | |
;; shell-mode のエンコーディングを変更 | |
(cond ((win?) | |
(add-hook | |
'shell-mode-hook | |
'(lambda () | |
(set-buffer-process-coding-system 'sjis 'sjis))))) | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; 色 | |
(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") | |
;; ELispの正規表現をちょっと見やすくする | |
;; http://d.hatena.ne.jp/sonota88/20110111/1294695497 | |
(set-face-foreground 'font-lock-regexp-grouping-backslash "#666") | |
(set-face-foreground 'font-lock-regexp-grouping-construct "#f60") | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; 追加ライブラリ等 | |
;; パスを追加 | |
(add-to-list 'load-path "/home/USER/elisp") | |
;; 行番号表示 | |
(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) | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; 現在の日付と時刻を挿入 | |
(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) | |
;; または、Linux の場合 C-u M-! date RET で。 | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; *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) | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; UbuntuでEmacsのkill-ringとGnomeのクリップボードを同期する | |
;; http://www.honjala.net/user/pyrosuke/log/4700/ | |
(cond (window-system | |
(setq x-select-enable-clipboard t))) | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment