August 8, 2010

Carbon Emacsのpython-modeの設定

Carbon Emacsにはデフォルトでpython-mode.elが入ってる。
ただし、設定しないとpython.elのまま。python.elだとバッファ上で実行するから同じフォルダの他のファイルをインポートできない。ちょっと困る。時もある。

以下設定方法。

~/.emacsファイルに次のように記述。
;;; python-mode
(autoload 'python-mode "python-mode" "Python editing mode." t)

以下使い方。python-mode.elより抜粋。後で見やすくする?
;; electric keys
(define-key py-mode-map ":" 'py-electric-colon)
;; indentation level modifiers
(define-key py-mode-map "\C-c\C-l" 'py-shift-region-left)
(define-key py-mode-map "\C-c\C-r" 'py-shift-region-right)
(define-key py-mode-map "\C-c<" 'py-shift-region-left) (define-key py-mode-map "\C-c>" 'py-shift-region-right)
;; subprocess commands
(define-key py-mode-map "\C-c\C-c" 'py-execute-buffer)
(define-key py-mode-map "\C-c\C-m" 'py-execute-import-or-reload)
(define-key py-mode-map "\C-c\C-s" 'py-execute-string)
(define-key py-mode-map "\C-c|" 'py-execute-region)
(define-key py-mode-map "\e\C-x" 'py-execute-def-or-class)
(define-key py-mode-map "\C-c!" 'py-shell)
(define-key py-mode-map "\C-c\C-t" 'py-toggle-shells)
;; Caution! Enter here at your own risk. We are trying to support
;; several behaviors and it gets disgusting. :-( This logic ripped
;; largely from CC Mode.
;;
;; In XEmacs 19, Emacs 19, and Emacs 20, we use this to bind
;; backwards deletion behavior to DEL, which both Delete and
;; Backspace get translated to. There's no way to separate this
;; behavior in a clean way, so deal with it! Besides, it's been
;; this way since the dawn of time.
(if (not (boundp 'delete-key-deletes-forward))
(define-key py-mode-map "\177" 'py-electric-backspace)
;; However, XEmacs 20 actually achieved enlightenment. It is
;; possible to sanely define both backward and forward deletion
;; behavior under X separately (TTYs are forever beyond hope, but
;; who cares? XEmacs 20 does the right thing with these too).
(define-key py-mode-map [delete] 'py-electric-delete)
(define-key py-mode-map [backspace] 'py-electric-backspace))
;; Separate M-BS from C-M-h. The former should remain
;; backward-kill-word.
(define-key py-mode-map [(control meta h)] 'py-mark-def-or-class)
(define-key py-mode-map "\C-c\C-k" 'py-mark-block)
;; Miscellaneous
(define-key py-mode-map "\C-c:" 'py-guess-indent-offset)
(define-key py-mode-map "\C-c\t" 'py-indent-region)
(define-key py-mode-map "\C-c\C-d" 'py-pdbtrack-toggle-stack-tracking)
(define-key py-mode-map "\C-c\C-f" 'py-sort-imports)
(define-key py-mode-map "\C-c\C-n" 'py-next-statement)
(define-key py-mode-map "\C-c\C-p" 'py-previous-statement)
(define-key py-mode-map "\C-c\C-u" 'py-goto-block-up)
(define-key py-mode-map "\C-c#" 'py-comment-region)
(define-key py-mode-map "\C-c?" 'py-describe-mode)
(define-key py-mode-map "\C-c\C-h" 'py-help-at-point)
(define-key py-mode-map "\e\C-a" 'py-beginning-of-def-or-class)
(define-key py-mode-map "\e\C-e" 'py-end-of-def-or-class)
(define-key py-mode-map "\C-c-" 'py-up-exception)
(define-key py-mode-map "\C-c=" 'py-down-exception)
;; stuff that is `standard' but doesn't interface well with
;; python-mode, which forces us to rebind to special commands
(define-key py-mode-map "\C-xnd" 'py-narrow-to-defun)
;; information
(define-key py-mode-map "\C-c\C-b" 'py-submit-bug-report)
(define-key py-mode-map "\C-c\C-v" 'py-version)
(define-key py-mode-map "\C-c\C-w" 'py-pychecker-run)
;; shadow global bindings for newline-and-indent w/ the py- version.
;; BAW - this is extremely bad form, but I'm not going to change it
;; for now.
(mapc #'(lambda (key)
(define-key py-mode-map key 'py-newline-and-indent))
(where-is-internal 'newline-and-indent))
;; Force RET to be py-newline-and-indent even if it didn't get
;; mapped by the above code. motivation: Emacs' default binding for
;; RET is `newline' and C-j is `newline-and-indent'. Most Pythoneers
;; expect RET to do a `py-newline-and-indent' and any Emacsers who
;; dislike this are probably knowledgeable enough to do a rebind.
;; However, we do *not* change C-j since many Emacsers have already
;; swapped RET and C-j and they don't want C-j bound to `newline' to
;; change.
(define-key py-mode-map "\C-m" 'py-newline-and-indent)

No comments:

Post a Comment