Skip to content

Instantly share code, notes, and snippets.

@t-mat
Created December 14, 2011 22:26
Show Gist options
  • Save t-mat/1478850 to your computer and use it in GitHub Desktop.
Save t-mat/1478850 to your computer and use it in GitHub Desktop.
my dot emacs
;; https://gist.github.com/1478850
;; GNU Emacs 23.3.1 (x86_64-apple-darwin11.2.0, NS apple-appkit-1138.23)
;;
;; Kotoeri Shortcut plist
;; /System/Library/Input Methods/Kotoeri.app/Contents/Resources/Menu.plist
; 言語を日本語にする
(set-language-environment 'Japanese)
; UTF-8をできるだけ使う
(prefer-coding-system 'utf-8)
; commandキーとoptionキーの動作を逆にする
(setq ns-command-modifier (quote meta))
(setq ns-alternate-modifier (quote super))
; DnD でファイルを開く
(define-key global-map [ns-drag-file] 'ns-find-file)
; ファイル名が重複していたらディレクトリ名を追加する
(require 'uniquify)
(setq uniquify-buffer-name-style 'post-forward-angle-brackets)
; UI
(menu-bar-mode -1) ;; メニューバー無し
(tool-bar-mode -1) ;; ツールバー無し
(auto-image-file-mode t) ;; 画像ファイルをバッファ内に表示
; paren
(show-paren-mode 1) ;; 対応括弧強調
(setq show-paren-delay 0) ;; ディレイ無し
(setq show-paren-style 'mixed)
(setq-default show-trailing-whitespace t) ;; 行末の空白を強調表示
; 折り返しをしない
(setq-default truncate-lines t)
(setq-default truncate-partial-width-windows t)
; 同一のウィンドウで新しいファイルを開く
(setq ns-pop-up-frames nil)
; backup ファイルを ~/.emacs.d/backup 以下に保存する
; ** 動いてない **
(setq make-backup-files t)
(setq backup-directory-alist
(cons (cons "¥¥.*$" (expand-file-name "~/.backup/")) backup-directory-alist))
(setq version-control t)
(setq kept-new-versions 5)
(setq kept-old-versions 5)
(setq delete-old-versions 5)
(setq vc-make-backup-files t)
(setq truncate-lines nil)
(setq-default truncate-lines nil)
(setq truncate-partial-width-windows nil)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; http://www.bookshelf.jp/2ch/unix/1001393679.html
(defun sane-next-line (arg)
"Goto next line by ARG steps with scrolling sanely if needed"
(interactive "p")
(let ((newpt (save-excursion (line-move arg) (point))))
(while (null (pos-visible-in-window-p newpt))
(if (< arg 0) (scroll-down 1) (scroll-up 1)))
(goto-char newpt)
(setq this-command 'next-line) ()))
(defun sane-previous-line (arg)
"Goto previous line by ARG steps with scrolling back sanely if needed."
(interactive "p")
(sane-next-line (- arg))
(setq this-command 'previous-line) ())
; smooth scroll
; http://www.emacswiki.org/emacs/SmoothScrolling
(setq scroll-step 1)
(setq scroll-conservatively most-positive-fixnum)
(setq scroll-margin 2)
(setq scroll-preserve-screen-position t)
(setq auto-window-vscroll t)
; (setq mouse-wheel-scroll-amount '(0.02))
; (setq mouse-wheel-progressive-speed nil)
; (setq mouse-wheel-follow-mouse 't)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; smooth scroll
;; http://www.emacswiki.org/emacs/smooth-scroll.el
;;(add-to-list 'load-path "~/.emacs.d/smooth-scroll/")
;;(when (require 'smooth-scroll nil t)
;; (smooth-scroll-mode t))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; undo tree
;; http://what-linux.seesaa.net/article/158676846.html
;; git://gist.github.com/301447.git
(add-to-list 'load-path "~/.emacs.d/undo-tree/")
(when (require 'undo-tree nil t)
(global-undo-tree-mode))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; auto complete
;; http://cx4a.org/software/auto-complete/index.ja.html
(add-to-list 'load-path "~/.emacs.d/")
(require 'auto-complete-config)
(add-to-list 'ac-dictionary-directories "~/.emacs.d/ac-dict")
(ac-config-default)
;;
(setq completion-ignore-case t) ;;補完時に大文字小文字の区別をしない
(setq read-file-name-completion-ignore-case t) ;; read-file 時の補完で大文字小文字の区別をしない
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; dired
(require 'dired-x)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun my-back-window () (interactive) (other-window -1))
(defun my-load-init-el-file () (interactive) (load-file "~/.emacs.d/init.el"))
(defun my-open-init-el-file () (interactive) (progn (find-file "~/.emacs.d/init.el")))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; frame control
(defun my-get-screen-width-chars () (/ (x-display-pixel-width) (frame-char-width)))
(defun my-get-screen-height-chars () (/ (x-display-pixel-height) (frame-char-height)))
(defun my-get-current-frame-x () (cdr (assoc 'left (frame-parameters))))
(defun my-get-current-frame-y () (cdr (assoc 'top (frame-parameters))))
(defun my-get-current-frame-w () (* (frame-char-width) (frame-width)))
(defun my-get-current-frame-h () (* (frame-char-height) (frame-height)))
(defun my-set-half-frame-width () (interactive) (set-frame-width (selected-frame) (/ (my-get-screen-width-chars) 2)))
(defun my-set-full-frame-width () (interactive) (progn
(set-frame-width (selected-frame) (my-get-screen-width-chars))
(set-frame-position (selected-frame) 0 (my-get-current-frame-y))
))
(defun my-set-half-frame-height () (interactive) (set-frame-height (selected-frame) (/ (my-get-screen-height-chars) 2)))
(defun my-set-full-frame-height () (interactive) (progn
(set-frame-height (selected-frame) (floor (my-get-screen-height-chars)))
(set-frame-position (selected-frame) (my-get-current-frame-x) 0)
))
(defun my-set-full-frame-size () (interactive) (progn
(set-frame-width (selected-frame) (my-get-screen-width-chars))
(set-frame-height (selected-frame) (my-get-screen-height-chars))
(set-frame-position (selected-frame) 0 0)
))
(defun my-frame-snap-to-left-edge () (interactive)
(set-frame-position (selected-frame)
0
(my-get-current-frame-y)))
(defun my-frame-snap-to-right-edge () (interactive)
(set-frame-position (selected-frame)
(- (x-display-pixel-width) (my-get-current-frame-w))
(my-get-current-frame-y)))
(defun my-frame-snap-to-top-edge () (interactive)
(set-frame-position (selected-frame)
(my-get-current-frame-x)
0))
(defun my-frame-snap-to-bottom-edge () (interactive)
(set-frame-position (selected-frame)
(my-get-current-frame-x)
(- (x-display-pixel-height) (my-get-current-frame-h))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;(global-set-key [(down)] 'sane-next-line)
(global-set-key (kbd "C-/") 'undo-tree-undo)
(global-set-key (kbd "M-/") 'undo-tree-redo)
(global-set-key (kbd "M-z") 'undo-tree-undo)
(global-set-key (kbd "C-h") 'backward-delete-char)
(global-set-key (kbd "M-h") 'backward-delete-char)
(global-set-key (kbd "C-0") 'delete-window)
(global-set-key (kbd "C-1") 'delete-other-windows)
(global-set-key (kbd "C-2") 'split-window-vertically)
(global-set-key (kbd "C-3") 'split-window-horizontally)
(global-set-key (kbd "C-o") 'other-window)
(global-set-key (kbd "M-o") 'my-back-window)
(global-set-key (kbd "C-f") 'dabbrev-expand)
(global-set-key (kbd "C-t") 'kill-word)
(global-set-key (kbd "M-d") 'kill-line)
(global-set-key (kbd "C-u") 'yank)
(global-set-key (kbd "C-x ?") 'describe-key-briefly)
(global-set-key (kbd "C-c C-.") 'my-load-init-el-file)
(global-set-key (kbd "C-c C-,") 'my-open-init-el-file)
(global-set-key (kbd "C-,") 'beginning-of-buffer)
(global-set-key (kbd "M-,") 'beginning-of-buffer)
(global-set-key (kbd "C-.") 'end-of-buffer)
(global-set-key (kbd "M-.") 'end-of-buffer)
(global-set-key (kbd "M-v") 'yank)
(global-set-key [(control left)] 'backward-char)
(global-set-key [(control right)] 'forward-char)
(global-set-key [(control up)] 'previous-line)
(global-set-key [(control down)] 'next-line)
(global-set-key [(meta left)] 'previous-buffer)
(global-set-key [(meta right)] 'next-buffer)
(global-set-key (kbd "C-x C-k") 'kill-this-buffer)
(global-set-key (kbd "C-c C-k") 'kill-this-buffer)
(global-set-key (kbd "M-g") 'goto-line)
(global-set-key (kbd "M-r") 'quqery-replace)
(global-set-key (kbd "M-C-r") 'query-replace-regexp)
(global-set-key (kbd "C-S-z") 'my-set-full-frame-size)
(global-set-key (kbd "C-S-x") 'my-set-full-frame-height)
(global-set-key (kbd "C-<") 'my-set-half-frame-height)
(global-set-key (kbd "C->") 'my-set-half-frame-width)
(global-set-key (kbd "C-S-e") 'my-frame-snap-to-right-edge)
(global-set-key (kbd "C-S-a") 'my-frame-snap-to-left-edge)
(global-set-key (kbd "C-S-p") 'my-frame-snap-to-top-edge)
(global-set-key (kbd "C-S-n") 'my-frame-snap-to-bottom-edge)
;; TODO : kill all buffer and hide window
;; TODO : dynamic macro
;; TODO : indent selection
;; TODO : show buffer tab
;; TODO : paren hilighting
;; TODO : rect selection, yank
;; TODO : mode settings ( C, C++, ObjC, Java )
;; TODO : mode line (cursor char, encoding, mode)
;; TODO : right-shift+up,dn -> pgup, pgdn
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq-default cursor-type 'box) ;; cursor type
(global-hl-line-mode 1) ;; hilight cursor line
(global-linum-mode 1) ;; show line number
(setq ring-bell-function 'ignore) ;; do nothing about ring-bell
(set-scroll-bar-mode nil) ;; dont show scroll bar
;;;; mode line
(display-time-mode 0)
(line-number-mode 1)
(column-number-mode 1)
;;;; color
(if window-system (progn
;; 文字の色を設定します。
(add-to-list 'default-frame-alist '(foreground-color . "#ffffff"))
;; 背景色を設定します。
(add-to-list 'default-frame-alist '(background-color . "#000030"))
;; カーソルの色を設定します。
(add-to-list 'default-frame-alist '(cursor-color . "SlateBlue2"))
;; マウスポインタの色を設定します。
(add-to-list 'default-frame-alist '(mouse-color. "SlateBlue2"))
;; モードラインの文字の色を設定します。
(set-face-foreground 'modeline "white")
;; モードラインの背景色を設定します。
(set-face-background 'modeline "SlateBlue2")
;; 選択中のリージョンの色を設定します。
(set-face-background 'region "LightSteelBlue1")
;;モードライン(アクティブでないバッファ)の文字色を設定します。
(set-face-foreground 'mode-line-inactive "gray30")
;; モードライン(アクティブでないバッファ)の背景色を設定します。
(set-face-background 'mode-line-inactive "gray85")
))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; font settings
;; http://d.hatena.ne.jp/setoryohei/20110117/1295336454
;; フォントセットを作る
;; 00112233445566778899001122
;; 0123456789
;; abcdefghijklmnopqrstuvwxyz
;; ABCDEFGHIJKLMNOPQRSTUVWXYZ
;;(setq mac-allow-anti-aliasing t)
(create-fontset-from-ascii-font "Menlo-14:weight=normal:slant=normal" nil "menlokakugo")
(set-fontset-font "fontset-menlokakugo"
'unicode
(font-spec :family "Hiragino Kaku Gorhic ProN" :size 16)
nil
'append)
(add-to-list 'default-frame-alist '(font . "fontset-menlokakugo"))
(setq face-font-rescale-alist '((".*Hiragino.*" . 1.2) (".*Menlo.*" . 1.0)))
;; (let* ((fontset-name "myfonts") ; フォントセットの名前
;; (size 12) ; ASCIIフォントのサイズ [9/10/12/14/15/17/19/20/...]
;; ;; (asciifont "Menlo") ; ASCIIフォント
;; (asciifont "Menlo") ; ASCIIフォント
;; ;; (jpfont "Hiragino Maru Gothic ProN") ; 日本語フォント
;; (jpfont "Hiragino Maru Gothic") ; 日本語フォント
;; ;; (jpfont "Hiragino Kaku Gothic") ; 日本語フォント
;; (font (format "%s-%d:weight=normal:slant=normal" asciifont size))
;; (fontspec (font-spec :family asciifont))
;; (jp-fontspec (font-spec :family jpfont))
;; (fsn (create-fontset-from-ascii-font font nil fontset-name)))
;; (set-fontset-font fsn 'japanese-jisx0213.2004-1 jp-fontspec)
;; (set-fontset-font fsn 'japanese-jisx0213-2 jp-fontspec)
;; (set-fontset-font fsn 'katakana-jisx0201 jp-fontspec) ; 半角カナ
;; (set-fontset-font fsn '(#x0080 . #x024F) fontspec) ; 分音符付きラテン
;; (set-fontset-font fsn '(#x0370 . #x03FF) fontspec) ; ギリシャ文字
;; )
;; デフォルトのフレームパラメータでフォントセットを指定
;; (add-to-list 'default-frame-alist '(font . "fontset-myfonts"))
;; フォントサイズの比を設定
;; (dolist (elt '( ("^-apple-hiragino.*" . 1.2)
;; (".*osaka-bold.*" . 1.2)
;; (".*osaka-medium.*" . 1.2)
;; (".*courier-bold-.*-mac-roman" . 1.0)
;; (".*monaco cy-bold-.*-mac-cyrillic" . 1.0)
;; (".*monaco-bold-.*-mac-roman" . 1.0)))
;; (add-to-list 'face-font-rescale-alist elt))
;; デフォルトフェイスにフォントセットを設定
;; # これは起動時に default-frame-alist に従ったフレームが
;; # 作成されない現象への対処
;; (set-face-font 'default "fontset-myfonts")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment