プログラム

;;;
;;;     Emacs Lispによる単語検索
;;;
(setq dict-exit-char ?\033)
(setq dict-delete-char ?\177)
(setq dict-kill-char ?\^U)

(defun dict ()
  (interactive)
  (let ((dict-string ""))
    (setq dict-buffer "ejdic")
    (dict-message)
    (get-buffer-create "*EJ dictionary*")
    (switch-to-buffer "*EJ dictionary*")
    (catch 'dict-done
      (while t
        (let ((char (read-char)))
          (cond ((eq char dict-exit-char)
                 (throw 'dict-done t))
                ((eq char dict-delete-char)
                 (if (> (length dict-string) 0)
                     (setq dict-string (substring dict-string 0 (1- (length dict-string)))))
                 (dict-search dict-string t)
                 )
                ((eq char dict-kill-char)
                 (setq dict-string "")
                 (dict-message)
                 )
                ((< char 32)
                 (ding)
                 )
                (t
                 (setq dict-string (concat dict-string
                                         (char-to-string char)))
                 (dict-search dict-string)
                 )
                )
          (dict-message dict-string)
          )))
    ))
(defun dict-message (&optional str)
  (let ((s "English Word: "))
    (if (stringp str)
        (setq s (concat s str)))
    (message s)
    ))
(defun dict-search (pat &optional fromstart)
  (if (string= pat "")
      (dict-message)
    (let ((done) (count 0))
      (set-buffer "ejdic")
      (beginning-of-buffer)
      (set-buffer "*EJ dictionary*")
      (erase-buffer)
      (while (and (not done) (< count 20))
        (set-buffer dict-buffer)
        (setq done (not (re-search-forward (concat "^" pat) nil t)))
        (if (not done)
            (progn
              (beginning-of-line)
              (setq p (point))
              (next-line 1)
              (setq s (buffer-substring p (point)))
              (set-buffer "*EJ dictionary*")
              (insert s)
              (setq count (1+ count))
              ))
        )
      )
    ))