作者: みずはのぶお
日時: 2010/1/28(22:49)
みなさまへ

 脚注モードです。

 みずは

;;; -*- Mode: Lisp; Package: EDITOR -*-
;;;
;;; This file is part of xyzzy.
;;;
;;footnote-mode-->fn-mode
(provide "footnotemode")

(in-package "user")
;;推奨はeditorだったのだが、名前が衝突するとのエラーが出たため変更
;;理屈は分からない
(export '(*fn-mode-hook* *fn-mode-map* *tab-stop-list*
	  tab-to-tab-stop center-region center-line center-paragraph
	  fn-mode *fn-mode-syntax-table*))

(defvar *fn-mode-hook* nil)

(defvar *tab-stop-list* '(8 16 24 32 40 48 56 64 72 80 88 96 104 112 120 128))

(defvar *fn-mode-map* nil)
(unless *fn-mode-map*
  (setq *fn-mode-map* (make-sparse-keymap))
  ;(define-key *text-mode-map* #\TAB 'tab-to-tab-stop)
  (define-key *fn-mode-map* #\M-S 'center-paragraph)
  (define-key *fn-mode-map* '(#\C-c #\C-k) 'footnote-mode-jump)
  (define-key *fn-mode-map* '(#\C-c #\C-c) 'footnote-mode-quit)
  (define-key *fn-mode-map* '(#\C-c #\C-n) 'footnote-mode-narrow)
  ;(define-key *text-mode-map* #\M-s 'center-line)
)
;;xyzzyの2ストローク

(defvar *fn-mode-syntax-table* nil)
(unless *fn-mode-syntax-table*
  (setq *fn-mode-syntax-table* (make-syntax-table))
  (set-syntax-symbol *fn-mode-syntax-table* #\&)
  (set-syntax-symbol *fn-mode-syntax-table* #\*)
  (set-syntax-symbol *fn-mode-syntax-table* #\+)
  (set-syntax-symbol *fn-mode-syntax-table* #\-)
  (set-syntax-symbol *fn-mode-syntax-table* #\/)
  (set-syntax-symbol *fn-mode-syntax-table* #\<)
  (set-syntax-symbol *fn-mode-syntax-table* #\=)
  (set-syntax-symbol *fn-mode-syntax-table* #\>)
  (set-syntax-symbol *fn-mode-syntax-table* #\_)
  (set-syntax-symbol *fn-mode-syntax-table* #\|))

(defvar *fn-mode-abbrev-table* nil)
(unless *fn-mode-abbrev-table*
  (define-abbrev-table '*fn-mode-abbrev-table*))

(defun tab-to-tab-stop ()
  (interactive "*")
  (let ((tab (member (current-column) *tab-stop-list* :test #'<)))
    (if tab
	(indent-to (car tab))
      (let ((*last-command-char* #\TAB))
	(self-insert-command)))))

(defun center-region (from to)
  (interactive "*r")
  (save-restriction
    (narrow-to-region from to)
    (goto-char (point-min))
    (while (not (eobp))
      (delete-region (point)
		     (progn
		       (skip-chars-forward " \t ")
		       (point)))
      (goto-eol)
      (delete-region (point)
		     (progn
		       (skip-chars-backward " \t ")
		       (point)))
      (let ((n (truncate (- fill-column (current-column)) 2)))
	(when (plusp n)
	  (goto-bol)
	  (or (eolp)
	      (indent-to n))))
      (unless (forward-line 1)
	(return))))
  t)

(defun center-line (&optional (arg 1))
  (interactive "*p")
  (center-region (point)
		 (progn
		   (forward-line arg)
		   (point))))

(defun center-paragraph ()
  (interactive "*")
  (center-region (progn
		   (forward-paragraph)
		   (point))
		 (progn
		   (backward-paragraph)
		   (point))))

(defun fn-mode ()
  (interactive)
  (toggle-ime t)
  (kill-all-local-variables)
  (setq buffer-mode 'fn-mode)
  (setq mode-name "FootNote")
  (use-keymap *fn-mode-map*)
  (use-syntax-table *fn-mode-syntax-table*)
  (setq *local-abbrev-table* *fn-mode-abbrev-table*)
  (make-local-variable 'highlight-keyword)
  (setq highlight-keyword nil)
  (run-hooks '*fn-mode-hook*))