xyzzyのsiteinit.l

普段、クライアントとしてはMicrosoft Windows XPを使用している。で、コーディングや長い文章を書くときにはMeadowを使うけれども、ちょっとしたファイルの変更や参照するにはMeadowは起動が遅すぎる。そこで、軽いエディタが必要となる。

Unixをメインに使っていた頃はviがその役割を担っていた。Windowsではxyzzyを使用している。xyzzyの拡張を増やしていくと起動が遅くなってきたので、今は必要ない設定を削るようにしている。今のsiteinit.lをさらしてみる。いくつか、lispを探してこないといけない記述もあります。

これぐらいすれば、Emacs使いでも短時間であればxyzzyを使うことが出来る*1

ポイントは

  • ネットインストーラは要らなくなったので消す
  • ファンクションキーはWindowsに洗脳されたため
  • yank/killはclipbordを使用する
  • grepの結果は、検索して2chに記載されていた
  • comment-regionがxyzzyに無いので代用品を探して使っている
;emacs移植セット
(require "elisp")
;netinstaller
;(require "ni/setup")
;; 自動設定を利用する
;(ni-autoload)
;(setq ni::*http-proxy-host* "proxy.hogehoge.jp")  ; PROXY のホスト
;(setq ni::*http-proxy-port* 8080)          ; PROXY のポート

; ファンクションキー設定
(global-set-key #\F3 #'search-dialog)
(set-function-bar-label #\F3 "search")
(global-set-key #\F4 #'grep-dialog)
(set-function-bar-label #\F4 "Grep")
(global-set-key #\F12 #'list-function)
(set-function-bar-label #\F12 "関数一覧")

; c-mode
(add-hook '*c-mode-hook*
		  '(lambda ()
			(setq *c-indent-tabs-mode* t)
			(setq *c-tab-always-indent* nil)
			(set-tab-columns 4 (selected-buffer))
			(setq c-indent-level 4)
			(setq c-continued-statement-offset 4)
			(setq c-argdecl-indent 0)
			(setq c-brace-offset -4)
			(setq c-brace-imaginary-offset 0)
			(setq c-label-offset 0)
			(setq indent-tabs-mode t)))

(define-key ed::*c-mode-map* #\tab 'self-insert-command)
;インデントの挿入はTABにする
(setq-default indent-tabs-mode t)

; C-w でselectionを切り取り/コピー from winkey.l
(defvar *default-selection-keymap*
  (let ((keymap (make-sparse-keymap)))
    (define-key keymap #\M-w 'copy-selection-to-clipboard)
    (define-key keymap #\C-w 'kill-selection-to-clipboard)
    keymap))
(setq-default selection-keymap *default-selection-keymap*)

; howm
(pushnew (merge-pathnames "site-lisp/howm/" (si:system-root))
		 *load-path* :test #'string-equal)
(require "howm-wrap")
(setq howm-list-all-title t)
(setq howm-menu-refresh-after-save nil)

;grepの結果を別バッファにする from 2ch
(add-hook 'ed::*grep-hook* #'(lambda ()
			       (rename-buffer (if (eq ed::*this-command* 'grep)
						  ed::*last-grep-regexp*
						ed::*last-fgrep-pattern*)
					      (selected-buffer))))
(add-hook 'ed::*grepd-hook* #'(lambda ()
				(rename-buffer (first ed::*minibuffer-search-string-history*)
					       (selected-buffer))))

;; comment-regionの代用
(autoload 'comment-out-region "comment" t nil)
(global-set-key '(#\C-c #\q) 'comment-out-region)

; 以下emacs風設定集+改良型
;(load-library "emacskey")

; key bind
(global-set-key #\C-/ 'undo)
(global-set-key #\M-v 'previous-page)
(global-set-key #\M-% 'replace-string)
(global-set-key #\C-M-% 'replace-regexp)
(global-set-key #\C-M-\\ 'indent-region)
(global-set-key '(#\C-x #\h) 'mark-page)
(global-set-key '(#\C-x #\u) 'undo)
(global-set-key '(#\C-x #\r #\d) 'delete-rectangle)
(global-set-key '(#\C-x #\r #\k) 'kill-rectangle)
(global-set-key '(#\C-x #\r #\o) 'open-rectangle)
(global-set-key '(#\C-x #\r #\t) 'string-rectangle)
(global-set-key '(#\C-x #\r #\y) 'yank-rectangle)
(global-set-key '(#\C-x #\r #\w) 'copy-rectangle)
(global-set-key #\Home 'beginning-of-buffer)
(global-set-key #\End 'end-of-buffer)
(global-set-key #\C-_ 'undo)
(global-set-key #\C-- 'negative-argument)
(global-set-key #\C-\\ 'toggle-ime)
(dolist (c '(#\C-0 #\C-1 #\C-2 #\C-3 #\C-4 #\C-5 #\C-6 #\C-7 #\C-8 #\C-9))
  (global-set-key c 'digit-argument))

; ヤンク、キルにクリップボードを使う。
(global-set-key '(#\C-w) 'kill-region-to-clipboard)
(global-set-key '(#\M-w) 'copy-region-to-clipboard)
(global-set-key '(#\C-y) 'paste-from-clipboard)

; C-xC-bがMeadowと異なるので暫定で対応
(global-set-key '(#\C-x #\C-b) 'select-buffer)

; kill-line-to-clipboard を定義する。
(defun kill-line-to-clipboard (&optional lines)
  (interactive "*p")
  (kill-line lines)
  (copy-to-clipboard (apply #'concat (car ed::*kill-ring*))))
; C-k に割り当て
(global-set-key '(#\C-k) 'kill-line-to-clipboard )

; インクリメンタルサーチ (C-s, C-r)
(require "isearch")

; dynamic abbreviation
(require "dabbrev")
(global-set-key #\M-/ 'dabbrev-expand)

; write-file
; バッファーの名前や割り付けられているファイル名も新しく指定
; されたファイルに変える
(define-key ctl-x-map #\C-w 'emacs-write-file)

; C-x C-v
; 廃棄するバッファのファイル名がミニバッファに表示
(setq *find-other-file-requires-file-name* t)

; sort-lines
(defun sort-lines (start end)
  (interactive "*r")
  (filter-region "sort" start end))

; ウィンドウを左右に分割
(define-key ctl-x-map #\3 'split-window-vertically)

; frame
(global-set-key '(#\C-x #\5 #\o) 'other-pseudo-frame)
(global-set-key '(#\C-x #\5 #\0) 'delete-pseudo-frame)
(global-set-key '(#\C-x #\5 #\2) 'new-pseudo-frame)

; 文字コードの変更
(global-set-key '(#\C-x #\RET #\f) 'change-fileio-encoding)

; M-x で入力したコマンドにショートカットキーがあれば教える
(defun execute-extended-command (command &optional raw arg)
  (interactive "0CM-x: \nP\np")
  (let ((*prefix-args* raw)
	(*prefix-value* arg))
    (setq *last-complex-command* nil)
    (setq *this-command* command)
    (command-execute command (and (interactive-p)
				  (not *executing-macro*)
				  #'ed::record-complex-command))
					;ここから上書き
    (let ((global (command-keys command *global-keymap* nil))
	  (local (command-keys command *global-keymap* (local-keymap)))
	  (minor (command-keys command *global-keymap* (local-keymap) (minor-mode-map))))
      (when minor
	(message "You can run the command '~A' with ~S (~A)"
		 command
		 (key-to-string (car minor))
		 (cond (global "global")
		       (local "local")
		       (t "minor")))
	(sit-for 3)))))

*1:デフォルトのxyzzyEmacsライクではない。