;; 外部ファイル読み込み ;; (load-file "~/filepath") ;; (thing-at-point 'word) ;; (define-generic-mode) (unless (file-directory-p (expand-file-name "~/.emacs.d")) (make-directory (expand-file-name "~/.emacs.d"))) (unless (file-directory-p (expand-file-name "~/.emacs.d/lisp")) (make-directory (expand-file-name "~/.emacs.d/lisp"))) (add-to-list 'load-path "~/.emacs.d/lisp") (add-to-list 'load-path "~/dbx/Public/myelisp") (require 'cl) (defvar my-prefix-map (make-sparse-keymap)) (global-set-key (kbd "C-z") my-prefix-map) (define-key my-prefix-map (kbd "C-z") 'suspend-frame) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; start and quit (setq inhibit-startup-message t) (setq frame-title-format (list '(:eval (my-format-time-string)) " | %b " '(:eval (number-to-string (length (buffer-list-not-start-with-space)))) " buffers [" invocation-name " " emacs-version " " (symbol-name system-type) "] " '(:eval (symbol-name last-command)))) (defun buffer-list-not-start-with-space () (let ((bl (buffer-list)) b nbl) (while bl (setq b (pop bl)) (unless (string-equal " " (substring (buffer-name b) 0 1)) (add-to-list 'nbl b))) nbl)) (setq confirm-kill-emacs 'y-or-n-p) (setq gc-cons-threshold (* 1024 1024 4)) (when window-system (add-to-list 'default-frame-alist '(cursor-type . box)) (add-to-list 'default-frame-alist '(background-color . "white")) (add-to-list 'default-frame-alist '(foreground-color . "gray10")) ;; (add-to-list 'default-frame-alist '(alpha . (80 100 100 100))) ;聞いてないみたい ) (if window-system (menu-bar-mode 1) (menu-bar-mode 0)) (tool-bar-mode 0) (set-scroll-bar-mode nil) (add-hook 'kill-emacs-hook ; 終了時に読み込んで壊れてないか調べる (lambda () (when (file-readable-p "~/.emacs") (load-file "~/.emacs")))) (when (eq system-type 'Darwin) (mac-set-input-method-parameter ’japanese ’cursor-color ”red”) (mac-set-input-method-parameter ’roman ’cursor-color ”black”)) (when (and (boundp 'input-method-activate-hook) ;ちょっと正しいかわかんない (boundp 'input-method-inactivate-hook)) (add-hook 'input-method-activate-hook (lambda () (set-cursor-color "red"))) (add-hook 'input-method-inactivate-hook (lambda () (set-cursor-color "black")))) (cd ".") ; when using windows use / instead of \ in default-directory ;; locale (set-language-environment "Japanese") (set-default-coding-systems 'utf-8) (prefer-coding-system 'utf-8) (setq system-time-locale "C") ;; display (setq redisplay-dont-pause t) (setq visible-bell t) (setq ring-bell-function 'ignore) ;; (comint-show-maximum-output) ;; change color for border (set-face-foreground (make-face 'vertical-border-face) "red") (set-display-table-slot standard-display-table 'vertical-border (make-glyph-code #x3a 'vertical-border-face)) ;; kill scratch (add-hook 'after-init-hook (lambda () (kill-buffer "*scratch*"))) (defun my-delete-frame-or-kill-emacs () "delete frame when opening multiple frame, kill emacs when only one." (interactive) (if (eq 1 (length (frame-list))) (save-buffers-kill-emacs) (delete-frame))) (global-set-key (kbd "C-x C-c") 'my-delete-frame-or-kill-emacs) (define-key my-prefix-map (kbd "C-x C-c") 'save-buffers-kill-emacs) ;; modifier keys (setq mac-option-modifier 'control) (setq w32-apps-modifier 'meta) ;; http://www.emacswiki.org/emacs/ChangingCursorDynamically ;; bufferの保存はなんで必要なんだろう? ;; Change cursor color according to mode (defvar hcz-set-cursor-color-color "") (defvar hcz-set-cursor-color-buffer "") (defun hcz-set-cursor-color-according-to-mode () "change cursor color according to some minor modes." ;; set-cursor-color is somewhat costly, so we only call it when needed: (let ((color (if buffer-read-only "blue" (if overwrite-mode "yellow" "black")))) (unless (and (string= color hcz-set-cursor-color-color) (string= (buffer-name) hcz-set-cursor-color-buffer)) (set-cursor-color (setq hcz-set-cursor-color-color color)) (setq hcz-set-cursor-color-buffer (buffer-name))))) (add-hook 'post-command-hook 'hcz-set-cursor-color-according-to-mode) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; minibuffer (setq insert-default-directory t) (setq completion-ignore-case t read-file-name-completion-ignore-case t read-buffer-completion-ignore-case t) (setq resize-mini-window t) (temp-buffer-resize-mode 1) (fset 'yes-or-no-p 'y-or-n-p) (define-key read-expression-map (kbd "TAB") 'lisp-complete-symbol) ; complete symbol when `eval' ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; editting (setq require-final-newline t) (setq kill-whole-line t) (setq scroll-conservatively 35 scroll-margin 2 scroll-step 0) ;4行ずつスクロール? (setq default-major-mode 'text-mode) (setq next-line-add-newlines nil) (setq kill-read-only-ok t) (setq truncate-partial-width-windows nil) ; when splitted horizontally ;; (setq-default line-spacing 0.2) (setq-default indicate-empty-lines t) ; なんだろうこれ (setq-default tab-width 4) (setq-default indent-tabs-mode nil) (pc-selection-mode 1) (delete-selection-mode 1) ;; key bindings (global-set-key (kbd "C-m") 'newline-and-indent) (global-set-key (kbd "C-o") (lambda () (interactive) (goto-char (point-at-eol)) (newline-and-indent))) (global-set-key (kbd "C-k") 'kill-whole-line) (global-set-key (kbd "M-k") 'my-copy-whole-line) ;; (global-set-key "\C-z" 'undo) ; undo is C-/ ;; (global-set-key (kbd "C-") (lambda () (interactive) (insert "\f\n"))) (global-set-key (kbd "M-u") 'undo) (global-set-key (kbd "C-r") 'query-replace-regexp) (global-set-key (kbd "C-s") 'isearch-forward-regexp) (global-set-key (kbd "M-i") (lambda () (interactive) (call-interactively (key-binding (kbd "M-TAB"))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; letters, font-lock mode and fonts (show-paren-mode 1) (setq show-paren-style 'mixed) (transient-mark-mode 1) (global-font-lock-mode 1) (standard-display-ascii ?\n "$\n") (defface my-eol-face '((t (:foreground "gray"))) "eol.") (standard-display-ascii ?\f "---------------------------------------------------------------------------------------^L") (defface my-pagebreak-face '((t (:foreground "gray"))) "pagebreak.") (defvar my-eol-face '(("\n" . '(0 my-eol-face t nil)))) (defvar my-pagebreak-face '(("\f" . 'my-pagebreak-face))) (defvar my-highlight-face '(("\t" . '(0 highlight t nil)) (" " . '(0 highlight t nil)))) ;; (defvar my-face ;; '(("\t" . 'highlight) ;; (" " . 'highlight) ;; ("\n" . '(0 my-eol-face t nil)) ;; ("\f" . 'my-pagebreak-face))) ;; 現在行をハイライト ;; http://wiki.riywo.com/index.php?Meadow (defface hlline-face '((((type x w32) (class color) (background dark)) (:background "midnightblue")) ; :foreground "white")) ;; ハイライトの文字色は変えない方がいいかも (((type x w32) (class color) (background light)) (:background "gainsboro")) (t (:underline "black"))) "*Face used by hl-line.") ;; (defface hlline-ul-face ;; '((t (:underline "yellow"))) ;; "underline yellow") (setq hl-line-face 'hlline-face) ;; (setq hl-line-face nil) (global-hl-line-mode 1) ;; (hl-line-mode 1) (setq hl-line-global-modes '(not term-mode)) (setq font-lock-global-modes '(not help-mode eshell-mode term-mode Man-mode)) (add-hook 'font-lock-mode-hook (lambda () (font-lock-add-keywords nil my-eol-face) (font-lock-add-keywords nil my-highlight-face))) (set-face-foreground 'font-lock-regexp-grouping-backslash "#666") (set-face-foreground 'font-lock-regexp-grouping-construct "#f60") ;; fonts ;; (defun my-w32-set-font () ;; "set font for windows." ;; ((lambda (&rest lists) ;; (let ((dir "c:/WINDOWS/Fonts") ;; lfs) ;; (while lists ;; (setq lfs (pop lists)) ;; (when (directory-files dir nil (car lfs)) ;; (my-set-ascii-and-jp-font-with-size (cdr lfs)) ;; (setq lists nil))))) ;; '("^DejaVuSansMono" "dejavu sans mono" 80 "ms gothic" 12) ;; '("^inconsolata" "inconsolata" 100 "ms gothic" 12))) ;; (defun my-w32-set-available-ascii-and-jp-font-with-size (&rest lists) ;; "" ;; (let ((dir "c:/WINDOWS/Fonts") ;; lfs) ;; (while lists ;; (setq lfs (pop lists)) ;; (when (directory-files dir nil (car lfs)) ;; (my-set-ascii-and-jp-font-with-size (cdr lfs)) ;; (setq lists nil))))) (defun my-set-ascii-and-jp-font-with-size (list) "" (set-face-attribute 'default nil :family (nth 0 list) :height (nth 1 list)) (set-fontset-font "fontset-default" 'japanese-jisx0208 (font-spec :family (nth 2 list) :size (nth 3 list))) (set-fontset-font "fontset-default" 'katakana-jisx0201 (font-spec :family (nth 2 list) :size (nth 3 list)))) ; font spec is available in emacs23 and later, cannot used in emacs22 ;; (my-set-ascii-and-jp-font-with-size '("dejavu sans mono" 90 "takaogothic" 13)) ;; (my-set-ascii-and-jp-font-with-size '("dejavu sans mono" 100 "takaogothic" 14)) ;; (my-set-ascii-and-jp-font-with-size '("monaco" 75 "takaogothic" 11)) ;; (my-set-ascii-and-jp-font-with-size '("monaco" 90 "takaogothic" 13)) ;; (my-set-ascii-and-jp-font-with-size '("ProggyCleanTTSZ" 120 "takaogothic" 11)) ;; あ a (defun my-22-set-ascii-and-jp-font-with-size (list) "" (set-face-attribute 'default nil :family (nth 0 list) :height (nth 1 list)) (set-fontset-font "fontset-default" 'japanese-jisx0208 (cons (nth 2 list) "jisx0208.*")) (set-fontset-font "fontset-default" 'katakana-jisx0201 (cons (nth 2 list) "jisx0201.*"))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; mode-line (which-function-mode 0) (line-number-mode 0) (column-number-mode 0) (size-indication-mode 0) (setq mode-line-position '(:eval (format "L%%l/%d,C%%c" (count-lines (point-max) (point-min))))) ;; http://www.geocities.jp/simizu_daisuke/bunkei-meadow.html#frame-title ;; display date (add-hook 'after-init-hook (lambda () (setq display-time-string-forms '(dayname ", " day " " monthname " " year " " 24-hours ":"minutes ":" seconds)) (setq display-time-string-forms '((my-format-time-string))) (when display-time-mode (display-time-update)) )) (setq display-time-interval 29) (setq display-time-day-and-date t) (if window-system (display-time-mode 0) (display-time-mode 1)) ;; current directory (let ((ls (member 'mode-line-buffer-identification mode-line-format))) (setcdr ls (cons '(:eval (concat " (" (abbreviate-file-name default-directory) ")")) (cdr ls)))) (let ((ls (member 'mode-line-buffer-identification mode-line-format))) (setcdr ls (cons '(:eval (concat " " my-buffer-file-last-modified-time)) (cdr ls)))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; file handling ;; http://www.bookshelf.jp/soft/meadow_24.html#SEC260 (setq make-backup-files t) ;; (make-directory (expand-file-name "~/.emacsbackup")) (setq backup-directory-alist (cons (cons "\\.*$" (expand-file-name "~/.emacs.d/backup")) backup-directory-alist)) (setq version-control t) (setq delete-old-versions t) (setq auto-save-list-file-prefix (expand-file-name "~/.emacs.d/autosave/")) (setq delete-auto-save-files t) (setq delete-by-moving-to-trash t trash-directory "~/.emacs.d/trash") ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; for emacsclient ;; (if window-system (server-start)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; global keys (define-key my-prefix-map (kbd "C-f") 'make-frame-command) (define-key my-prefix-map (kbd "C-o") 'occur) (define-key my-prefix-map (kbd "C-s") (or (require 'multi-term nil t) 'ansi-term)) ;; moving around ;; (global-set-key (kbd "M-j") 'next-line) ;; (global-set-key (kbd "M-k") 'previous-line) ;; (global-set-key (kbd "M-h") 'backward-char) ;; (global-set-key (kbd "M-l") 'forward-char) ;;(keyboard-translate ?\M-j ?\C-j) (global-set-key (kbd "M-p") 'backward-paragraph) (global-set-key (kbd "M-n") 'forward-paragraph) (global-set-key (kbd "C-") (lambda () (interactive)(scroll-down 1))) (global-set-key (kbd "C-") (lambda () (interactive)(scroll-up 1))) (global-set-key (kbd "C-") 'scroll-down) (global-set-key (kbd "C-") 'scroll-up) (global-set-key (kbd "C-x M-x") 'execute-extended-command) (global-set-key (kbd "C-x M-:") 'eval-expression) (global-set-key (kbd "