;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; CSE環境向けEmacs.appお勧め初期設定
;; Ver. 20170207
;;
;; Copyright Eitetsu Oomoto 2016-2017
;;
;; 対象とするEmacsディストリビューションは以下の3つ
;;    Carbon Emacs
;;           http://th.nao.ac.jp/MEMBER/zenitani/emacs-j.html)
;;    Emacs Mac port
;;           http://www.muskmelon.jp/?page_id=79
;;           http://sakito.jp/emacs/emacs24.html
;;           http://kouzuka.blogspot.jp/2011/03/emacs-mac-port.html
;;    Cocoa Emacs (つまり素のGNU Emacs) 24.5.1
;;           https://www.gnu.org/software/emacs/history.html
;;           http://sakito.jp/emacs/emacs24.html
;;           https://emacsformacosx.com
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;; 実行環境判別用関数の定義 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; define predicates
(defun x->bool (elt) (not (not elt)))

;; emacs-version predicates
(setq emacs22-p (string-match "^22" emacs-version)
      emacs23-p (string-match "^23" emacs-version)
      emacs24-p (string-match "^24" emacs-version)
      emacs25-p (string-match "^25" emacs-version))

;; system-type predicates
(setq carbon-p  (featurep 'carbon-emacs-package) ;; Carbon Emacsの場合
      macport-p (featurep 'mac-win) ;; Emacs Mac portの場合
      ns-p      (featurep 'ns)) ;; Cocoa Emacsの場合


;;;;;;;; ロードパス関連設定 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; load-pathを追加する関数を定義
(when (< emacs-major-version 23) ;; Emacs 23以前のバージョンへの対応
  (defvar user-emacs-directory "~/.emacs.d/"))
;; ロードパス追加関数を定義
 (defun add-to-load-path (&rest paths)
   (let (path)
     (dolist (path paths paths)
      (let ((default-directory (expand-file-name (concat user-emacs-directory path))))
         (add-to-list 'load-path default-directory)
          (if (fboundp 'normal-top-level-add-subdirs-to-load-path)
              (normal-top-level-add-subdirs-to-load-path))))))
;; .emacs.d配下のディレクトリをサブディレクトリごとload-pathに追加
(add-to-load-path "conf" "elisp")

;;;;;;;; Emacsのバージョン・実行環境毎の設定読み込み ;;;;;;;;;;;;;;;;;;;;;
(if window-system
    ;; ウィンドウモードでEmacs.appを起動した場合
    (progn 
      (when carbon-p
        (message "%s" "DEBUG: You are using the Carbon Emacs.")
        (load "init_Carbon.el"))
      (when macport-p
        (message "%s" "DEBUG: You are using the Emacs Mac port.")
        (load "init_CSE.el"))
      (when ns-p
        (message "%s" "DEBUG: You are using the Cocoa Emacs.")
        (load "init_CSE.el")))
  ;; ターミナル上でemacsを起動した場合
  (when emacs22-p
    (message "%s" "DEBUG: You are using the Emacs 22 bundled with Mac OS X.")
    (load "init_Emacs22.el")))


;;;;;;;; 各個人の追加設定はこの行より下に書き込む ;;;;;;;;;;;;;;;;;;;;;;;;
;;(global-linum-mode -1) ;; 漢に行番号といった軟弱なモノは要らぬ!

;;(require 'drill-instructor)       ;; さらに真の漢にはカーソルキーやTABキー
;;(setq drill-instructor-global t)  ;; いや,RETURNキーすら要らぬわ!
;; 出典 https://github.com/k1LoW/emacs-drill-instructor/wiki

;;(when window-system ;; ウィンドウモードで起動した場合
;;  (set-background-color "DarkBlue") ;; 背景色 Darkblue
;;  (set-foreground-color "snow") ;; 前景色 snow
;;  (set-face-attribute 'linum nil
 ;;                      :foreground "yellow" ;; 行番号色 yellow
 ;;                      :height 0.9))
 
 ;;(set-cursor-color "LimeGreen") ;; カーソル色 LimeGreen
 
 ;;(when macport-p
 ;;  ;; 英語モード・日本語モードでカーソル色を変えたくない
 ;;  (remove-hook 'mac-selected-keyboard-input-source-change-hook
 ;;               'mac-selected-keyboard-input-source-change-hook-func))
 
 ;; 起動時にプロ生ちゃんを常に表示
 ;;(setq fancy-splash-image (expand-file-name "~/.emacs.d/conf/EmacsForCSE.png"))
 
 
 ;;;;;;;; 各個人の追加設定はここまで ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
 
 ;; 安全のため,もし設定を何か間違った場合,全ての初期設定を無効化
 (put 'eval-expression 'disabled nil)
 
 ;;;;;;;; End of init.el ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;