Hatena::Groupnomotivation

Shinnya::Emacs

Shinnya::Emacs

Shinnya::Emacs

右の画像のライセンスGNU General Public License version 3 or later です。


Tips

起動時のメッセージを消す

;; 起動時のメッセージを表示しない
(setq inhibit-startup-message t)

C-hでBackSpaceする

;; C-hでBSする
(global-set-key "\C-h" 'delete-backward-char)

物理行移動を有効にする

;;物理行移動を有効にする
(global-set-key "\C-p" 'previous-window-line)
(global-set-key "\C-n" 'next-window-line)
(global-set-key [up] 'previous-window-line)
(global-set-key [down] 'next-window-line)
(defun previous-window-line (n)
  (interactive "p")
  (let ((cur-col
          (- (current-column)
             (save-excursion (vertical-motion 0) (current-column)))))
    (vertical-motion (- n))
    (move-to-column (+ (current-column) cur-col)))
  (run-hooks 'auto-line-hook)
  )
(defun next-window-line (n)
  (interactive "p")
  (let ((cur-col
          (- (current-column)
             (save-excursion (vertical-motion 0) (current-column)))))
    (vertical-motion n)
    (move-to-column (+ (current-column) cur-col)))
  (run-hooks 'auto-line-hook)
  )

yes noをy nにする

;;yes noをy nにする
(fset 'yes-or-no-p 'y-or-n-p)

補完で大文字小文字を区別しない

;; 補完で大文字小文字を区別しない
(setq completion-ignore-case t)

;; ファイル名補完で大文字小文字を区別しない
(setq read-file-name-completion-ignore-case t)

動的にシンタックスチェックをする

;; 動的にシンタックスチェックをする
(require 'flymake)

カーソルの後ろの単語を大文字にする

;; 後ろの単語を大文字にする
(defun upcase-backward-word (arg)
    "Convert previous word (or arg words) to upper case."
      (interactive "p")
        (upcase-word (- arg)))

C-x % で対応する括弧に飛べるようにする

ファイル後方にしか飛べませんorz

;; C-x % で対応する括弧に飛べるようにする
(progn
  (defvar com-point nil
    "Remember com point as a marker. \(buffer specific\)")
  (set-default 'com-point (make-marker))
  (defun getcom (arg)
    "Get com part of prefix-argument ARG."
    (cond ((null arg) nil)
          ((consp arg) (cdr arg))
          (t nil)))
  (defun paren-match (arg)
    "Go to the matching parenthesis."
    (interactive "P")
    (let ((com (getcom arg)))
      (if (numberp arg)
        (if (or (> arg 99) (< arg 1))
          (error "Prefix must be between 1 and 99.")
          (goto-char
            (if (> (point-max) 80000)
              (* (/ (point-max) 100) arg)
              (/ (* (point-max) arg) 100)))
          (back-to-indentation))
        (cond ((looking-at "[\(\[{]")
               (if com (move-marker com-point (point)))
               (forward-sexp 1)
               (if com
                 (paren-match nil com)
                 (backward-char)))
              ((looking-at "[])]}")
               (forward-char)
               (if com (move-marker com-point (point)))
               (backward-sexp 1)
               (if com (paren-match nil com)))
              (t (error ""))))))
  (define-key ctl-x-map "%" 'paren-match))

shellをzshにする

;; zshを使う
(setq shell-file-name "/bin/zsh")

SKKを使う

;;;SKK_CONFIGURE
(require 'skk-autoloads)
(setq skk-egg-like-newline t)
(define-key global-map (kbd "C-x j") 'skk-mode)
(define-key global-map (kbd "C-x \\") 'skk-mode)
(setq skk-number-style nil)
(global-set-key "\C-x\C-j" 'skk-mode)
(global-set-key "\C-xt" 'skk-tutorial)
(autoload 'skk-mode "skk" nil t)
(autoload 'skk-auto-fill-mode "skk" nil t)
(autoload 'skk-tutorial "skk-tut" nil t)
(autoload 'skk-isearch-mode-setup "skk-isearch" nil t)
(autoload 'skk-isearch-mode-cleanup "skk-isearch" nil t)
(setq skk-tut-file "/usr/share/skk/SKK.tut")
(setq skk-large-jisyo "/usr/share/skk/SKK-JISYO.L")
(add-hook 'isearch-mode-hook
      (function (lambda ()
              (and (boundp 'skk-mode) skk-mode
               (skk-isearch-mode-setup)))))

(add-hook 'isearch-mode-end-hook
      (function
       (lambda ()
         (and (boundp 'skk-mode) skk-mode (skk-isearch-mode-cleanup))
         (and (boundp 'skk-mode-invoked) skk-mode-invoked
          (skk-set-cursor-properly)))))

Dvorak配列を使う

;; Dvrak と qwertyのキーバインドを使い分ける
(defun dvorak ()
  "Dvorak keyboard table"
  (interactive)
  (setq keyboard-translate-table "\C-@\C-a\C-b\C-c\C-d\C-e\C-f\C-g\C-h\C-i\C-j\C-k\C-l\C-m\C-n\C-o\C-p\C-q\C-r\C-s\C-t\C-u\C-v\C-w\C-x\C-y\C-z\033\034\035\036\037 !_#$%&-()*+w`vz0123456789SsW=VZ@AXJE>UIDCHTNMBRL\"POYGK<QF:[\\]^~/axje.uidchtnmbrl'poygk,qf;{?}~?C-?"))
(defun qwerty ()
  "Qwerty keyboard table"
  (interactive)
  (setq keyboard-translate-table nil))
(dvorak)

elisp

install-elisp.el

EmacsWiki: install-elisp.el

;;install-elisp.elを読み込む
(require 'install-elisp)
;;install-elisp.elでインストールされるファイルの保存先を指定
(setq install-elisp-repository-directory "~/.emacs.d/elisp/")

shell-pop.el

EmacsWiki: Shell Pop

;; shell-pop
;; C-ctでshellをポップアップ
(require 'shell-pop)
(shell-pop-set-internal-mode "ansi-term") ;; ansi-termを使うよ
(shell-pop-set-internal-mode-shell "/bin/zsh") ;; zshを使うよ
(defvar ansi-term-after-hook nil)
(add-hook 'ansi-term-after-hook
          '(lambda ()
             (define-key term-raw-map "\C-ct" 'shell-pop)))
(defadvice ansi-term (after ansi-term-after-advice (org))
           "run hook as after advice"
           (run-hooks 'ansi-term-after-hook))
(ad-activate 'ansi-term)
(define-key global-map "\C-ct" 'shell-pop)

elscreen.el

Fragments of Reality - ElScreen

;; elscreen
(load "elscreen" "ElScreen" t)
(setq elscreen-prefix-key "\C-z")
(setq elscreen-display-tab nil)

anything.el, descbinds-anithing.el

EmacsWiki: Anything

;;anything.elの設定
(require 'anything-config)
(setq anything-sources (list anything-c-source-buffers
                             anything-c-source-bookmarks
                             anything-c-source-recentf
                             anything-c-source-file-name-history
                             anything-c-source-locate
                             anything-c-source-man-pages
                             anything-c-source-emacs-commands
                             anything-c-source-files-in-current-dir))
(define-key anything-map (kbd "C-p") 'anything-previous-line)
(define-key anything-map (kbd "C-n") 'anything-next-line)
(define-key anything-map (kbd "C-v") 'anything-next-source)
(define-key anything-map (kbd "M-v") 'anything-previous-source)
(define-key global-map (kbd "C-l") 'anything)
;(define-key global-map (kbd "C-x b") 'iswitchb-buffer)
;(iswitchb-mode)
;(anything-iswitchb-setup)

;; descbinds-anything.elの設定
(require 'descbinds-anything)
(descbinds-anything-install)
(define-key global-map (kbd "C-c C-'") 'describe-bindings)
(define-key global-map (kbd "C-c '") 'describe-bindings)

browse-kill-ring.el

EmacsWiki: Browse Kill Ring

;;browse-kill-ring.el
(require 'browse-kill-ring)
(global-set-key (kbd "C-c k") 'browse-kill-ring)

Scheme-mode

;; Scheme-mode
(setq scheme-program-name "gosh")
(require 'cmuscheme)

(defun scheme-other-window ()
    "Run scheme on other window"
      (interactive)
        (switch-to-buffer-other-window
             (get-buffer-create "*scheme*"))
          (run-scheme scheme-program-name))

(define-key global-map
              "\C-cS" 'scheme-other-window)

Perl-mode

基本設定

;; cperl-modeをperl-modeの代わりに使う
(defalias 'perl-mode 'cperl-mode)

;; indent settings
(setq cperl-indent-level 4
      cperl-continued-statement-offset 4
      cperl-close-paren-offset -4
      cperl-commnet-column 40
      cperl-indent-parens-as-block t
      cperl-tab-always-indent t)

選択リージョンの整形

;; perl tidy:選択したリージョンを一気に整形してくれる
;;
(defun perltidy-region ()
  "Run perltidy on the current region."
  (interactive)
  (save-excursion
    (shell-command-on-region (point) (mark) "perltidy -q" nil t)))
(defun perltidy-defun ()
  "Run perltidy on the current defun."
  (interactive)
  (save-excursion (mark-defun)
          (perltidy-region)))

(defun perltidy-region ()
  "Run perltidy on the current region."
  (interactive)
  (save-excursion
    (shell-command-on-region (point) (mark) "perltidy -q" nil t)))
(defun perltidy-defun ()
  "Run perltidy on the current defun."
  (interactive)
  (save-excursion (mark-defun)
          (perltidy-region)))

スクリプトの実行もしくはsyntax check

;; C-c C-cでスクリプトを実行もしくはsyntax check
;; http://d.hatena.ne.jp/hirose31/20060823/1156331805
(add-hook 'cperl-mode-hook
          '(lambda ()
             (require 'perl-completion)
             (perl-completion-mode t)
             (when (require 'auto-complete nil t)
               (auto-complete-mode t)
               (make-variable-buffer-local 'ac-sources)
               (setq ac-sources
                     '(ac-source-perl-completion)))
             (make-local-variable 'compile-command)
             (setq compile-command
                   (concat "perl " (buffer-file-name)))
             (cperl-define-key "\C-c\C-cc" 'compile)))

リージョン選択して実行

;; emacs上でリージョンを選択して実行する
(defun perl-eval (beg end)
  "Run selected region as Perl code"
  (interactive "r")
  (save-excursion
  (shell-command-on-region beg end "perl"))
)

pod-mode

;; pod-mode
;; http://cpansearch.perl.org/src/SCHWIGON/pod-mode-0.4/pod-mode.el
(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)
            )))

perldocを便利にする

;; M-x perldoc-mで飛べる
;; モジュールソースバッファの場合はその場で、
;; その他のバッファの場合は別ウィンドウに開く。
(put 'perl-module-thing 'end-op
     (lambda ()
       (re-search-forward "\\=[a-zA-Z][a-zA-Z0-9_:]*" nil t)))
(put 'perl-module-thing 'beginning-op
     (lambda ()
       (if (re-search-backward "[^a-zA-Z0-9_:]" nil t)
       (forward-char)
     (goto-char (point-min)))))

(defun perldoc-m ()
  (interactive)
  (let ((module (thing-at-point 'perl-module-thing))
    (pop-up-windows t)
    (cperl-mode-hook nil))
    (when (string= module "")
      (setq module (read-string "Module Name: ")))
    (let ((result (substring (shell-command-to-string (concat "perldoc -m " module)) 0 -1))
      (buffer (get-buffer-create (concat "*Perl " module "*")))
      (pop-or-set-flag (string-match "*Perl " (buffer-name))))
      (if (string-match "No module found for" result)
      (message "%s" result)
    (progn
      (with-current-buffer buffer
        (toggle-read-only -1)
        (erase-buffer)
        (insert result)
        (goto-char (point-min))
        (cperl-mode)
        (toggle-read-only 1)
        )
      (if pop-or-set-flag
          (switch-to-buffer buffer)
        (display-buffer buffer)))))))

@INCに自動でlibを追加する

;; set-perl5lib
;; 開いたスクリプトのパスに応じて、@INCにlibを追加してくれる
;; 以下からダウンロードする必要あり
;; http://svn.coderepos.org/share/lang/elisp/set-perl5lib/set-perl5lib.el
(require 'set-perl5lib)