Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!husc6!yale!spolsky-joel From: spolsky-joel@CS.Yale.EDU (Joel Spolsky) Newsgroups: comp.emacs Subject: webster mode for GNU Emacs (look up a word in the dictionary) Message-ID: <53542@yale-celray.yale.UUCP> Date: 14 Mar 89 00:28:45 GMT Sender: root@yale.UUCP Reply-To: spolsky-joel@CS.Yale.EDU (Joel Spolsky) Organization: Yale University Computer Science Dept, New Haven CT 06520-2158 Lines: 155 Here is Jason Glasgow's webster.el. This allows you to look up a word in the Websters seventh edition via a server with Websters on line. There are servers at Boston University, Purdue, and others, although I do not know where nor do I know how one goes about becoming a webster server. Don't even bother asking me about such esoterica. Needless to say you must have telnet for this to work. This is only an "alpha test" version: comments, suggestions, and bug fixes are encouraged. +----------------+----------------------------------------------------------+ | Joel Spolsky | bitnet: spolsky@yalecs.bitnet uucp: ...!yale!spolsky | | | internet: spolsky@cs.yale.edu voicenet: 203-436-1483 | +----------------+----------------------------------------------------------+ +----------------+----------------------------------------------------------+ | Jason Glasgow | bitnet: glasgow@yalecs.bitnet uucp: ...!yale!glasgow | | | internet: glasgow@cs.yale.edu voicenet: 203-436-1437 | +----------------+----------------------------------------------------------+ -----------------snip snip snip snip-------------------- ;; Copyright (C) 1989 Free Software Foundation ;; This file is part of GNU Emacs. ;; GNU Emacs is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY. No author or distributor ;; accepts responsibility to anyone for the consequences of using it ;; or for whether it serves any particular purpose or works at all, ;; unless he says so in writing. Refer to the GNU Emacs General Public ;; License for full details. ;; Everyone is granted permission to copy, modify and redistribute ;; GNU Emacs, but only under the conditions described in the ;; GNU Emacs General Public License. A copy of this license is ;; supposed to have been given to you along with GNU Emacs so you ;; can know your rights and responsibilities. It should be in a ;; file named COPYING. Among other things, the copyright notice ;; and this notice must be preserved on all copies. ;; ;; Author Jason R. Glasgow (glasgow@cs.yale.edu) ;; Modified from telnet.el by William F. Schelter ;; But almost entirely different ;; ;; To use this, you might want to add this line to your .emacs file: ;; ;; (autoload 'webster "webster" "look up a word in Webster's 7th edition" t) ;; ;; Then just hit M-x webster to look up a word. ;; (defvar webster-host "128.197.2.40" "Host that is a webster server (Boston U). Try also 26.0.0.73, which is sri-nic") (defvar webster-port "103" "The port to connect to. Either 103 or 2627") (defvar webster-request "DEFINE" "The type of request to use. Try DEFINE SPELLING ENDINGS") ;;; ;;; Initial filter for ignoring information until successfully connected ;;; (defun webster-initial-filter (proc string) (cond ((string-match "No such host" string) (kill-buffer (process-buffer proc)) (error "No such host.")) ((string-match "]" string) (set-process-filter proc 'webster-filter) (sleep-for 2) ;;; wait for good connection (message (concat "Looking up word " webster-word "...")) (send-string (get-buffer-process (current-buffer)) (concat webster-request " " webster-word "\n"))))) (defun webster-filter (proc string) (let ((place (string-match "\200" string))) (cond (place (webster-filter proc (concat (substring string 0 (- place 1)) "\n\n")) (message "Closing connection...") (progn (kill-process proc) (set-buffer (process-buffer proc)) (replace-regexp "Process webster killed" "" nil) (goto-char 1)) (message "Done.")) ((string-match "SPELLING 0" string) (message "Word not found in webster") (set-buffer (process-buffer proc)) (goto-char (point-max)) (insert "SPELLING 0") (progn (kill-process proc) (replace-regexp "Process webster killed" "" nil))) (t (save-excursion (set-buffer (process-buffer proc)) (goto-char (point-max)) (let ((now (point))) (insert string) (delete-char-in-region now (point) ?\^m ?\ )) (if (process-mark proc) (set-marker (process-mark proc) (point)))))))) ;;; ;;; delete char1 and char2 if it precedes char1 ;;; used to get rid of (defun delete-char-in-region (start end char1 char2) (goto-char start) (while (search-forward (char-to-string char1) end t) (backward-delete-char 1) (if (equal (char-after (- (point) 1)) char2) (backward-delete-char 1)))) (defun webster (arg) "Open a network login connection to a webster host. And look lookup a word using DEFINE WORD. Communication with host is recorded in a buffer *webster*. The process will end after a \200 is sent." (interactive "sLook up word in webster: ") (require 'shell) (let ((name "webster")) (cond ((not (eq (get-buffer-window (concat "*" name "*")) nil)) (select-window (get-buffer-window (concat "*" name "*")))) ((one-window-p) (split-window-vertically) (other-window 1))) (message (concat "Attempting to connect to server " webster-host "...")) (switch-to-buffer (make-shell name "telnet")) (set-process-filter (get-process name) 'webster-initial-filter) (erase-buffer) (send-string name (concat "open " webster-host " " webster-port "\n")) (webster-mode) (setq webster-word arg))) (defun webster-endings (arg) "Call webster looking for endings" (interactive "sFind endings for word in webster: ") (webster arg) (setq webster-request "ENDINGS")) (defun webster-spell (arg) "Call webster looking for endings" (interactive "sTry to spell word in webster: ") (webster arg) (setq webster-request "SPELL")) (defun webster-mode () "Basically a mode that does nothing. Any characters should make this window disapper, but not yet implemented." (interactive) (kill-all-local-variables) (setq major-mode 'webster-mode) (setq mode-name "Webster") (make-local-variable 'webster-request) (setq webster-request "DEFINE") (make-local-variable 'webster-word) (setq webster-word "jason") (setq fill-column 80))