Emacs始めました。。。

頑張ってEmacs始めましたが。。。お仕事で使うPHP-Modeの設定がかなりググッたんですが、
設定してもダメでした。。。

レベルはチュートリアルが終わった程度の腕前です。。。
とりあえず、設定して、使い慣れていきたいんです。

何がダメなのか、どなたかご教授下さい。。。(ToT)
以下.emacs(いっぱいコメントアウトしている内容はとりあえず、削除しました。)

;;;; -*- mode: lisp-interaction; syntax: elisp; coding: iso-2022-7bit -*-
;;;;

;;Windowsだと設定するとWEBの内容コピーすると文字化けしたりするかやめる
(set-language-environment "Japanese")
;(set-default-coding-systems 'utf-8)
;(set-terminal-coding-system 'utf-8)
;(set-keyboard-coding-system 'utf-8)
;;(set-clipboard-coding-system 'utf-8)

(setq inhibit-startup-message t)	; スタートアップメッセージ表示しない
(line-number-mode t)			; 行番号表示

;;; 日本語環境設定
(set-language-environment "Japanese")

;; ;;; カーソルの設定
;; ;; (set-cursor-type 'box)            ; Meadow-1.10互換 (SKK等で色が変る設定)
;; ;; (set-cursor-type 'hairline-caret) ; 縦棒キャレット

;;; マウスカーソルを消す設定
(setq w32-hide-mouse-on-key t)
(setq w32-hide-mouse-timeout 5000)

;リターンを押した時にオートインデントさせる(前の行と同じインデント)。
(global-set-key "\C-m" 'newline-and-indent)
(setq indent-line-function 'indent-relative-maybe)

;C-k だけで行全体を削除。
(setq kill-whole-line t)

;文字列検索時にマッチを強調表示
(setq search-highlight t)

;選択範囲を見えるようにしておく。
(setq transient-mark-mode t)

;;; Redoをつかえるように
(when (require 'redo nil t)
  (define-key ctl-x-map (if window-system "U" "r") 'redo)
  (define-key global-map [?\C-.] 'redo))

;;; font-lockの設定
(global-font-lock-mode t)

;;メイリオフォントを使う
(defun my-set-assoc-data (list key value)
  ;; リストに既に同じキーがあれば上書き、無ければ新規追加
  (let ((item (assoc key (symbol-value list))))
    (if item
 (setcdr item value)
      (add-to-list list (cons key value)))))

(defun my-set-font (ascii-font jis-font size mul)
  ;; フォント設定
  ;; ascii フォント、和文フォント、サイズ、倍率の順に指定する。
  (create-fontset-from-ascii-font
   (concat "-*-" ascii-font "-normal-r-normal-normal-"
    (int-to-string size) "-*-*-*-*-*-iso8859-1")
   nil
   (concat ascii-font (int-to-string size)))
      
  (let* ((encoded (encode-coding-string jis-font 'emacs-mule))
  (family (concat encoded "*"))
  (fontset (concat "fontset-" ascii-font (int-to-string size))))

    (set-fontset-font fontset 'japanese-jisx0208
        (cons family "jisx0208-sjis"))
    (set-fontset-font fontset 'katakana-jisx0201
        (cons family "jisx0201-katakana"))
    
    (my-set-assoc-data 'face-font-rescale-alist (concat ".*" encoded ".*") mul)
    (my-set-assoc-data 'default-frame-alist 'font fontset)
    (set-frame-font fontset)))

;; 倍率は全角と半角の比率を調整する。サイズによって最適値は異なる。
(my-set-font "Consolas" "メイリオ" 12 1.2)
;(my-set-font "Consolas" "メイリオ" 14 1.2)
;(my-set-font "Courier New" "MS ゴシック" 14 1.2)
;(my-set-font "MS ゴシック" "MS ゴシック" 14 1.0)

;;終了時のフレームサイズを記憶する。
(defun my-window-size-save ()
  (let* ((rlist (frame-parameters (selected-frame)))
         (ilist initial-frame-alist)
         (nCHeight (frame-height))
         (nCWidth (frame-width))
         (tMargin (if (integerp (cdr (assoc 'top rlist)))
                      (cdr (assoc 'top rlist)) 0))
         (lMargin (if (integerp (cdr (assoc 'left rlist)))
                      (cdr (assoc 'left rlist)) 0))
         buf
         (file "~/.framesize.el"))
    (if (get-file-buffer (expand-file-name file))
        (setq buf (get-file-buffer (expand-file-name file)))
      (setq buf (find-file-noselect file)))
    (set-buffer buf)
    (erase-buffer)
    (insert (concat
             ;; 初期値をいじるよりも modify-frame-parameters
             ;; で変えるだけの方がいい?
             "(delete 'width initial-frame-alist)\n"
             "(delete 'height initial-frame-alist)\n"
             "(delete 'top initial-frame-alist)\n"
             "(delete 'left initial-frame-alist)\n"
             "(setq initial-frame-alist (append (list\n"
             "'(width . " (int-to-string nCWidth) ")\n"
             "'(height . " (int-to-string nCHeight) ")\n"
             "'(top . " (int-to-string tMargin) ")\n"
             "'(left . " (int-to-string lMargin) "))\n"
             "initial-frame-alist))\n"
             ;;"(setq default-frame-alist initial-frame-alist)"
             ))
    (save-buffer)
    ))

(defun my-window-size-load ()
  (let* ((file "~/.framesize.el"))
    (if (file-exists-p file)
        (load file))))

(my-window-size-load)

;; Call the function above at C-x C-c.
(defadvice save-buffers-kill-emacs
  (before save-frame-size activate)
  (my-window-size-save))

;;スクロールを1行ずつ
(setq scroll-step 1)

;;終了確認をする
(defadvice save-buffers-kill-emacs

  (before safe-save-buffers-kill-emacs activate)

  "safe-save-buffers-kill-emacs"

  (unless (y-or-n-p "Exit Emacs Really?")

    (keyboard-quit)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; tabbar-mode: バッファ上部にタブを表示する
;   
; - 参考ページ 
; -- EmacsWiki - Tab Bar Mode:
;      http://www.emacswiki.org/cgi-bin/wiki/TabBarMode
; -- 見た目の変更 - Amit's Thoughts: Emacs: buffer tabs:
;      http://amitp.blogspot.com/2007/04/emacs-buffer-tabs.html
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; scratch buffer 以外をまとめてタブに表示する
(require 'cl) ; for emacs-22.0.50 on Vine Linux 4.2
 (when (require 'tabbar nil t)
    (setq tabbar-buffer-groups-function
	  (lambda (b) (list "All Buffers")))
    (setq tabbar-buffer-list-function
          (lambda ()
            (remove-if
             (lambda(buffer)
               (find (aref (buffer-name buffer) 0) " *"))
             (buffer-list))))
    (tabbar-mode))

;; Ctrl-Tab, Ctrl-Shift-Tab でタブを切り替える
  (dolist (func '(tabbar-mode tabbar-forward-tab tabbar-forward-group tabbar-backward-tab tabbar-backward-group))
    (autoload func "tabbar" "Tabs at the top of buffers and easy control-tab navigation"))
  (defmacro defun-prefix-alt (name on-no-prefix on-prefix &optional do-always)
    `(defun ,name (arg)
       (interactive "P")
       ,do-always
       (if (equal nil arg)
  	 ,on-no-prefix
         ,on-prefix)))
  (defun-prefix-alt shk-tabbar-next (tabbar-forward-tab) (tabbar-forward-group) (tabbar-mode 1))
  (defun-prefix-alt shk-tabbar-prev (tabbar-backward-tab) (tabbar-backward-group) (tabbar-mode 1))
  (global-set-key [(control tab)] 'shk-tabbar-next)
  (global-set-key [(control shift tab)] 'shk-tabbar-prev)

;; 外観変更
 (set-face-attribute
   'tabbar-default-face nil
   :background "gray60")
  (set-face-attribute
   'tabbar-unselected-face nil
   :background "gray85"
   :foreground "gray30"
   :box nil)
  (set-face-attribute
   'tabbar-selected-face nil
   :background "#f2f2f6"
   :foreground "black"
   :box nil)
  (set-face-attribute
   'tabbar-button-face nil
   :box '(:line-width 1 :color "gray72" :style released-button))
  (set-face-attribute
   'tabbar-separator-face nil
   :height 0.7)

;; F4 で tabbar-mode
(global-set-key [f4] 'tabbar-mode)


;; ---------------------------------------
;; 自動セーブとバックアップファイルを無効にする
(setq make-backup-files nil)
(setq auto-save-default nil)

;;; スクロールバーを右側に表示する
;;(set-scroll-bar-mode 'right)

;; ----------------------------------------
;; 行番号を表示 (wb-line-number.el)

(require 'wb-line-number)
(wb-line-number-toggle)
(custom-set-faces
 '(wb-line-number-face ((t (:foreground "LightGrey"))))
 '(wb-line-number-scroll-bar-face
   ((t (:foreground "white" :background "LightBlue2")))))
(setq truncate-partial-width-windows nil)
(set-scroll-bar-mode nil) ;;初回に表示させると番号の振りがおかしい。。
(setq wb-line-number-scroll-bar t)
(global-set-key [f11] 'wb-line-number-toggle)

;; ---------------------------------------
;; 対応する括弧をハイライト表示
(show-paren-mode)
(setq show-paren-style 'mixed)
(set-face-background 'show-paren-match-face "plum2")
(set-face-foreground 'show-paren-match-face "Blue")

;; ---------------------------------------
;; タブ, 全角スペース、改行直前の半角スペースを表示する
(when (require 'jaspace nil t)
  (when (boundp 'jaspace-modes)
    (setq jaspace-modes (append jaspace-modes
                                (list 'php-mode
                                      'yaml-mode
                                      'javascript-mode
                                      'ruby-mode
                                      'text-mode
                                      'fundamental-mode))))
  (when (boundp 'jaspace-alternate-jaspace-string)
    (setq jaspace-alternate-jaspace-string "□"))
  (when (boundp 'jaspace-highlight-tabs)
    (setq jaspace-highlight-tabs ?^))
  (add-hook 'jaspace-mode-off-hook
            (lambda()
              (when (boundp 'show-trailing-whitespace)
                (setq show-trailing-whitespace nil))))
  (add-hook 'jaspace-mode-hook
            (lambda()
              (progn
                (when (boundp 'show-trailing-whitespace)
                  (setq show-trailing-whitespace t))
                (face-spec-set 'jaspace-highlight-jaspace-face
                               '((((class color) (background light))
                                  (:foreground "blue"))
                                 (t (:foreground "green"))))
                (face-spec-set 'jaspace-highlight-tab-face
                               '((((class color) (background light))
                                  (:foreground "red"
                                   :background "unspecified"
                                   :strike-through nil
                                   :underline t))
                                 (t (:foreground "purple"
                                     :background "unspecified"
                                     :strike-through nil
                                     :underline t))))
                (face-spec-set 'trailing-whitespace
                               '((((class color) (background light))
                                  (:foreground "red"
                                   :background "unspecified"
                                   :strike-through nil
                                   :underline t))
                                 (t (:foreground "purple"
                                     :background "unspecified"
                                     :strike-through nil
                                     :underline t))))))))

;; --------------------------------------
;; カラーテーマの読み込み
(require 'color-theme)
(color-theme-initialize)
(color-theme-dark-blue2)

;;php-modeの設定
(autoload 'php-mode "php-mode")
(setq auto-mode-alist
      (cons '("\\.php\\'" . php-mode) auto-mode-alist))
(setq php-mode-force-pear t)
(add-hook 'php-mode-user-hook
  '(lambda ()
     (define-key php-mode-map "\C-j" 'php-complete-function)
     (setq tab-width 4)
     (setq c-basic-offset 4)
     (setq php-manual-path "C:/Emacs/etc/php_manual_ja/html")
     (setq php-manual-url "http://www.phppro.jp/phpmanual/")
     (setq tags-file-name "C:/Emacs/etc/phpetags/TAGS")))

;;css-modeの設定
(autoload 'css-mode "css-mode")
(setq auto-mode-alist
      (cons '("\\.css\\'" . css-mode) auto-mode-alist))
(setq cssm-indent-function #'cssm-c-style-indenter)

;;java-script-modeの設定
(add-to-list 'auto-mode-alist (cons "\\.js\\'" 'javascript-mode))
(autoload 'javascript-mode "javascript" nil t)
(setq js-indent-level 4)

;;html-mode
(autoload 'html-helper-mode "html-helper-mode" "Yay HTML" t)
(setq auto-mode-alist (cons '("\\.html$" . html-helper-mode) auto-mode-alist))
(setq auto-mode-alist (cons '("\\.tpl$" . html-helper-mode) auto-mode-alist))

;; flymake (Emacs22から標準添付されている)
(when (require 'flymake nil t)
  (global-set-key "\C-cd" 'flymake-display-err-menu-for-current-line)
  ;; PHP用設定
  (when (not (fboundp 'flymake-php-init))
    ;; flymake-php-initが未定義のバージョンだったら、自分で定義する
    (defun flymake-php-init ()
      (let* ((temp-file   (flymake-init-create-temp-buffer-copy
                           'flymake-create-temp-inplace))
             (local-file  (file-relative-name
                           temp-file
                           (file-name-directory buffer-file-name))))
        (list "php" (list "-f" local-file "-l"))))
    (setq flymake-allowed-file-name-masks
          (append
           flymake-allowed-file-name-masks
           '(("\\.php[345]?$" flymake-php-init))))
    (setq flymake-err-line-patterns
          (cons
           '("\\(\\(?:Parse error\\|Fatal error\\|Warning\\): .*\\) in \\(.*\\) on line \\([0-9]+\\)" 2 3 nil 1)
           flymake-err-line-patterns)))
  ;; JavaScript用設定
  (when (not (fboundp 'flymake-javascript-init))
    ;; flymake-javascript-initが未定義のバージョンだったら、自分で定義する
    (defun flymake-javascript-init ()
      (let* ((temp-file (flymake-init-create-temp-buffer-copy
                         'flymake-create-temp-inplace))
             (local-file (file-relative-name
                          temp-file
                          (file-name-directory buffer-file-name))))
        ;;(list "js" (list "-s" local-file))
        (list "jsl" (list "-process" local-file))
        ))
    (setq flymake-allowed-file-name-masks
          (append
           flymake-allowed-file-name-masks
           '(("\\.json$" flymake-javascript-init)
             ("\\.js$" flymake-javascript-init))))
    (setq flymake-err-line-patterns
          (cons
           '("\\(.+\\)(\\([0-9]+\\)): \\(?:lint \\)?\\(\\(?:warning\\|SyntaxError\\):.+\\)" 1 2 nil 3)
           flymake-err-line-patterns)))
  (add-hook 'php-mode-hook
            '(lambda() (flymake-mode t)))
  (add-hook 'javascript-mode-hook
            '(lambda() (flymake-mode t))))

;; mmm-mode
(require 'mmm-auto)
(setq mmm-global-mode 'maybe)
(setq mmm-submode-decoration-level 2)

;(set-face-background 'mmm-default-submode-face nil) ;背景色が不要な場合

(mmm-add-classes
'((embedded-css
:submode css-mode
:front "]*>"
:back "")))
(mmm-add-mode-ext-class nil "\\.html\\'" 'embedded-css)

;; smarty-mode
(add-to-list 'auto-mode-alist (cons "\\.tpl\\'" 'smarty-mode))
(autoload 'smarty-mode "smarty-mode" "Smarty Mode" t)
(mmm-add-mode-ext-class nil "\\.html\\'" 'html-script)
(mmm-add-mode-ext-class nil "\\.tpl\\'" 'embedded-css)
(mmm-add-mode-ext-class nil "\\.tpl\\'" 'html-script)

;;;
;;; end of file
;;;