;;;
;;; Perl辞書サーバをEmacs Lispから検索
;;;
(setq dict-exit-char ?\033)
(setq dict-delete-char ?\177)
(setq dict-kill-char ?\^U)
(setq dict-server "localhost")
(setq dict-port 5678)
(defun dict ()
(interactive)
(let ((dict-string ""))
(dict-message)
(get-buffer-create "*EJ dictionary*")
(switch-to-buffer "*EJ dictionary*")
(open-network-stream "dictserver" "*EJ dictionary*" dict-server dict-port)
(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 ()
(set-buffer "*EJ dictionary*")
(erase-buffer)
(process-send-string "dictserver" (concat pat "\n"))
(accept-process-output "dictserver")
(beginning-of-buffer)
(replace-string "\C-M" "\C-J")
(beginning-of-buffer)
(replace-string "\C-I" "\C-J\C-I")
)))