siteinit.l & .xyzzy

僕のsiteinit.lと.xyzzyに記述しているlisp群です。見やすいかどうかは怪しいですが、htmlにしてみました。参考になることが少しでもあれば幸いです。プログラムはほとんどWeb上から頂いています。ソースを思い出せるものに関しては横に明記していますが、忘れているものがほとんどです。ほとんどすべてのプログラムは リンクのページからたどれると思うので、そちらを利用してください。順番や分け方は特に工夫していません。ご自分で自由にどうぞ。もちろん、ここに載っているものを使うときは自己責任でお願いします。

Last modified: "2005/09/06 10:33:42 +0900"

以下のように、siteinit.lに書いてあるか.xyzzyに書いてあるかで色分けしています。また、先頭の;;から選択してそのまま貼り付ければインデントはされませんが、そのまま使えるようにはしています。

こちらはsiteinit.l用の色です。
こちらは.xyzzy用の色です。

一応、僕のsiteinit.lと.xyzzyの使い分けはセッティングを頻繁に変えるか否かです。以下コンテンツ。

拡張lisp関連 favorites追加
csv-mode, auto-time-stamp, clickable-url, html+-mode, paren, GnuGo, R-mode, kamail, xml-mode, www-mode, tterm, flex-fill, お隣とdiff, master-mind, outlinex, info, switch-bar, template-insert, favorites
拡張プログラム関連
ispell, diff, browser.dll, ローカルでhtmllint
お好みセッティング関連 セッションファイルの展開をアップデート new! (2004/05/08)
C-aで全て選択, IME情報表示, IMEをC-oで, isearch, 置換, デフォルトのディレクトリ, .xyzzyをlispで, F1でヘルプ, バッファの移動, siteinit.lのバイトコンパイル&ダンプ, Windowの幅を変える, C-xC-wをemacs風に, バックアップを特定のフォルダに, 同じバッファから補完, 最近使ったファイルリスト, 一発でインデント, 文字カウント, C-modeでtab, text-mode, クローズボックス, find-fileの時にディレクトリを作れるように, lisp-modeの色付け, ファイラで全てのファイルを表示, リージョンと選択範囲をトグル, google検索, 折り返し位置の変更
その他へのリンク
Manual of xyzzy

それにしても縦長で見にくくなってきた。手間をかけず、見やすく、活かしやすいようにするにはどうしたらいいのだろう?

拡張lisp関連

;; csv-mode OHKUBOさん: http://members.tripod.co.jp/ohkubo/xyzzy/#csv-mode
(in-package "editor")
(export '(csv-mode tsv-mode))
(autoload 'csv-mode "csv-mode" t)
(autoload 'tsv-mode "csv-mode" t)
(pushnew '("\\.csv$" . csv-mode) *auto-mode-alist* :test 'equal)
(pushnew '("\\.tsv$" . csv-mode) *auto-mode-alist* :test 'equal)
(in-package "user")
;; auto-time-stamp
;; Last modified: "" or <>
(load-library "auto-time-stamp")
(define-key ctl-x-map #\C-s 'save-buffer-with-time-stamp)
;; clickable-url.l
(load-library "clickable-url")
; firefox用設定 (from 質問スレ)
(setq *clickable-url-open-command* "C:/Program Files/Mozilla Firefox/firefox.exe")
;; html+-mode
(in-package "editor")
(export 'html+-mode)
(autoload 'html+-mode "html+-mode" t)
(pushnew '("\\.s?html?$" . html+-mode) *auto-mode-alist* :test 'equal)
(in-package "user")
; 折り返し
(add-hook 'ed::*html+-mode-hook* #'(lambda () (set-buffer-fold-width 100)))
;; paren.l
(require "paren")
(setq *c-mode-hook* '(lambda ()
(setq *paren-highlight-only-paren* t)
(setq *paren-paren-attribute* '(:underline t :bold t))
(turn-on-paren)))
;; GnuGo
(require "gnugo")
;; R-mode
(load-library "R-mode")
(push '("\\.R$" . R-mode) *auto-mode-alist*)
;; popup-completion-list
(setq *popup-completion-list-default* :always)
;; kamail
(autoload 'kamail "kamail/kamail" t)
;; xml-mode
(require "xml-mode")
(use-package 'xml)
(pushnew '("\\.\\(xml\\|xsl\\|svg\\|fo\\|xi\\|rlx\\|sdoc\\)" . xml-mode)
*auto-mode-alist* :test 'equal)
;; www-mode
(autoload 'www "www/www" t) ; 通常起動
(autoload 'www-open-url "www/www" t) ; URLを指定して起動
(autoload 'www-open-local-file "www/www" t) ; ローカルのファイルを指定して開く
(autoload 'www-open-current-buffer "www/www" t) ; 現在のバッファのファイルを開く
;; tterm
(load-library "tterm")
(use-package "tterm")
;; flex-fill
(require "flex-fill")
;; お隣とdiff
(require "diff-buffer")
;; master mind
(load-library "master")
;; outlinex
(load-library "outlinex")
;; info.l
(load-library "info")
;; Switch-bar
(require "switch-bar")
;; Switch-bar with maximize from HIEさん
(require "wip/winapi")
(c:define-dll-entry winapi:BOOL ShowWindow (winapi:HWND c:int) "user32")
;最大化
(defun maximize-xyzzy ()
(interactive)
(ShowWindow (get-window-handle) 3))
;元のサイズに戻す
(defun restore-xyzzy ()
(interactive)
(ShowWindow (get-window-handle) 9))
;トグル
(c:define-dll-entry winapi:BOOL IsZoomed (winapi:HWND) "user32")
(defun toggle-maximize-xyzzy ()
(interactive)
(if (/= 0 (IsZoomed (get-window-handle)))
(restore-xyzzy)
(maximize-xyzzy)))
;; switch-barでトグルする機能の一覧
(setq *switch-function*'
(toggle-ruler
toggle-mode-line
;toggle-function-bar
toggle-line-number
toggle-maximize-xyzzy))
;; template-insert from kiaさん(http://www.geocities.co.jp/SiliconValley-PaloAlto/5042/xyzzy/index.html#template-insert)
;; xyzzy日記(稲原さん: http://web.sfc.keio.ac.jp/~t01089ti/xyzzy.html)に刺激されて。メインのページ、xyzzyのページ、Rのページ用にスタイルシート等が違うので、以下のような設定にしている。ご自分の使いやすいようにtemplate-insert.lを読んで設定してください。
(require "template-insert")
(use-package 'template-insert)
(setq *template-insert-directory* "~/templates/")
(setq *template-insert-alist*
(append '(("D:/WebSite/.*\\.html?" . "website.html")
("D:/WebSite/R/.*\\.html?" . "r.html")
("D:/WebSite/xyzzy/.*\\.html?" . "xyzzy.html"))
*template-insert-alist*))
;; favorites from 山本さん(http://www1.odn.ne.jp/ymtz/favorites.html)
(require "favorites")

拡張プログラム関連

;; ispell
(setq *ispell-command* "C:/soft/xyzzy/ispell/ispell.exe")
;; diff
(setq ed::*diff-command-name* (map-slash-to-backslash
(merge-pathnames "bin/diff.exe" (user-homedir-pathname))))
;; browser.dll
(load-library "browser")
(load-library "browserex")
;; ローカルでhtmllint from 黒い羽根さん(http://www.uranus.dti.ne.jp/~shiro-/soft/xyzzy/html+.html#lint)
(defvar *htmllint-file* "D:/htmllint/htmllint")
(defun htmllint-exec ()
(interactive)
(let ((file (get-buffer-file-name)))
(when file
(pipe-command
(format nil "perl \"~A\" \"~A\""
(map-slash-to-backslash *htmllint-file*)
(map-slash-to-backslash file))))))
(global-set-key #\C-F4 'htmllint-exec)

お好みセッティング関連

;; text-modeではC-aですべて選択する
(define-key *text-mode-map* #\C-a 'selection-whole-buffer)
;; IMEのステータスを表示
(setq-default mode-line-format "--%*- %b (%M) [%k:%l] %P %f [%i]")
;; IMEをC-oでトグル
(global-set-key #\C-o 'toggle-ime)
;; インクリメンタルサーチ
(require "isearch")
;; 確認しながら置換する
(global-set-key #\M-% 'query-replace)
;; デフォルトのフォルダを決める
(set-default-directory "D:/documents/")
;; .xyzzy を lisp-mode で編集する
(pushnew '("\\.xyzzy$" . lisp-mode) *auto-mode-alist*)
;; F1でHTML Helpを開く設定例
;; reference.chm は xyzzy/etc に置く
(defvar *reference-html-help-file* "reference.chm")
(defun reference-show-html-help ()
(interactive)
(ed::html-help (merge-pathnames *reference-html-help-file* (ed::etc-path))
(ed::get-winhelp-topic)))
(define-key ed::*lisp-mode-map* #\F1 'reference-show-html-help)
(define-key ed::*lisp-interaction-mode-map* #\F1 'reference-show-html-help)
;; バッファ移動
(setq *next-buffer-in-tab-order* t) ; バッファ移動をタブ順に
(global-set-key #\M-Right 'next-buffer) ; 前のバッファに移動
(global-set-key #\M-Left 'previous-buffer) ; 後のバッファに移動
;; siteinit.l のバイトコンパイル&ダンプファイルの削除(XP対応)(HIEさん)
(defun compile-and-delete-dump-file ()
(interactive)
(and (find-buffer "siteinit.l")
(eval-buffer "siteinit.l"))
(byte-compile-file
(concat (si:system-root) "site-lisp/siteinit.l"))
(let ((dumpfile
(concat (si:system-root) "xyzzy."
(case (os-platform)
(whistler "wxp")
(windows-2000 "w2k")
(windows-nt "wnt")
(windows-me "wme")
(windows-98 "w98")
(windows-95 "w95")
(win32s "32s")
(t "unknown")))))
(if (string-matchp "xyzzy.unknown" dumpfile)
(message "Distinction of os-platform cannot be performed.")
(and (file-exist-p dumpfile)
(delete-file dumpfile)))))
(global-set-key '(#\C-c #\b) 'compile-and-delete-dump-file)
;; 幅を広めたり(C-c w)、幅を狭めたり(C-c n)
(global-set-key '(#\C-c #\w) 'enlarge-window-horizontally)
(global-set-key '(#\C-c #\n) 'shrink-window-horizontally)
;; C-x C-wでemacs風の処理をさせるには
(defun emacs-write-file (filename)
(interactive "FWrite file: " :title0 "Write File")
(and (rename filename)
(save-buffer)))
(define-key ctl-x-map #\C-w 'emacs-write-file)
;; backup は特定のフォルダに
(require "backup")
(setq *backup-directory* "d:/XyzzyBackup")
(setq *hierarchic-backup-directory* nil)
;; 同じバッファから文字を補完
(require "dabbrev")
(global-set-key #\C-\; 'dabbrev-expand)
;; 最近使ったファイルリスト
(defun list-file ()
(interactive)
(let ((hist (subseq *minibuffer-file-name-history* 0 9)))
(multiple-value-bind (result data)
(dialog-box '(dialog 0 0 262 108
(:caption "File List")
(:font 9 "MS Pゴシック")
(:control
(:listbox files nil #x50b10101 7 7 248 75)
(:button IDOK "OK" #x50010001 148 88 50 14)
(:button IDCANCEL "cancel" #x50010000 205 88 50 14)))
(list (cons 'files hist))
'((files :must-match t :enable (IDOK))))
(when result
(let ((file (cdar data)))
; ファイルを開く
(when (file-exist-p file)
(find-file file)
(add-history file '*minibuffer-file-name-history*)))))))
(global-set-key #\C-/ 'list-file)
;; 一発でインデント
(defun indent-current-buffer ()
(interactive)
(indent-region (point-min) (point-max))
(message "indent buffer"))
(global-set-key #\C-F8 'indent-current-buffer)
;; 文字カウント
(defun count-char-from-point ()
(interactive) (save-excursion
(let ((p1 (point)) (p2 (point-max)))
(setq parcnt
(- (progn (goto-char p2) (current-line-number))
(progn (goto-char p1) (current-line-number))))
(message "~d paragraphs, ~d characters."
parcnt (- p2 p1 parcnt)))))
(global-set-key '(#\C-c #\c) 'count-char-from-point)
;; c-modeでtab入力
(define-key ed::*c-mode-map* #\tab 'self-insert-command)
;; text-mode
(add-hook '*text-mode-hook*
#'(lambda ()
(auto-fill-mode t)
(set-local-window-flags (selected-buffer) *window-flag-cursor-line* t)))
;; クローズボックス(OHKUBOさん: "http://ohkubo.s53.xrea.com/xyzzy/memo.html#miscellaneous")
(add-hook '*init-app-menus-hook*
#'(lambda ()
(add-menu-item *app-menu* 'close-box :close-box
#'kill-selected-buffer)))
;; find-file 時にディレクトリが作れるように
(defun make-directory-unless-directory-exists (filename)
(unless (valid-path-p filename)
(let ((d (directory-namestring filename)))
(when (yes-or-no-p "~a~%ディレクトリがないけど作る?" d)
(create-directory d)))) nil)
; ファイルを開く前に実行
(add-hook '*before-find-file-hook*
#'make-directory-unless-directory-exists)
;; lisp 色付け HIEさん
(in-package "editor")
(defvar *lisp-keyword-hash-table* nil)
(defun use-lisp-keyword ()
"キーワード色付け"
(if (null *lisp-keyword-hash-table*)
(setq *lisp-keyword-hash-table*
(load-keyword-file "lisp")))
(when *lisp-keyword-hash-table*
(make-local-variable 'keyword-hash-table)
(setq keyword-hash-table *lisp-keyword-hash-table*)))
(add-hook '*lisp-mode-hook*
#'(lambda ()
(use-lisp-keyword)
(define-key *lisp-mode-map* #\C-. 'lisp-complete-symbol)))
(add-hook '*lisp-interaction-mode-hook*
#'(lambda ()
(use-lisp-keyword)
(define-key *lisp-interaction-mode-map* #\C-. 'lisp-complete-symbol)))
(in-package "user")
;; filerですべてのファイルを表示 http://www.sc.tutpse.tut.ac.jp/Member/OB/Umeda/fws_tips.html#xyzzy
; 2画面用
(setq *filer-primary-file-mask* '("*"))
(setq *filer-secondary-file-mask* '("*"))
; 1画面用
(setq *filer-last-file-mask* '("*"))
;; リージョンと選択範囲をトグルで変換 from 黒い羽さん
(defun exchange-region-and-selection ()
"リージョンと選択範囲をトグルで変換"
(interactive)
(let (start end)
(case (get-selection-type)
((1 2)
(setq start (selection-mark))
(setq end (selection-point))
(if (> start end)
(rotatef start end))
(stop-selection)
(set-mark start)
(goto-char end))
(3
(error "矩形選択はリージョンに変換できません"))
(t
(if (mark t)
(progn (setq start (mark))
(setq end (point))
(if (> start end)
(rotatef start end))
(start-selection 2 t start)
(goto-char end))
(error "マークがないので選択範囲に変換できません"))))))
(global-set-key '(#\C-c #\s) 'exchange-region-and-selection)
;; google search
(defun search-google-selection ()
(interactive)
(ed::edict-lookup-selection #'search-google))
(defun search-google (from to)
(interactive "r")
(if (= from to)
(progn (message "単語が選択されてない") (return-from search-google nil)))
(long-operation
(let ((str (si:www-url-encode (buffer-substring from to))) url)
(setq url (concat "http://www.google.com/search?q=" str))
;----------------------------------------
; 1. browser.dll & browserex.l を使う場合
;(bx::navigate url :position bx::XPIS_BOTTOM :size 200)
; 2. 標準ブラウザを使う場合
;(shell-execute url t)
; 3. www-mode を使う場合
(www-open-url url)
;----------------------------------------
)))
(global-set-key '(#\C-c #\g) 'search-google-selection)
;; 折り返し位置の変更 from wiki(佐野さんが書いて稲原さんが掲載した模様)
(defun next-buffer-fold-type ()
(interactive)
(case
(cond
((set-buffer-fold-type-none-update) 0)
((set-buffer-fold-type-column-update) 1)
((set-buffer-fold-type-window-update) 2))
(0 (set-buffer-fold-type-window)(message "ウィンドウ幅にした"))
(1 (set-buffer-fold-type-none)(message "折り返し無しにした"))
(2 (set-buffer-fold-type-column)(message "指定位置にした"))))
(global-set-key #\C-F3 'next-buffer-fold-type)
;; ファイルを開く時にセッションファイルならば展開する(佐野さん、リンクはXyzzyWiki: tips/ファイルを開く時にセッションファイルならば展開する
(add-hook '*before-find-file-hook*
#'(lambda (x)
(when (string-matchp "\\.ssn$" x)
(load-session x)
(selected-buffer))))