;; (and (file-readable-p "~/.dotfiles/emacs.el") ;; (load-file "~/.dotfiles/emacs.el")) ;; make directories (unless (file-directory-p (expand-file-name user-emacs-directory)) (make-directory (expand-file-name user-emacs-directory))) (let ((d (expand-file-name (concat user-emacs-directory "lisp")))) (unless (file-directory-p d) (make-directory d)) (add-to-list 'load-path d)) (require 'cl nil t) (progn (defvar buffer-file-changed-functions nil "Hook run when buffer file changed. Each function is called with two args, the filename before changing and after changing.") (declare-function run-buffer-file-changed-functions "emacs.el") (add-hook 'post-command-hook 'run-buffer-file-changed-functions) (lexical-let (previous-file) (defun run-buffer-file-changed-functions () "" (unless (and previous-file (equal previous-file (expand-file-name (or buffer-file-name default-directory)))) (let ((pfile previous-file) (cfile (expand-file-name (or buffer-file-name default-directory)))) (setq previous-file cfile) (run-hook-with-args 'buffer-file-changed-functions pfile cfile))))) ;; (add-hook 'buffer-file-changed-function ;; (lambda (pdir cdir) ;; (message "dir changed %s to %s !" pdir cdir))) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; download library from web (require 'url) (defun dllib-if-unfound (url &optional byte-compile-p force-download-p) "If library does not exist, download it from URL and locate it in \"~/emacs.d/lisp/\". Return nil if library unfound and failed to download, otherwise the path where the library installed." (let* ((dir (expand-file-name (concat user-emacs-directory "lisp/"))) (lib (file-name-sans-extension (file-name-nondirectory url))) (lpath (concat dir lib ".el")) (locate-p (locate-library lib))) (if (or force-download-p (not locate-p)) (progn (condition-case nil (progn (message "downloading %s..." url) (url-copy-file url lpath t) (when (and byte-compile-p (require 'bytecomp nil t)) (and (file-exists-p (byte-compile-dest-file lpath)) (delete-file (byte-compile-dest-file lpath))) (byte-compile-file lpath)) ) (error (and (file-writable-p lpath) (delete-file lpath)) (message "downloading %s...something wrong happened!" url) nil)) (locate-library lib)) locate-p))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; start and quit (setq inhibit-startup-message t) (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))) ;; does not work? ) ;; (add-to-list 'default-frame-alist '(cursor-type . box)) (if window-system (menu-bar-mode 1) (menu-bar-mode 0)) (and (fboundp 'tool-bar-mode) (tool-bar-mode 0)) (and (fboundp 'set-scroll-bar-mode) (set-scroll-bar-mode nil)) (add-hook 'kill-emacs-hook ;; load when exitting to examine if file is written properly (lambda () (when (file-readable-p "~/.emacs") (load-file "~/.emacs")) )) (add-hook 'after-init-hook (lambda () (message "%s was taken to initialize emacs." (emacs-init-time)) (switch-to-buffer "*Messages*") )) (cd ".") ; when using windows use / instead of \ in `default-directory' ;; locale (set-language-environment "Japanese") (set-default-coding-systems 'utf-8-unix) (prefer-coding-system 'utf-8-unix) (setq system-time-locale "C") ;; my prefix map (define-prefix-command 'my-prefix-map) '(add-hook 'after-init-hook (lambda () (define-key ctl-x-map (kbd "C-x") 'my-prefix-map) )) (define-key ctl-x-map (kbd "C-x") 'my-prefix-map) (define-key my-prefix-map (kbd "C-q") 'quoted-insert) (define-key my-prefix-map (kbd "C-z") 'suspend-frame) ;; (comint-show-maximum-output) ;; kill scratch (add-hook 'after-init-hook (lambda () (kill-buffer "*scratch*"))) ;; modifier keys ;; (setq mac-option-modifier 'control) (setq w32-apps-modifier 'meta) ;; display (setq redisplay-dont-pause t) (setq visible-bell t) (setq ring-bell-function 'ignore) (mouse-avoidance-mode 'banish) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; global keys (global-set-key (kbd "") (lambda() (interactive) (scroll-down 1))) (global-set-key (kbd "") (lambda() (interactive) (scroll-up 1))) (global-set-key (kbd "") 'scroll-down) (global-set-key (kbd "") 'scroll-up) (define-key my-prefix-map (kbd "C-o") 'occur) ;; (define-key my-prefix-map (kbd "C-h") help-map) (global-set-key (kbd "C-\\") help-map) (define-key ctl-x-map (kbd "DEL") help-map) (define-key ctl-x-map (kbd "C-h") help-map) (define-key help-map "a" 'apropos) ;; compose window (global-set-key [?\C--] 'other-window) (global-set-key [?\C-0] 'delete-window) (global-set-key [?\C-1] 'delete-other-windows) (global-set-key [?\C-2] 'split-window-vertically) (global-set-key [?\C-3] 'split-window-horizontally) ;; disable annoying keys (global-set-key [prior] 'ignore) (global-set-key (kbd "") 'ignore) (global-set-key [menu] 'ignore) (global-set-key [down-mouse-1] 'ignore) (global-set-key [down-mouse-2] 'ignore) (global-set-key [down-mouse-3] 'ignore) (global-set-key [mouse-1] 'ignore) (global-set-key [mouse-2] 'ignore) (global-set-key [mouse-3] 'ignore) (global-set-key (kbd "") 'ignore) (global-set-key (kbd "C-") 'ignore) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; title and mode-line (setq eol-mnemonic-dos "crlf") (setq eol-mnemonic-mac "cr") (setq eol-mnemonic-unix "lf") (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 () (when display-time-mode (display-time-update)) )) (setq display-time-interval 29) (setq display-time-day-and-date t) (setq display-time-format "%a, %d %b %Y %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)))) ;; ;; display last modified time ;; (let ((ls (member 'mode-line-buffer-identification ;; mode-line-format))) ;; (setcdr ls ;; (cons '(:eval (concat " " ;; my-buffer-file-last-modified-time)) ;; (cdr ls)))) '(setq-default header-line-format (list " " 'display-time-string)) (defvar set-terminal-title-term-regexp "" "Rexexp for `set-terminal-title'.") (setq set-terminal-title-term-regexp "^\\(rxvt\\|xterm\\|aterm$\\|screen\\)") (defun set-terminal-title (&rest args) "" (interactive "sString to set as title: ") (let ((tty (frame-parameter nil 'tty-type))) (when (and tty (string-match set-terminal-title-term-regexp tty)) (send-string-to-terminal (apply 'concat "\033]0;" `(,@args "\007")))))) (defun my-set-terminal-title () "" (set-terminal-title "[" user-login-name "@" system-name ":" (abbreviate-file-name (or buffer-file-name default-directory)) "][" invocation-name " " emacs-version " " (symbol-name system-type) "][" "FRAME:" (frame-parameter nil 'name) ":" (number-to-string (length (buffer-list-not-start-with-space))) "]" )) (add-hook 'buffer-file-changed-functions (lambda (p c) (my-set-terminal-title))) (add-hook 'suspend-resume-hook 'my-set-terminal-title) (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)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; 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) (savehist-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' ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; letters, font-lock mode and fonts ;; (set-face-background 'vertical-border (face-foreground 'mode-line)) (and (or (eq system-type 'Darwin) (eq system-type 'darwin)) (fboundp 'mac-set-input-method-parameter) (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) ; i dont know this is correct (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")))) (show-paren-mode 1) (setq show-paren-delay 0.5 show-paren-style 'parenthesis) ; mixed is hard to read (set-face-background 'show-paren-match (face-foreground 'default)) (set-face-inverse-video-p 'show-paren-match t) (transient-mark-mode 1) (global-font-lock-mode 1) (setq font-lock-global-modes '(not help-mode eshell-mode term-mode Man-mode)) ;; (standard-display-ascii ?\n "$\n") (defvar my-eol-face '(("\n" . (0 font-lock-comment-face t nil))) ) (defvar my-tab-face '(("\t" . '(0 highlight t nil)))) (defvar my-jspace-face '(("\u3000" . '(0 highlight t nil)))) (add-hook 'font-lock-mode-hook (lambda () ;; (font-lock-add-keywords nil my-eol-face) (font-lock-add-keywords nil my-jspace-face) )) (when (require 'whitespace nil t) (setq whitespace-style '(face trailing ; trailing blanks newline ; newlines newline-mark ; use display table for newline empty ; empty lines at beg or end of buffer lines-tail ; lines over 80 )) ;; (setq whitespace-newline 'font-lock-comment-face) (add-to-list 'whitespace-display-mappings `(newline-mark ?\n ,(vconcat "$\n")) ) (global-whitespace-mode t)) (and nil (dllib-if-unfound "http://www.emacswiki.org/emacs/download/fill-column-indicator.el" t) (require 'fill-column-indicator nil t) (setq fill-column-indicator)) ;; highlight current line ;; http://wiki.riywo.com/index.php?Meadow (defface hlline-face '((((type x w32) (class color) (background dark)) (:background "midnightblue")) (((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)) (set-face-foreground 'font-lock-regexp-grouping-backslash "#666") (set-face-foreground 'font-lock-regexp-grouping-construct "#f60") ;; fonts (defun my-set-ascii-and-jp-font (list) "" (if (> emacs-major-version 22) ;; font spec is available in emacs23 and later (progn ; 23 or later (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)))) (progn ; 22 (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.*")) ))) ;; (my-set-ascii-and-jp-font '("dejavu sans mono" 90 "takaogothic" 13)) ;; (my-set-ascii-and-jp-font '("dejavu sans mono" 100 "takaogothic" 14)) ;; (my-set-ascii-and-jp-font '("dejavu sans mono" 100 "ms gothic" 14)) ;; (my-set-ascii-and-jp-font '("monaco" 75 "takaogothic" 11)) ;; (my-set-ascii-and-jp-font '("monaco" 90 "takaogothic" 13)) ;; (my-set-ascii-and-jp-font '("ProggyCleanTTSZ" 120 "takaogothic" 11)) ;; あ a (and (dllib-if-unfound "https://raw.github.com/10sr/emacs-lisp/master/set-modeline-color.el" t) (progn (require 'set-modeline-color nil t))) (let ((fg (face-foreground 'default)) (bg (face-background 'default))) (set-face-background 'mode-line-inactive (if (face-inverse-video-p 'mode-line) fg bg)) (set-face-foreground 'mode-line-inactive (if (face-inverse-video-p 'mode-line) bg fg))) (set-face-underline-p 'mode-line-inactive t) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; file handling (setq revert-without-query '(".+")) ;; save cursor position (setq save-place-file (concat user-emacs-directory "places")) (when (require 'saveplace nil t) (setq-default save-place t)) ;; 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 'never) (setq delete-old-versions t) (setq auto-save-list-file-prefix (expand-file-name "~/.emacs.d/autosave/")) (setq delete-auto-save-files t) (add-to-list 'completion-ignored-extensions ".bak") ;; (setq delete-by-moving-to-trash t ;; trash-directory "~/.emacs.d/trash") (add-hook 'after-save-hook 'executable-make-buffer-file-executable-if-script-p) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; editting (setq require-final-newline t) (setq kill-whole-line t) (setq scroll-conservatively 35 scroll-margin 2 scroll-step 0) (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) ; when using x indicate empty line (setq-default tab-width 4) (setq-default indent-tabs-mode nil) (setq-default indent-line-function nil) ;; (pc-selection-mode 1) ; make some already defined keybind back to default (delete-selection-mode 1) (cua-mode 0) (setq line-move-visual nil) ;; key bindings ;; 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) (define-key esc-map "p" 'backward-paragraph) ;; (global-set-key (kbd "M-n") 'forward-paragraph) (define-key esc-map "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 "