macでemacs python環境

Carbon Emacsを入れる

.emacsの一般的な設定

参考 http://blog.s2factory.co.jp/yoshizu/2008/05/carbon-emacs.html

;; ロードパス
(setq load-path (cons "~/emacs/site-lisp" load-path))
(setq load-path (cons "~/emacs/site-lisp/w3m" load-path))

;; 行数表示
(line-number-mode t)

;; スタートアップページを表示しない
(setq inhibit-startup-message t)

;; バックアップファイルを作らない
(setq backup-inhibited t)

;; Macのキーバインドを使う。optionをメタキーにする。
(mac-key-mode 1)
(setq mac-option-modifier 'meta)

;; タブキー
(setq default-tab-width 4)
(setq indent-line-function 'indent-relative-maybe)

;; シフト + 矢印で範囲選択
(setq pc-select-selection-keys-only t)
(pc-selection-mode 1)

;; フォント設定
(if (eq window-system 'mac) (require 'carbon-font))
(fixed-width-set-fontset "hirakaku_w3" 12)
(setq fixed-width-rescale nil)

;; ウィンドウ設定
(if window-system (progn
  (setq initial-frame-alist '((width . 110) (height . 60) (top . 50)))
  (set-background-color "Black")
  (set-foreground-color "LightGray")
  (set-cursor-color "Gray")
  (set-frame-parameter nil 'alpha 80)
))

;; メニューバーを隠す
(tool-bar-mode -1)

ターミナルからemcas起動できるようにする

.bashrcの設定

    alias emacs='/Applications/Emacs.app/Contents/MacOS/Emacs'

.bash_profileの設定
参考 http://memo358.blog18.fc2.com/blog-entry-30.html

if [ -f ~/.bashrc ] ; then
. ~/.bashrc
fi

pythonの設定

ロードパス作成
mkdir -p ~/emacs/site-lisp
mkdir -p ~/emacs/site-lisp/w3m
GAE用にpython2.5のeasy_setupをインストール
sudo port install py25-setuptools
pyhon-modeとauto-completeを取得

ここから、パス確認
https://launchpad.net/python-mode/+download

cd ~/emacs/site-lisp
wget http://launchpadlibrarian.net/61970301/python-mode.el
wget http://www.emacswiki.org/emacs/download/auto-complete.el
.emacsの設定
;; python-mode
(setq auto-mode-alist
      (cons '("\\.py$" . python-mode) auto-mode-alist))
(autoload 'python-mode "python-mode" "Python editing mode." t)

;; auto-complete
(require 'auto-complete)
(global-auto-complete-mode t)
pysmellの設定

pysmellを入れる
補完候補を作成

sudo easy_install pysmell
cd 
pysmell .
cd /opt/local/lib/python2.5/
pysmell . -x site-packages test -o ~/PYSMELLTAGS.stdlib
python-modeでインデントを4つにする
;;python-mode
(add-hook 'python-mode-hook
      '(lambda()
         (setq indent-tabs-mode t)
         (setq indent-level 4)
         (setq python-indent 4)
         (setq tab-width 4))) 
.emacsの設定
;; pysmell
(require 'pysmell)
(add-hook 'python-mode-hook (lambda () (pysmell-mode 1)))

.emacs

最終的にこうなる

;; ロードパス
(setq load-path (cons "~/emacs/site-lisp" load-path))
(setq load-path (cons "~/emacs/site-lisp/w3m" load-path))

;; 行数表示
(line-number-mode t)

;; スタートアップページを表示しない
(setq inhibit-startup-message t)

;; バックアップファイルを作らない
(setq backup-inhibited t)

;; Macのキーバインドを使う。optionをメタキーにする。
(mac-key-mode 1)
(setq mac-option-modifier 'meta)

;; タブキー
(setq default-tab-width 4)
(setq indent-line-function 'indent-relative-maybe)

;; シフト + 矢印で範囲選択
(setq pc-select-selection-keys-only t)
(pc-selection-mode 1)

;; フォント設定
(if (eq window-system 'mac) (require 'carbon-font))
(fixed-width-set-fontset "hirakaku_w3" 12)
(setq fixed-width-rescale nil)

;; ウィンドウ設定
(if window-system (progn
  (setq initial-frame-alist '((width . 110) (height . 60) (top . 50)))
  (set-background-color "Black")
  (set-foreground-color "LightGray")
  (set-cursor-color "Gray")
  (set-frame-parameter nil 'alpha 80)
))

;; ウィンドウを透明化
(add-to-list 'default-frame-alist '(alpha . (0.85 0.85)))

;; python-mode
(setq auto-mode-alist
      (cons '("\\.py$" . python-mode) auto-mode-alist))
(autoload 'python-mode "python-mode" "Python editing mode." t)

;; auto-complete
(require 'auto-complete)
(global-auto-complete-mode t)

;; pysmell
(require 'pysmell)
(add-hook 'python-mode-hook (lambda () (pysmell-mode 1)))

;;python-mode
(add-hook 'python-mode-hook
      '(lambda()
         (setq indent-tabs-mode t)
         (setq indent-level 4)
         (setq python-indent 4)
         (setq tab-width 4)))