annotate lisp/packages/webster.el @ 76:c0c698873ce1 r20-0b33

Import from CVS: tag r20-0b33
author cvs
date Mon, 13 Aug 2007 09:05:10 +0200
parents 376386a54a3c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;; Copyright (C) 1989 Free Software Foundation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; This file is part of GNU Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; GNU Emacs is distributed in the hope that it will be useful,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; but WITHOUT ANY WARRANTY. No author or distributor
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;; accepts responsibility to anyone for the consequences of using it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; or for whether it serves any particular purpose or works at all,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; unless he says so in writing. Refer to the GNU Emacs General Public
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; License for full details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; Everyone is granted permission to copy, modify and redistribute
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; GNU Emacs, but only under the conditions described in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; GNU Emacs General Public License. A copy of this license is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; supposed to have been given to you along with GNU Emacs so you
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; can know your rights and responsibilities. It should be in a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; file named COPYING. Among other things, the copyright notice
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; and this notice must be preserved on all copies.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;;; Synched up with: Not in FSF.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;; Author Jason R. Glasgow (glasgow@cs.yale.edu)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;; Modified from telnet.el by William F. Schelter
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;; But almost entirely different.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;; Modified by Dirk Grunwald to maintain an open connection.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;; 3/18/89 Ashwin Ram <Ram-Ashwin@yale.edu>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;; Added webster-mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;; Fixed documentation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;; 3/20/89 Dirk Grunwald <grunwald@flute.cs.uiuc.edu>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;; Merged Rams changes with new additions: smarter window placement,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;; correctly handles un-exposed webster windows, minor cleanups.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;; Also, ``webster-word'', akin to ``spell-word''.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;; To use this, you might want to add this line to your .emacs file:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;; (autoload 'webster "webster" "look up a word in Webster's 7th edition" t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;; Then just hit M-x webster to look up a word.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 ;; 3/21/89 Dave Sill <dsill@relay.nswc.navy.mil>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 ;; Removed webster-word and webster-define, adding default of current word to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 ;; webster, webster-spell, and webster-endings instead.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 ;; 1/21/91 Jamie Zawinski <jwz@lucid.com>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 ;; Added webster-reformat to produce better looking output. Made it notice
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 ;; references to other words in the definitions (all upper-case) and do
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 ;; completion on them in the string read by meta-x webster.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 ;; 9/14/91 Jamie Zawinski <jwz@lucid.com>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 ;; Improved the above.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 ;; 4/15/92 Jamie Zawinski <jwz@lucid.com>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 ;; Improved formatting some more, and added Lucid GNU Emacs font and mouse
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 ;; support (mostly cannibalized from webster-ucb.el.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 (defvar webster-host "agate.berkeley.edu" ;"129.79.254.192"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 "The host to use as a webster server.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 (defvar webster-port "2627"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 "The port to connect to. Either 103 or 2627")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (defvar webster-process nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 "The current webster process")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (defvar webster-process-name "webster"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 "The current webster process")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (defvar webster-buffer nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 "The current webster process")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (defvar webster-running nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 "Used to determine when connection is established")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 ;;; Initial filter for ignoring information until successfully connected
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (defun webster-initial-filter (proc string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (let ((this-buffer (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (set-buffer webster-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (cond ((not (eq (process-status webster-process) 'run))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (setq webster-running t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (message "Webster died"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 ((string-match "No such host" string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (setq webster-running t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (kill-buffer (process-buffer proc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (error "No such host."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 ((string-match "]" string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (setq webster-running t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (set-process-filter proc 'webster-filter)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (set-buffer this-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (defvar webster-reformat t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 "*Set this to t if you want the webster output to be prettied up, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 for the \\[webster] prompt to do completion across the set of words known
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 to be in the dictionary (words you've looked up, or which appeared in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 definitions as crossreferences.)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (defun webster-filter (proc string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (let ((this-buffer (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (endp nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (set-buffer webster-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (cond ((not (eq (process-status webster-process) 'run))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (message "Webster died"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 ((string-match "Connection closed" string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (message "Closing webster connection...")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (kill-process proc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (replace-regexp "Process webster killed" "" nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (goto-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (message "Closing webster connection...Done."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 ((string-match "SPELLING 0" string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (insert "...Word not found in webster\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 ((string-match "SPELLING 1" string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (insert "...Spelled correctly\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 ((let ((end-def-message (or (string-match "\200" string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (string-match "\0" string))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (if end-def-message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (webster-filter
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 proc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (concat (substring string 0 (- end-def-message 1)) "\n\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (setq endp t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (let ((now (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (insert string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (delete-char-in-region now (point) "\^M" " "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (if (process-mark proc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (set-marker (process-mark proc) (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (if endp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 ;; if the webster window is visible, move the last line to the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 ;; bottom of that window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (let ((webster-window (get-buffer-window webster-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (window (selected-window)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (if webster-reformat (webster-reformat (process-mark proc)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (if webster-window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (select-window webster-window)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (recenter (1- (window-height webster-window)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (select-window window)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (defconst webster-completion-table (make-vector 511 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (defun webster-intern (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (while (string-match "\\." string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (setq string (concat (substring string 0 (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 (substring string (match-end 0)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 (intern (downcase string) webster-completion-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (defvar webster-fontify (string-match "XEmacs" emacs-version)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 "*Set to t to use the XEmacs/Lucid Emacs font-change mechanism.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (cond ((fboundp 'make-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 (or (find-face 'webster)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (face-differs-from-default-p (make-face 'webster))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 (copy-face 'default 'webster))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (or (find-face 'webster-bold)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (face-differs-from-default-p (make-face 'webster-bold))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (copy-face 'bold 'webster-bold))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (or (find-face 'webster-italic)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (face-differs-from-default-p (make-face 'webster-italic))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 (copy-face 'italic 'webster-italic))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 (or (find-face 'webster-bold-italic)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (face-differs-from-default-p (make-face 'webster-bold-italic))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (copy-face 'bold-italic 'webster-bold-italic))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (or (find-face 'webster-small)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (face-differs-from-default-p (make-face 'webster-small))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (copy-face 'webster-bold 'webster-small))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 (defun webster-fontify (start end face &optional highlight)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (let ((e (make-extent start end (current-buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (set-extent-face e face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 (if highlight (set-extent-property e 'highlight t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 (defun webster-reformat (end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 "Clean up the output of the webster server, and gather words for the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 completion table."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (if (not webster-reformat) nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (goto-char end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 (let ((case-fold-search nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (re-search-backward "^[A-Z]+" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (if webster-fontify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 (previous-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (if (looking-at "^DEFINE \\([^ \n]+\\)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (webster-fontify (match-beginning 1) (match-end 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 'webster-bold t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 ((or (looking-at "^DEFINITION [0-9]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 (looking-at "^SPELLING"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (let ((p (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (indent 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 (search-forward "\n\n" nil 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (narrow-to-region p (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 (goto-char p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (while (search-forward "\n" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 (delete-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (just-one-space))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (goto-char p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 (while (not (eobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (if (looking-at " *\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (delete-region (match-beginning 0) (match-end 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 (cond ((looking-at "^[0-9]+ ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (if webster-fontify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (webster-fontify (point) (match-end 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 'webster-bold-italic))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 (goto-char (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (if (looking-at "[^\n0-9]+ [0-9]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 (goto-char (1- (match-end 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (insert "\n")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 (if (looking-at "[a-z]+\\( [a-z]+\\)*[ \n]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 (webster-intern
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 (buffer-substring (point) (1- (match-end 0)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (if webster-fontify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (webster-fontify (point) (1- (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 'webster-bold t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (goto-char (1- (match-end 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (if (looking-at " *\n") (forward-line 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 ((looking-at " *[0-9]+\\. ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 (setq indent 5)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (delete-horizontal-space)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (insert (if (= (preceding-char) ?\n) " " "\n "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 (skip-chars-forward "0-9. ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (if webster-fontify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 (webster-fontify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (save-excursion (beginning-of-line) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 'webster-bold-italic)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 ((looking-at " *\\([0-9]+\\): *")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (let ((n (buffer-substring (match-beginning 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (match-end 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 (delete-region (match-beginning 0) (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (insert "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (indent-to (- 6 (length n)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 (insert n " : ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 (setq indent 9)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (if webster-fontify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 (webster-fontify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (save-excursion (beginning-of-line) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 'webster-bold-italic))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 ((looking-at " *\\([0-9]+\\)\\([a-z]+\\): *")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (let ((n (buffer-substring (match-beginning 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 (match-end 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (m (buffer-substring (match-beginning 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 (match-end 2))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 (if (not (equal m "a")) (setq n " "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (delete-region (match-beginning 0) (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (insert "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 (indent-to (- 6 (length n)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (insert n " ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (insert m " : ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 (setq indent 12)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (if webster-fontify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 (webster-fontify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 (save-excursion (beginning-of-line) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 'webster-bold-italic))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 ((looking-at " *\\([0-9]+\\)\\([a-z]+\\)\\([0-9]+\\): *")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 (let ((n (buffer-substring (match-beginning 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 (match-end 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 (m (buffer-substring (match-beginning 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 (match-end 2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 (o (buffer-substring (match-beginning 3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 (match-end 3))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (if (not (equal o "1")) (setq m " "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 (if (not (equal m "a")) (setq n " "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 (delete-region (match-beginning 0) (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (insert "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 (indent-to (- 6 (length n)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 (insert n " ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (insert m " ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 (insert "(" o ") : ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 (setq indent 17)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 (if webster-fontify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 (webster-fontify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 (save-excursion (beginning-of-line) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 'webster-bold-italic))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 ((looking-at " *\\\\")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 (setq indent 5)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 (setq p (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 (goto-char (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 (search-forward "\\")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 (if (> (current-column) fill-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 (goto-char p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 (insert "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 (indent-to 18)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 (search-forward "\\")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 (if webster-fontify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 (webster-fontify p (point) 'webster-italic)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 ((looking-at " *\\[")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 (setq indent 6)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 (delete-horizontal-space)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 (insert "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 (indent-to 5)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 (forward-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 ((and (= (preceding-char) ?\])
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 (looking-at " *:"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 (delete-horizontal-space)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 (setq indent 5)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 (insert "\n "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 ((looking-at " *SYN *")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 (delete-region (point) (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 (insert "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 (delete-horizontal-space)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 (insert " ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 (setq indent 6)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 (if (looking-at "syn ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 (if webster-fontify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 (webster-fontify (point) (+ (point) 3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 'webster-bold))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 (goto-char (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 (insert "see "))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 (setq p (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 (skip-chars-forward " ,:;-")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 (if (or (looking-at
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 "\\([A-Z][-A-Z]+[A-Z]\\)\\( [A-Z][-A-Z]*[A-Z]\\)*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 (looking-at "[a-z][-a-z]*\\(\\.[a-z][-a-z]*\\)+"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 (let ((s (buffer-substring (point) (match-end 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 (if webster-fontify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 (webster-fontify (point) (match-end 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 'webster-bold t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 (while (string-match "\\." s)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 (setq s (concat (substring s 0 (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 (substring s (match-end 0)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 (webster-intern s)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 (skip-chars-forward "^ \\")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 (if (> (current-column) fill-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 (goto-char p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 (insert "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 (delete-horizontal-space)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 (indent-to indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 (skip-chars-forward " ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 (skip-chars-forward "^ \\")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 (while (looking-at "\n") (delete-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 (insert "\n\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 (widen))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 ;; " \\(\\(slang\\|cap\\|pl\\|aj\\|av\\|n\\|v\\|vt\\|vi\\)\\(,[ \n]+\\)?\\)+\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 ;;; delete char1 and char2 if it precedes char1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 ;;; used to get rid of <space><return>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 (defun delete-char-in-region (start end char1 char2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 (goto-char start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 (setq char2 (aref char2 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 (while (search-forward char1 end t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 (delete-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 (if (= (char-after (- (point) 1)) char2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 (delete-char -1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 (defun webster (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 "Look up a word in the Webster's dictionary.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 Open a network login connection to a webster host if necessary.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 Communication with host is recorded in a buffer *webster*."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 (interactive (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 (let ((prompt (concat "Look up word in webster ("
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 (current-word) "): "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 (completion-ignore-case t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 (downcase
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 (if webster-reformat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 (completing-read prompt webster-completion-table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 nil nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 (read-string prompt))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 (if (equal "" arg) (setq arg (current-word)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 (webster-send-request "DEFINE" arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 (defun webster-endings (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 "Look up endings for a word in the Webster's dictionary.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 Open a network login connection to a webster host if necessary.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 Communication with host is recorded in a buffer *webster*."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 (interactive (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 (read-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 (concat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 "Find endings for word in webster (" (current-word) "): "))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 (if (equal "" arg) (setq arg (current-word)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 (webster-send-request "ENDINGS" arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 (defun webster-spell (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 "Look spelling for a word in the Webster's dictionary.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 Open a network login connection to a webster host if necessary.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 Communication with host is recorded in a buffer *webster*."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 (interactive (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 (read-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 (concat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 "Try to spell word in webster (" (current-word) "): "))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 (if (equal "" arg) (setq arg (current-word)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 (webster-send-request "SPELL" arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 (defun webster-send-request (kind word)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 (require 'shell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 (let
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 ((webster-command (concat "open " webster-host " " webster-port "\n")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 (if (or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 (not webster-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 (not webster-process)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 (not (eq (process-status webster-process) 'run)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 (message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 (concat "Attempting to connect to server " webster-host "..."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 (setq webster-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 (if (not (fboundp 'make-shell)) ;emacs19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 (make-comint webster-process-name "telnet")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 (make-shell webster-process-name "telnet")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 (let
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 ((this-buffer (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 (set-buffer webster-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 (webster-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 (set-buffer this-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 (setq webster-process (get-process webster-process-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 (set-process-filter webster-process 'webster-initial-filter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 (process-send-string webster-process webster-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 (setq webster-running nil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 (while (not webster-running) ; wait for feedback
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 (accept-process-output)))) ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 (display-buffer webster-buffer nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 (process-send-string webster-process (concat kind " " word "\n"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 (defun webster-quit ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 "Close connection and quit webster-mode. Buffer is not deleted."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 (message "Closing connection to %s..." webster-host)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 (kill-process webster-process)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 (message "Closing connection to %s...done" webster-host)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 (bury-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 (defvar webster-mode-map nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 (defun webster-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 "Major mode for interacting with on-line Webster's dictionary.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 \\{webster-mode-map}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 Use webster-mode-hook for customization."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 (kill-all-local-variables)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 (setq major-mode 'webster-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 (setq mode-name "Webster")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 (use-local-map webster-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 (run-hooks 'webster-mode-hook))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 (if webster-mode-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 (setq webster-mode-map (make-sparse-keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 (define-key webster-mode-map "?" 'describe-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 (define-key webster-mode-map "d" 'webster)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 (define-key webster-mode-map "e" 'webster-endings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 (define-key webster-mode-map "q" 'webster-quit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 (define-key webster-mode-map "s" 'webster-spell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 (if (string-match "XEmacs" emacs-version)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 (define-key webster-mode-map 'button2 'webster-xref-word)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 ;; now in simple.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 ;(defun current-word ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 ; "Word cursor is over, as a string."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 ; (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 ; (let (beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 ; (re-search-backward "\\w" nil 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 ; (re-search-backward "\\b" nil 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 ; (setq beg (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 ; (re-search-forward "\\w*\\b" nil 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 ; (setq end (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 ; (buffer-substring beg end))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 (defun webster-xref-word (event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 "Define the highlighted word under the mouse.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 Words which are known to have definitions are highlighted when the mouse
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 moves over them. You may define any word by selecting it with the left
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 mouse button and then clicking middle."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 (interactive "e")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 (let* ((buffer (event-buffer event))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 (extent (extent-at (event-point event) buffer 'highlight))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 text)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 (cond (extent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 (setq text (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 (set-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 (buffer-substring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 (extent-start-position extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 (extent-end-position extent)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 ((x-selection-owner-p) ; the selection is in this emacs process.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 (setq text (x-get-selection)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 (error "click on a highlighted word to define")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 (while (string-match "\\." text)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 (setq text (concat (substring text 0 (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 (substring text (match-end 0)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 (message "looking up %s..." (upcase text))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 (webster text)))