end0tknr's kipple - web写経開発

太宰府天満宮の狛犬って、妙にカワイイ

emacs 23.2 for windows(NTEmacs in gnupack)なら日本語入力(IME挙動)も問題なし

emacs23がリリースされてから、しばらくたちますが、emacs 23.2 for windows(NTEmacs)のバイナリを見つけたので、installしてみました。www.gnu.orgで公開されているemacs23 for windowsではIME変換時の挙動が不自然と聞いたことがありますが、NTEmacsでは正しく?インラインで変換されるので、NTEmacsを使うのもよいと思います。

NTEmacsはgnupackのprojectから入手

http://gnupack.sourceforge.jp/docs/current/UsersGuide.html
今回、gnupackという解凍してするだけでCygwinと NTEmacsが使えるパッケージの存在をしりました。
gnupackに含まれるntemacsを使用しても構いませんが、私の環境には既にCygwinはinstallされていますし、gnupackのパッケージが100MB程もあるので、次のurlにあるNTEmacsのみを入手しました。

http://gnupack.sourceforge.jp/docs/current/UsersGuide_download.html

installといっても解凍するだけです

ntemacsはinstallと行っても、自己解答形式のファイルを解凍するだけですので、参考までに私の環境の.emacsを記載しておきます。

; -*- Mode: Emacs-Lisp ; Coding: utf-8 -*-

;参考command
;M-x query-replace-regexp		;正規表現による文字列の置換
;M-x replace-regexp			;正規表現による文字列の無条件置換
;M-x set-buffer-file-coding-system	;文字+改行コードの変更
;M-x untabify ,M-x tabify		;タブ->スペース,スペース->タブ
;M-=					;文字数,行数をカウント
;C-x RET c euc-jp-unix C-x C-f		;文字コードを指定してfileを開く
;M-x print-buffer			;バッファの印刷
;M-x upcase-region, M-x downcase-region	;大文字<->小文字
;M-x perltidy-region
;C-/					;undo
;C-.					;バッファをワシワシ切り替え
;M-x japanese-hankaku-region		;全角->半角 変換
;M-/				;動的略語展開
;C-x '				;静的略語展開(define ~/.abbrev_defs)
;M-x kill-rectangle		;矩形でcut
;M-x yank-rectangle		;矩形でpaste
;M-TAB in css-mode		;cssの属性補完
;置換文字列 = C-q C-m(CR), C-q C-j(LF)	;置換文字列に改行コードを使う
;C-x b				;anything
;C-RET				;zencoding
;M-x sort-lines			;sort
;C-u 2 M-x sort-fields		;no2 columnでsort
;M-x se/make-summary-buffer	;medhod一覧表示
;M-x set-variable[RET]tab-width[RET]4[RET] ;tab幅変更
;M-x hs-hide-all , hs-show-all ;関数の折りたたみ. 要 M-x hs-minor-mode

;------------------------------------------------------------------------
(prefer-coding-system 'utf-8-unix)	; 日本語入力のための設定
(setq default-file-name-coding-system 'shift_jis) ;diredで日本語file名出力
(set-default-font "MS ゴシック-10")
;------------------------------------------------------------------------
(setq default-input-method "W32-IME")	;標準IMEの設定
(w32-ime-initialize)			;IMEの初期化
(set-cursor-color "red")		;IME OFF時の初期カーソルカラー
(setq w32-ime-buffer-switch-p nil)	;バッファ切り替え時にIME状態を引き継ぐ

;IME ON/OFF時のカーソルカラー
(add-hook 'input-method-activate-hook
	  (lambda() (set-cursor-color "green")))
(add-hook 'input-method-inactivate-hook
	  (lambda() (set-cursor-color "red")))

;------------------------------------------------------------------------
(setq default-frame-alist
      (append (list
	       '(width . 81)
	       '(height . 53)
	       '(top . 0)
	       '(left . 720))
	      default-frame-alist))
(setq resize-mini-windows t)			;ミニバッファ拡大防止

(show-paren-mode 1)
(setq-default make-backup-files nil)		;BackUp File
(setq auto-save-default nil)			;自動保存
(global-set-key "\C-h" 'backward-delete-char)	;C-h でBackSpace
;(menu-bar-mode t)				;menu bar表示
(tool-bar-mode nil)				;tool bar表示
(setq line-number-mode t)			;行番号表示
(setq column-number-mode 1)			;列番号表示
(put 'downcase-region 'disabled nil)		;小文字化実行時の確認を無効に
(global-set-key "\C-x\C-b" 'bs-show)		;C-xC-bをM-x bs-showに変更
(global-set-key [M-kanji] 'ignore)	;M-kanjiとうるさいので...
(put 'upcase-region 'disabled nil)

;; ------------------------------------------------------------------------
;;keisen.el Shift+矢印で簡単に罫線を描画
(global-set-key [S-right] 'keisen-right-move )
(global-set-key [S-left] 'keisen-left-move )
(global-set-key [S-up] 'keisen-up-move )
(global-set-key [S-down] 'keisen-down-move )

(autoload 'keisen-up-move "keisen" nil t)
(autoload 'keisen-down-move "keisen" nil t)
(autoload 'keisen-left-move "keisen" nil t)
(autoload 'keisen-right-move "keisen" nil t)
;; ------------------------------------------------------------------------
;; programing mode

;;php-mode
;; (load-library "php-mode")
;; ;(require 'php-mode)
;; (setq php-mode-force-pear t)
;; (add-hook 'php-mode-user-hook
;;           '(lambda ()
;;              (c-set-style "stroustrup")
;;              (setq tab-width 4)
;;              (setq c-basic-offset 4)
;;              (setq indent-tabs-mode nil)))

;;cperl-mode
(autoload 'cperl-mode "cperl-mode" "alternate mode for editing Perl programs" t)
(setq auto-mode-alist
      (append '(("\\.\\([pP][Llm]\\|al\\|cgi\\|t\\|psgi\\)$" . cperl-mode))
              auto-mode-alist ))
(add-hook 'cperl-mode-hook
	  (lambda ()
	    (setq cperl-font-lock t)
	    (cperl-set-style "PerlStyle")))
;; M-x hs-hide-all , hs-show-all で関数の折りたたみ
(add-hook 'cperl-mode-hook
          '(lambda()
            (hs-minor-mode 1)))

;元々のperl-modeはcperlへ依存させることで、動作が軽くなります
(defalias 'perl-mode 'cperl-mode)


;;html-helper-mode  tag内のindentがイマイチなので使用中止しました
;(autoload 'html-helper-mode "html-helper-mode" "Yay HTML" t)
;(setq auto-mode-alist (cons '("\\.html$" . html-helper-mode) auto-mode-alist))
;(add-hook 'html-helper-load-hook '(lambda () (require 'html-font)))


;;zencoding-mode それ程、生産性が向上しなかったので、使用中止しました
;(require 'zencoding-mode)
;(add-hook 'sgml-mode-hook 'zencoding-mode)
;(add-hook 'html-mode-hook 'zencoding-mode)

;; css-mode
(autoload 'css-mode "css-mode")
(setq auto-mode-alist (cons '("\\.css$" . css-mode) auto-mode-alist))
(setq cssm-indent-level 4)
(setq cssm-indent-function #'cssm-c-style-indenter) ;インデントをc-styleに

;; js2-mode
(autoload 'js2-mode "js2" nil t)
(add-to-list 'auto-mode-alist '("\\.js$" . js2-mode))

; fixing indentation
; refer to http://mihai.bazon.net/projects/editing-javascript-with-emacs-js2-mode
; emacs 23.2以降では不要かも?
(autoload 'espresso-mode "espresso")

(defun my-js2-indent-function ()
  (interactive)
  (save-restriction
    (widen)
    (let* ((inhibit-point-motion-hooks t)
           (parse-status (save-excursion (syntax-ppss (point-at-bol))))
           (offset (- (current-column) (current-indentation)))
           (indentation (espresso--proper-indentation parse-status))
           node)

      (save-excursion

        ;; I like to indent case and labels to half of the tab width
        (back-to-indentation)
        (if (looking-at "case\\s-")
            (setq indentation (+ indentation (/ espresso-indent-level 2))))

        ;; consecutive declarations in a var statement are nice if
        ;; properly aligned, i.e:
        ;;
        ;; var foo = "bar",
        ;;     bar = "foo";
        (setq node (js2-node-at-point))
        (when (and node
                   (= js2-NAME (js2-node-type node))
                   (= js2-VAR (js2-node-type (js2-node-parent node))))
          (setq indentation (+ 4 indentation))))

      (indent-line-to indentation)
      (when (> offset 0) (forward-char offset)))))

(defun my-indent-sexp ()
  (interactive)
  (save-restriction
    (save-excursion
      (widen)
      (let* ((inhibit-point-motion-hooks t)
             (parse-status (syntax-ppss (point)))
             (beg (nth 1 parse-status))
             (end-marker (make-marker))
             (end (progn (goto-char beg) (forward-list) (point)))
             (ovl (make-overlay beg end)))
        (set-marker end-marker end)
        (overlay-put ovl 'face 'highlight)
        (goto-char beg)
        (while (< (point) (marker-position end-marker))
          ;; don't reindent blank lines so we don't set the "buffer
          ;; modified" property for nothing
          (beginning-of-line)
          (unless (looking-at "\\s-*$")
            (indent-according-to-mode))
          (forward-line))
        (run-with-timer 0.5 nil '(lambda(ovl)
                                   (delete-overlay ovl)) ovl)))))

(defun my-js2-mode-hook ()
  (require 'espresso)
  (setq espresso-indent-level 4
        indent-tabs-mode nil
        c-basic-offset 4)
  (c-toggle-auto-state 0)
  (c-toggle-hungry-state 1)
  (set (make-local-variable 'indent-line-function) 'my-js2-indent-function)
  ; (define-key js2-mode-map [(meta control |)] 'cperl-lineup)
  (define-key js2-mode-map "\C-\M-\\"
    '(lambda()
       (interactive)
       (insert "/* -----[ ")
       (save-excursion
         (insert " ]----- */"))
       ))
  (define-key js2-mode-map "\C-m" 'newline-and-indent)
  ; (define-key js2-mode-map [(backspace)] 'c-electric-backspace)
  ; (define-key js2-mode-map [(control d)] 'c-electric-delete-forward)
  (define-key js2-mode-map "\C-\M-q" 'my-indent-sexp)
  (if (featurep 'js2-highlight-vars)
      (js2-highlight-vars-mode))
  (message "My JS2 hook"))

(add-hook 'js2-mode-hook 'my-js2-mode-hook)
;; (autoload 'js2-mode "js2" nil t)
;; (add-to-list 'auto-mode-alist '("\\.js$" . js2-mode))
;; (add-hook 'js2-mode-hook
;;           '(lambda ()
;;              (setq js2-basic-offset 4)))

;;yaml-mode
(require 'yaml-mode)
(add-to-list 'auto-mode-alist '("\\.\\(yaml\\|yml\\)$" . yaml-mode))

;; vbnet-mode
(autoload 'vbnet-mode "vbnet-mode" "Mode for editing VB.NET code." t)
(setq auto-mode-alist (append '(("\\.\\(frm\\|bas\\|cls\\|vb\\|vbs\\)$" .
				 vbnet-mode)) auto-mode-alist))


;------------------------------------------------------------------------
;;c-modeのコーディングスタイル
;(setq c-default-style "linux")
;;インデントはタブにする
;(setq indent-tabs-mode t)
;;インデント幅
;(setq c-basic-offset 4)
;;タブ幅
;(setq default-tab-width 4)
;(setq tab-width 4)

;------------------------------------------------------------------------
;;; methodLog or prolog mode

(setq-default auto-mode-alist
  (nconc '(
;		   ("\\.pl$" . prolog-mode)
		   ("\\.cs$" . prolog-mode)
;		   ("\\.tbl$" . prolog-mode)
		   )
	 auto-mode-alist))

(add-hook 'prolog-mode-hook
	    '(lambda ()
	       (make-local-variable 'font-lock-syntactic-keywords)
	       (setq font-lock-syntactic-keywords
		     '(("\\$\\([#\"'`$\\]\\)" 1 (1 . nil))
		       ("\\(#\\)[{$@]" 1 (1 . nil))))
	       (make-local-variable 'font-lock-defaults)
	       (setq font-lock-defaults '((prolog-font-lock-keywords) nil nil))
	       (setq font-lock-keywords prolog-font-lock-keywords)))

(defvar prolog-font-lock-keywords
    (list
     (cons (concat
	    "\\(^\\|[^_:.@$]\\|\\.\\.\\)\\b\\("
	    (mapconcat
	     'identity
	     '("class"
	       "be"
	       "endClass"
	       "superClass"
	       "classSlot"
	       "instanceSlot"
	       "fail"
	       "true"
	       "is"
	       "for"
	       "module"
	       "not"
	       "or"
	       "catch"
	       "throw"
	       "super"
	       "there"
	       "upper"
	       "here"
	       )
	     "\\|")
	    "\\)\\>[^_]")
	   2)
     ;; variables
     '("\\b\\(nil\\|self\\)\\b"
       1 font-lock-variable-name-face)
     ;; variables
     '("[$@].\\(\\w\\|_\\)*"
       0 font-lock-variable-name-face)
     ;; constants
     '("\\(^\\|[^_]\\)\\b\\([A-Z]+\\(\\w\\|_\\)*\\)"
       2 font-lock-type-face)
     ;; functions
     '("^\\s *def\\s *\\<\\(\\(\\w\\|_\\)+\\(\\.\\|::\\)\\)?\\(\\(\\w\\|_\\)+\\??\\)\\>"
       4 font-lock-function-name-face t)
     ;; symbols
     '("\\(^\\|[^:]\\)\\(:\\(\\w\\|_\\)+\\??\\)\\b"
       2 font-lock-reference-face))
    "*Additional expressions to highlight in prolog mode.")

;; ------------------------------------------------------------------------
;;全角空白、タブ文字、行末空白の表示
;;   http://homepage1.nifty.com/blankspace/emacs/color.html
(defface my-face-b-1 '((t (:background "bisque"))) nil)
(defface my-face-b-2 '((t (:background "LemonChiffon2"))) nil)
(defface my-face-u-1 '((t (:foreground "SteelBlue" :underline t))) nil)
(defvar my-face-b-1 'my-face-b-1)
(defvar my-face-b-2 'my-face-b-2)
(defvar my-face-u-1 'my-face-u-1)
(defadvice font-lock-mode (before my-font-lock-mode ())
  (font-lock-add-keywords
   major-mode
   '((" " 0 my-face-b-1 append)
     ("\t" 0 my-face-b-2 append)
     ("[ \t]+$" 0 my-face-u-1 append)
     )))
(ad-enable-advice 'font-lock-mode 'before 'my-font-lock-mode)
(ad-activate 'font-lock-mode)

;------------------------------------------------------------------------
;静的略語展開(abbrev)
;(setq abbrev-file-name "c:/home/endo/.abbrev_defs")
;(setq save-abbrevs t)
;(quietly-read-abbrev-file)
(global-set-key "\M-/" 'expand-abbrev)
(eval-after-load "abbrev" '(global-set-key "\M-/" 'expand-abbrev))

;; auto-complete http://code.google.com/p/auto-complete/
(require 'auto-complete)
(require 'auto-complete-config)

;情報源			   ;bufferにある同一modeからsuggest
(setq-default ac-sources '(
			   ac-source-words-in-same-mode-buffers
			   ac-source-abbrev
			   ac-source-dictionary
;			   ac-source-filename	;file name suggest
			   ))
;refer to http://d.hatena.ne.jp/sugyan/20120107
(defvar ac-source-css-property-names
  '((candidates . (loop for property in ac-css-property-alist
                        collect (car property)))))
;css-modeの場合のみ、cssのkey-valueをsuggest
(defun my-css-mode-hook ()
  (add-to-list 'ac-sources 'ac-source-css-property)	   ;cssのkeyのsuggest
  (add-to-list 'ac-sources 'ac-source-css-property-names)) ;cssのvalのsuggest
(add-hook 'css-mode-hook 'my-css-mode-hook)

;auto-completeを使用するmode
(global-auto-complete-mode t)	;←これがtrueの場合、ac-modes の登録要
(setq ac-modes
      (append ac-modes
	      '(cperl-mode html-mode sql-mode vbnet-mode
			   css-mode actionscript-mode)))

(define-key ac-completing-map "\C-n" 'ac-next)
(define-key ac-completing-map "\C-p" 'ac-previous)
(setq ac-ignore-case t) ;大文字・小文字を区別しない

;------------------------------------------------------------------------
;http://ourcomments.org/Emacs/nXhtml/doc/nxhtml.html
;(load "nxhtml/autostart.el")
;------------------------------------------------------------------------
;;auto-install を使用する場合のみコメントを解除しましょう
;(require 'auto-install)
;(setq auto-install-directory "~/.emacs.d/auto-install/")
;(auto-install-update-emacswiki-package-name t)
;(auto-install-compatibility-setup)
;------------------------------------------------------------------------
(require 'anything-config)
(setq anything-sources
      (list
;       anything-c-source-buffers
;       anything-c-source-file-cache
       anything-c-source-file-name-history
;       anything-c-source-files-in-current-dir
       anything-c-source-recentf
;            anything-c-source-info-pages
;            anything-c-source-man-pages
;	    anything-c-source-locate
;            anything-c-source-emacs-commands
;	    anything-c-source-emacs-functions
	    ))
(global-set-key "\C-xb" 'anything)

;------------------------------------------------------------------------
(require 'pod-mode)
(add-to-list 'auto-mode-alist
             '("\\.pod$" . pod-mode))
(add-hook 'pod-mode-hook
          '(lambda () (progn
                        (font-lock-mode)
                        (auto-fill-mode 1)
                        (flyspell-mode 1)
                        )))
;------------------------------------------------------------------------
;; actionscript-mode
 (autoload
  'actionscript-mode "actionscript-mode" "Major mode for actionscript." t)
(add-to-list 'auto-mode-alist '("\\.as$" . actionscript-mode))
;------------------------------------------------------------------------
;; japanese-holidays.el
(require 'calendar)
(setq  number-of-diary-entries 31)
(define-key calendar-mode-map "f" 'calendar-forward-day)
(define-key calendar-mode-map "n" 'calendar-forward-day)
(define-key calendar-mode-map "b" 'calendar-backward-day)
(setq mark-holidays-in-calendar t)
;; (install-elisp "http://www.meadowy.org/meadow/netinstall/export/799/branches/3.00/pkginfo/japanese-holidays/japanese-holidays.el")
(require 'japanese-holidays)
(setq calendar-holidays
      (append japanese-holidays local-holidays other-holidays))
(setq calendar-weekend-marker 'diary)
(add-hook 'today-visible-calendar-hook 'calendar-mark-weekend)
(add-hook 'today-invisible-calendar-hook 'calendar-mark-weekend)

;; http://www.bookshelf.jp/soft/meadow_42.html#SEC641
(autoload 'se/make-summary-buffer "summarye" nil t)

;; http://d.hatena.ne.jp/rubikitch/20091224/recentf
;(require 'recentf-ext)

(when (require 'recentf nil t)
  (setq recentf-max-saved-items 2000)
  (setq recentf-exclude '(".recentf"))
  (setq recentf-auto-cleanup 10)
  (setq recentf-auto-save-timer
        (run-with-idle-timer 30 t 'recentf-save-list))
  (recentf-mode 1))

gnupackに含まれる.emacsも参考になります

gnupackにも.emacsは含まれていますが、font設定や世代管理できるbackup等参考になります。と言いつつ、これらの設定は私の.emacsには記載していません。