annotate lisp/packages/gopher.el @ 199:169c0442b401 r20-3b26

Import from CVS: tag r20-3b26
author cvs
date Mon, 13 Aug 2007 10:00:33 +0200
parents 489f57a838ef
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 ;;; gopher.el --- an emacs gopher client
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; Copyright (C) 1992 scott snyder
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Author: scott snyder <snyder@fnald0.fnal.gov>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Created: 29 Jun 1992
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;; Version: 1.03
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; Keywords: gopher, comm
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; LCD Archive Entry:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; gopher|scott snyder|snyder@fnald0.fnal.gov|
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; An emacs gopher client.|
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; 20-Apr-1993|1.02|~/interfaces/gopher.el.Z|
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; This file is not part of GNU Emacs, but is distributed under the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; same conditions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; GNU Emacs is distributed in the hope that it will be useful,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;; but WITHOUT ANY WARRANTY. No author or distributor
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; accepts responsibility to anyone for the consequences of using it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; or for whether it serves any particular purpose or works at all,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;; unless he says so in writing. Refer to the GNU Emacs General Public
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;; License for full details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;; Everyone is granted permission to copy, modify and redistribute
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;; GNU Emacs, but only under the conditions described in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;; GNU Emacs General Public License. A copy of this license is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;; supposed to have been given to you along with GNU Emacs so you
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;; can know your rights and responsibilities. It should be in a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;; file named COPYING. Among other things, the copyright notice
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;; and this notice must be preserved on all copies.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;;; Synched up with: Not in FSF.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;; An emacs gopher client. Currently supports directory, text, CSO,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;; index, image, and telnet objects.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;; Requires forms.el and background.el.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;; Written by scott snyder <snyder@fnald0.fnal.gov>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 ;; Some code borrowed from GNUS (by Masanobu UMEDA).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;; Some code (bookmarks, xterms, error handling) contributed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 ;; by Stewart Clamen <clamen@cs.cmu.edu>.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 ;; OPERATING INSTRUCTIONS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 ;; To use, `M-x gopher'. To specify a different root server, use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 ;; `C-u M-x gopher'. If you want to use bookmarks, set the variable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 ;; gopher-support-bookmarks appropriately.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 ;; The command `M-x gopher-atpoint' will attempt to interpret the text
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 ;; around point as a gopher bookmark specification and will retrieve
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 ;; that item.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ;; Sample .emacs configuration:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 ;; (autoload 'gopher "gopher")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 ;; (autoload 'gopher-atpoint "gopher")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 ;; (setq gopher-support-bookmarks t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 ;; In directory mode:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 ;; Space, return, `f', or `e' selects the line point is on.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 ;; With a numeric prefix argument, select that object.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 ;; `q', `l', or `u' will return to the previous node.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 ;; `n' and `p' to the next and previous lines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 ;; `a' will add an object to your bookmark list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 ;; `v' will display your bookmark list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 ;; `=' gives detailed information about an object.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 ;; In the bookmark list, all of the above (except `a'), plus:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 ;; `C-k' will delete an object from the bookmark list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 ;; `C-y' will yank the most recently deleted bookmark object back into
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 ;; the bookmark buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 ;; `s' will save the bookmark list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 ;; `Q' will quit gopher entirely, killing all gopher buffers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 ;; All commands which operate on a specific object can take an optional
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 ;; numeric prefix argument giving the index of the object on which
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 ;; to operate.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 ;; In document mode:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 ;; Space pages forward.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 ;; Delete pages backward.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 ;; `q', `l' or `u' returns to the last node.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 ;; In the CSO entry form:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 ;; `C-c RET' performs a look-up, based on the field contents
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 ;; you've filed in.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 ;; `C-c l' returns to the previous node.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 ;; Telnets:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 ;; If you have an X server set, gopher will try to create an xterm
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 ;; running telnet. If not, the emacs-lisp telnet mode will be used.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 ;; From the emacs-lisp telnet mode, use `C-c l' to kill the session
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 ;; and return to the previous node.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 ;; See also the variable gopher-telnet-command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 ;; Images:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 ;; Images are displayed using the command gopher-image-display-command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 ;; The default setting for this variable uses xv.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 ;; Note:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 ;; If gopher consistently hangs while trying to retrieve an object,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 ;; try turning on gopher-buggy-accept (which see).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 ;; VMS notes:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 ;; To use this on VMS, you'll need my emacs subprocess patches (recently
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 ;; posted on gnu.emacs.sources; if you can't find them, send me mail).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 ;; To be able to run telnet in a separate decterm, you'll also need
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 ;; to (setq shell-file-name "docmd") and create the file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 ;; emacs_library:[etc]docmd.com containing the following:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 ;; $ if p1 .eqs. "-C" then p1 = ""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 ;; $ deass sys$input
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 ;; $ 'p1 'p2 'p3 'p4 'p5 'p6 'p7 'p8
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 ;; $ eoj
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 ;;; Change Log:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 ;; Version 1.03 30-APR-1993
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 ;; * Add a buffer-local variable gopher-obj to all gopher buffers bound
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 ;; to the description of the object contained in that buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 ;; Version 1.02 20-APR-1993
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 ;; * Avoid using replace-regexp in gopher-clean-text. (Suggested by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 ;; sbyrnes@rice.edu (Steven Byrnes)).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 ;; * Added gopher-port-aliases.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 ;; * Print ports as strings in gopher-directory-show-object.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 ;; * Don't (ding) when the net stream closes unexpectedly.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 ;; * Added image display (based on code from beldar@MicroUnity.com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 ;; (Gardner Cohen)).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 ;; * Attempt to improve error reporting.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 ;; * Reworked gopher-parse-bookmark to handle out-of-order fields.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 ;; * Added gopher-atpoint.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 ;; * Moved bookmark init stuff to gopher-read-bookmarks.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 ;; * Added gopher-quit (based on code from Thomas L|fgren
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 ;; <tde9104@abacus.hgs.se>).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 ;; * Change usage of background for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 ;; (Patch from "William M. Perry" <wmperry@raisin.ucs.indiana.edu>).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 ;; * Added a (provide 'gopher) at end.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 ;; * Added `f' and `e' bindings in directory mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 ;; Version 1.01
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 ;; * Added patch suggested by Humberto Ortiz-Zuazaga
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 ;; <zuazaga@ucunix.san.uc.EDU> to allow null Path= items in .gopherrc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 ;; Version 1.00 29-AUG-1992
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 ;; * Added gopher-buggy-accept.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 ;; * Reworked telnet stuff to use an arbitrary command string to start up
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 ;; the telnet process. This can be used to start the telnet in a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 ;; separate terminal window.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 ;; Based on code from Stewart Clamen.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 ;; * Stewart Clamen <clamen@cs.cmu.edu> added bookmarks.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 ;; * Added 's key binding to save bookmarks.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 ;; * Added a prefix argument to gopher-directory-buffer and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 ;; gopher-add-bookmark.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 ;; * Added standard emacs-lisp header.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 ;; * Stewart Clamen <clamen@cs.cmu.edu> added some error trapping and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 ;; recovery (gopher-retrieve-document-cleanly).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 ;; * Appended node description to the node's buffer's name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 ;; * Reformat bookmark buffers when returning to them via gopher-last-node
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 ;; or when an item is deleted.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 ;; * Added gopher-yank-bookmark.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 ;; * Added gopher-bookmark-modified-tick to prevent reformatting bookmark
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 ;; buffers needlessly.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 ;; Version 0.92 27-JUL-1992
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 ;; * Added gopher-hostname-aliases.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 ;; Version 0.91 30-JUN-1992
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 ;; * Deal with servers which send stuff after the CR.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 ;; * Prevent gopher-directory-show-object from clearing the read-only flag.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 ;; * Allow specification of port number in `C-u M-x gopher'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 ;; Version 0.9 29-JUN-1992
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 ;; * Initial release.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 (require 'electric)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 (require 'forms)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 ;; background has the same name as an epoch function.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 ;; Rename it to gopher-background...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 ;; also, the version i got from the archive didn't have a provide...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 (cond ((and (string-lessp "19" emacs-version)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 (not (boundp 'epoch::version)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 ;; background is obsolete in emacs19: just add a & to shell-command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 (defun gopher-background (command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (shell-command (concat command "&"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 ;; background has the same name as an epoch function.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 ;; Rename it to gopher-background...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 ;; also, the version i got from the archive didn't have a provide...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 (if (not (fboundp 'gopher-background))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 (if (fboundp 'background)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (let ((old-background (symbol-function 'background)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (load-library "background")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (fset 'gopher-background (symbol-function 'background))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (fset 'background old-background))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 (load-library "background")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 (fset 'gopher-background (symbol-function 'background))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
202 (defgroup gopher nil
189
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 134
diff changeset
203 "Emacs gopher client."
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 134
diff changeset
204 :group 'hypermedia
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 134
diff changeset
205 :group 'comm)
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
206
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
208 (defcustom gopher-root-node (vector ?1 "root" "" "ucs_gopher" 70)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
209 "The root gopher server, as a gopher object."
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
210 :type '(vector character string string
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
211 (string :tag "Host")
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
212 (integer :tag "Port"))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
213 :group 'gopher
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
214 :group 'local)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
215
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
216 (defcustom gopher-directory-mode-hook nil
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
217 "*Invoked when entering a new gopher directory."
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
218 :type 'hook
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
219 :group 'gopher)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (defvar gopher-directory-mode-map (make-keymap)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 "Keymap for gopher-directory-mode.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
223 (defcustom gopher-document-mode-hook nil
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
224 "*Invoked when showing gopher document."
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
225 :type 'hook
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
226 :group 'gopher)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (defvar gopher-document-mode-map (make-keymap)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 "Keymap for gopher-document-mode.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
230 (defcustom gopher-form-mode-hooks nil
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
231 "*Invoked with entering a gopher form (i.e., for CSO)."
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
232 :type 'hook
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
233 :group 'gopher)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (defvar gopher-form-mode-map (make-keymap)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 "Keymap for gopher-form-mode.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (defvar gopher-tmp-buf nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 "Buffer used to receive output from gopher.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
240 (defcustom gopher-debug-read t
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
241 "*If non-nil, show the current status about reading the gopher server output."
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
242 :type 'boolean
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
243 :group 'gopher)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 ;; On some systems (such as SGI Iris), accept-process-output doesn't seem
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 ;; to return for the last packet received on a connection. Turn this on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 ;; to work around the problem, but does anyone know what causes this?
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
248 (defcustom gopher-buggy-accept nil
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 "*If non-nil, use sit-for instead of accept-process-output.
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
250 If gopher consistently hangs while fetching an object, try turning this on."
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
251 :type 'boolean
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
252 :group 'gopher)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
254 (defcustom gopher-hostname-aliases
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 '(("128.230.33.31" . "oliver.syr.edu"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 "Emacs can't deal with raw IP addresses used as a hostname.
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
257 Use this to work around..."
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
258 :type '(repeat (cons (string :tag "IP Address")
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
259 (string :tag "Host Name")))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
260 :group 'gopher)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
262 (defcustom gopher-port-aliases
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 '(("whois_port" . 43))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 "Some losing hosts send a port name instead of a number.
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
265 Use this table to convert..."
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
266 :type '(repeat (cons (string :tag "Named Port")
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
267 (integer :tag "Port Number")))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
268 :group 'gopher)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
271 (defcustom gopher-support-bookmarks nil
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 "*If nil, do not implement bookmarks.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 If 'unix or t, read and write bookmarks to ~/.gopherrc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 If a filename, read and save vector from there directly (not implemented yet).
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
275 If a vector, treat as a built-in directory."
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
276 :type '(choice (const :tag "off" nil)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
277 (const t) (const unix)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
278 file
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
279 vector)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
280 :group 'gopher)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (defconst gopher-bookmarks nil "Internal bookmark directory.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 (defconst gopher-bookmarks-modified nil "Do bookmarks need to be saved?")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 (defconst gopher-killed-bookmark nil "The last bookmark object to be killed")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 (defconst gopher-bookmark-directory-p nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 "Is this buffer a bookmark directory? A buffer-local variable.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 (defvar gopher-bookmark-modified-tick 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 "Counts each time the bookmark vector is modified.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
292 (defcustom gopher-telnet-command
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 (cond ((eq system-type 'vax-vms)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 (if (getenv "DECW$DISPLAY")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 "create/terminal/wait/window=(title=\"telnet\") telnet"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 (if (getenv "DISPLAY")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 "xterm -e telnet"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 "*Command to use to start a telnet session.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 If this is nil, the emacs-lisp telnet package will be used.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 The default setting is to create a terminal window running telnet
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
303 if you've specified an X server, and to use the emacs-lisp telnet otherwise."
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
304 :type '(choice (const nil) string)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
305 :group 'gopher)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
308 (defcustom gopher-image-display-command "xv -geometry +200+200"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
309 "*The command used to try to display an image object."
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
310 :type 'string
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
311 :group 'gopher)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
314 (defcustom gopher-object-type-alist
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 '(( ?0 "" gopher-document-object)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 ( ?1 "/" gopher-directory-object)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 ( ?2 " <CSO>" gopher-cso-object)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 ( ?3 " <error>" gopher-unimplemented-object)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 ( ?4 " <binhex>" gopher-binary-object)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 ( ?5 " <DOS>" gopher-binary-object)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 ( ?6 " <UU>" gopher-binary-object)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 ( ?7 " <?>" gopher-index-object)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 ( ?8 " <TEL>" gopher-telnet-object)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 ( ?9 " <bin>" gopher-binary-object)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 ( ?T " <T>" gopher-unimplemented-object)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 ( ?s " <)" gopher-binary-object)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 ( ?M " <MIME>" gopher-unimplemented-object)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 ( ?h " <html>" gopher-unimplemented-object)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 ( ?I " <image>" gopher-image-object)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 ( ?c " <cal>" gopher-unimplemented-object)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 ( ?g " <GIF>" gopher-image-object)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 "*Alist describing the types of gopher objects this client know about.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 The keys are the gopher type characters.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 The second element in each list is the string to tag onto the end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 of an object's description, to identify it to the user.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 The third element is the function to use to retrieve the object.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 It is called with two arguments: the gopher object to retrieve and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 the buffer which should be returned to when the user is done
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
340 with this object."
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
341 :type '(repeat (list character string function))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
342 :group 'object)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 ;;; The data structure describing a gopher object is a vector of five elements:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 ;;; [ TYPE DESCR SELECTOR HOST PORT ]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 ;;; TYPE is the type character.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 ;;; DESCR is the human-readable description of the object.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 ;;; SELECTOR is the opaque selector to be sent to HOST to retrieve the obj.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 ;;; HOST is the name of the Internet host on which the object resides.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 ;;; PORT is the TCP/IP port on which the host is listening.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 ;;; The following macros set and fetch elements of this structure.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 (defconst gopher-object-length 5)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 (defmacro gopher-object-type (object)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 "Return the gopher type of OBJECT."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 (` (aref (, object) 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 (defmacro gopher-object-descr (object)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 "Return the gopher description of OBJECT."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 (` (aref (, object) 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 (defmacro gopher-object-selector (object)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 "Return the gopher selector string for OBJECT."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 (` (aref (, object) 2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 (defmacro gopher-object-host (object)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 "Return the gopher hostname for OBJECT."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 (` (aref (, object) 3)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 (defmacro gopher-object-port (object)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 "Return the gopher TCP port number for OBJECT."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 (` (aref (, object) 4)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 (defmacro gopher-set-object-type (object type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 "Set the gopher type of OBJECT to TYPE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 (` (aset (, object) 0 (, type))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 (defmacro gopher-set-object-descr (object descr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 "Set the gopher description of OBJECT to DESCR."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 (` (aset (, object) 1 (, descr))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 (defmacro gopher-set-object-selector (object selector)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 "Set the gopher selector string for OBJECT to SELECTOR."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 (` (aset (, object) 2 (, selector))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 (defmacro gopher-set-object-host (object host)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 "Set the gopher hostname for OBJECT to HOST."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 (` (aset (, object) 3 (, host))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 (defmacro gopher-set-object-port (object port)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 "Set the gopher TCP port number for OBJECT to PORT."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 (` (aset (, object) 4 (, port))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 (defmacro gopher-retrieve-document-cleanly (args handle &rest body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 "Call gopher-retrieve-document with condition-case wrapped around,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 applying HANDLE if appropriate."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 (` (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 (gopher-retrieve-document (,@ args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 (,@ body))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 (error (, handle)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 ;; buffer-local variables.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 ;; declared here to prevent warnings from the new byte-compiler.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 (defvar gopher-dir nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 (defvar gopher-last nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 (defvar gopher-obj nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 (defvar gopher-telnet-process-name nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 (defvar gopher-bookmark-buffer-tick nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 (defvar forms-accept-action nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 ;;;;--------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 ;;;; main dispatching logic.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 ;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 (defun gopher (&optional askserv)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 "Start a gopher session. With C-u, prompt for a gopher server."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 (if askserv
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 (gopher-set-object-host
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 gopher-root-node
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 (read-string "Gopher server: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 (gopher-object-host gopher-root-node)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 (let (portstr port)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 (while (not (numberp port))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 (setq portstr
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 (read-string "Port: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 (int-to-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 (gopher-object-port gopher-root-node))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 (setq port (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 (car (read-from-string portstr))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 (error nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 (if (not (numberp port))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 (ding)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 (message "Port must be numeric")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 (sit-for 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 (gopher-set-object-port gopher-root-node port))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 (gopher-read-bookmarks)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 (gopher-dispatch-object gopher-root-node nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 (defun gopher-atpoint nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 "Try to interpret the text around point as a gopher bookmark, and dispatch
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 to that object."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 (let (bkmk)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 (re-search-backward "^#[ \t]*$\\|^[ \t]*$\\|\\`")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 (skip-chars-forward " \t\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 (setq bkmk (gopher-parse-bookmark)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 (if bkmk
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 (gopher-read-bookmarks)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 (gopher-dispatch-object bkmk nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 (error "Illformed bookmark"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 (defun gopher-dispatch-object (obj lastbuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 "Dispatch a gopher object depending on its type."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 (let ((typedesc (assq (gopher-object-type obj) gopher-object-type-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 (if typedesc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 (funcall (nth 2 typedesc) obj lastbuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 (gopher-unimplemented-object obj lastbuf))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 (defun gopher-unimplemented-object (obj lastbuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 (error "unimplemented object type"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 ;;;;--------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 ;;;; utilities
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 ;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 (defun gopher-next-field nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 "Returns as a string all chars between point and the next tab or newline.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 Point is advanced to after the tab (or to the end-of-line)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 (let ((beg (point)) s)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 (skip-chars-forward "^\t\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 (setq s (buffer-substring beg (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 (if (eq (following-char) ?\t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 (forward-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 s))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 ;; from GNUS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 (defun gopher-make-local-vars (&rest pairs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 ;; Take VARIABLE-VALUE pairs and makes local variables initialized to the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 ;; value.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 (while pairs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 (make-local-variable (car pairs))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 (set (car pairs) (car (cdr pairs)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 (setq pairs (cdr (cdr pairs)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 (defun gopher-get-tmp-buf nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 "Get a temporary buffer in which to receive gopher output."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 (or (bufferp gopher-tmp-buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 (setq gopher-tmp-buf (get-buffer-create " *gopher-tmp*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 (buffer-flush-undo gopher-tmp-buf)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 gopher-tmp-buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 (defun gopher-get-dir-buf (descr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 "Get a new buffer suitable for a gopher directory or document."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 (let ((buf (generate-new-buffer (concat "*gopher*" descr))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 (buffer-flush-undo buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 (fset 'gopher-get-doc-buf (symbol-function 'gopher-get-dir-buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 (defun gopher-trim-blanks (str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 "Remove leading and trailing blanks from STR."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 (string-match "\\`[ \t\n]*" str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 (substring str
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 (match-end 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 (string-match "[ \t\n]*\\'" str (match-end 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 ;;;;--------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 ;;;; directory handling
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 ;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 (defun gopher-directory-object (obj oldbuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 "Retrieve and display a gopher directory."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 (let ((tmpbuf (gopher-get-tmp-buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 (dirbuf (gopher-get-dir-buf (gopher-object-descr obj))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 ;; Get the directory...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 (gopher-retrieve-document-cleanly (tmpbuf
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 (gopher-object-selector obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 (gopher-object-host obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 (gopher-object-port obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 (kill-buffer dirbuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 (error "Problems retrieving directory."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 ;; Parse it and store our internal representation in gopher-dir.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 (switch-to-buffer dirbuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 (gopher-make-local-vars
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 'gopher-dir (gopher-parse-directory tmpbuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 'gopher-obj obj
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 'gopher-last oldbuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 ;; Format it for your viewing pleasure.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 (gopher-format-directory gopher-dir dirbuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 (if (> (- (point-max) (point)) 7) (forward-char 7))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 ;; Turn on directory mode and put the description in the mode line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 (gopher-directory-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 (setq mode-line-buffer-identification (concat "Gopher: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 (gopher-object-descr obj)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 (defun gopher-parse-directory (buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 "Parse the gopher directory in buffer BUF into our internal representation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 Returns a vector of gopher objects."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 (set-buffer buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 (let* ((len (count-lines (point-min) (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 (dir (make-vector len nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 (i 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 (while (not (eobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 (aset dir i (gopher-parse-directory-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 (setq i (1+ i))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 (forward-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 dir)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 (defun gopher-parse-directory-line nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 "Parse the line containing point as a gopher directory entry.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 Returns the corresponding gopher object."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 (let (type descr selector host port)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 (setq type (following-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 (forward-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 (setq descr (gopher-next-field))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 (setq selector (gopher-next-field))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 (setq host (gopher-next-field))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 (setq port (gopher-next-field))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 (if (string-match "^[0-9]+$" port)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 (setq port (string-to-int port)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 (vector type descr selector host port)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 (defun gopher-format-directory (dir buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 "Print the directory vector DIR into buffer BUF."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 (set-buffer buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 (let ((i 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 (len (length dir)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 (while (< i len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 (gopher-format-directory-line (aref dir i) (1+ i))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 (setq i (1+ i)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 (defun gopher-format-directory-line (obj ndx)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 "Insert a line describing the gopher object OBJ into the current buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 NDX is a numeric index to display to the left of the object description."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 (let ((ndx-str (int-to-string ndx))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 (typedesc (assq (gopher-object-type obj) gopher-object-type-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 ;; display the index number. use 5 digits, right-justified.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 (if (< (length ndx-str) 5)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 (insert (make-string (- 5 (length ndx-str)) ? )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 (insert ndx-str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 (insert ". ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 ;; add the object description.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 (insert (gopher-object-descr obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 ;; add a tag indicating the gopher object type.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 (insert (if typedesc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 (nth 1 typedesc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 (concat " ???" (char-to-string (gopher-object-type obj)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 (insert "\n")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 (defun gopher-directory-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 "Gopher directory mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 \\{gopher-directory-mode-map}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 (use-local-map gopher-directory-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 (setq major-mode 'gopher-directory-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 (setq mode-name "gopher dir")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 (run-hooks 'gopher-directory-mode-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 (setq buffer-read-only t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 (require 'mode-motion)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 (make-local-variable 'mode-motion-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 (setq mode-motion-hook 'mode-motion-highlight-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 ;;; keymap for directory mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 (suppress-keymap gopher-directory-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 (define-key gopher-directory-mode-map "\r" 'gopher-directory-choose)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 (define-key gopher-directory-mode-map " " 'gopher-directory-choose)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 (define-key gopher-directory-mode-map "l" 'gopher-last-node)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 (define-key gopher-directory-mode-map "q" 'gopher-last-node)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 (define-key gopher-directory-mode-map "u" 'gopher-last-node)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 (define-key gopher-directory-mode-map "=" 'gopher-directory-show-object)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 (define-key gopher-directory-mode-map "Q" 'gopher-quit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 (define-key gopher-directory-mode-map "f" 'gopher-directory-choose)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 (define-key gopher-directory-mode-map "e" 'gopher-directory-choose)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 ; Virginia Peck <vapeck@cs> Mon Aug 10 1992
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 (define-key gopher-directory-mode-map "n" 'next-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 (define-key gopher-directory-mode-map "p" 'previous-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 ;;(define-key gopher-directory-mode-map "\C-xk" 'gopher-last-node)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 ; Stewart Clamen <clamen@cs.cmu.edu> Mon Aug 17 1992
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 (define-key gopher-directory-mode-map "v" 'gopher-display-bookmarks)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 (define-key gopher-directory-mode-map "a" 'gopher-add-bookmark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 (define-key gopher-directory-mode-map "\C-k" 'gopher-delete-bookmark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 (define-key gopher-directory-mode-map "s" 'gopher-directory-save-bookmarks)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 (define-key gopher-directory-mode-map "\C-y" 'gopher-yank-bookmark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 (define-key gopher-directory-mode-map 'button2 'gopher-mouse-directory-choose)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 (define-key gopher-directory-mode-map 'button3 'gopher-directory-menu)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 (defvar gopher-directory-menu
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 '("Gopher Commands"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 ["Select This Link" gopher-directory-choose t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 ["Goto Last Node" gopher-last-node t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 ["Show Object Internals" gopher-directory-show-object t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 ["Quit" gopher-quit t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 (defun gopher-directory-menu (event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 (interactive "e")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 (mouse-set-point event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 (popup-menu gopher-directory-menu))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 (defun gopher-mouse-directory-choose (event arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726 (interactive "e\nP")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 (mouse-set-point event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 (gopher-directory-choose arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 (defun gopher-directory-nth-obj (n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 "Returns the Nth object (starting at 1) in a gopher directory buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 (if (or (<= n 0) (> n (length gopher-dir)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735 (error "Out of range."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 (aref gopher-dir (1- n)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 (defun gopher-directory-n (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 "Return the index of the object specified by ARG (starting at 1).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 If ARG is nil, this is the index of the current line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 Otherwise, it is the value of ARG (as a prefix argument)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743 (if arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744 (prefix-numeric-value arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 (if (eq (point) (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 (1+ (count-lines (point-min) (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 (count-lines (point-min) (1+ (point))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 (defun gopher-directory-obj (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 "Return the gopher object given by prefix arg ARG.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 If it is nil, return the object given by the line point is on.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 Otherwise, ARG is the index of the object."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 (gopher-directory-nth-obj (gopher-directory-n arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 (defun gopher-directory-choose (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758 "Choose an item from the directory, and do whatever is appropriate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759 based on the object's type. Default is to choose the object given by the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 line the cursor is on. With numeric prefix argument N, choose object N."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762 (gopher-dispatch-object (gopher-directory-obj arg) (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 (defun gopher-directory-show-object (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766 "Dump the internal information in a gopher object.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767 With numeric prefix argument N, show information about the Nth object."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769 (let* ((obj (gopher-directory-obj arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 (type (gopher-object-type obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 (typespec (assq type gopher-object-type-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 (typetag (if typespec (nth 1 typespec) "?"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 (typeproc (if typespec (nth 2 typespec) "?")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 (with-output-to-temp-buffer "*Gopher object*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 (princ (format "Type : %c `%s' %s\n" type typetag typeproc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 (princ (format "Description : %s\n" (gopher-object-descr obj)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 (princ (format "Selector : %s\n" (gopher-object-selector obj)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 (princ (format "Host : %s\n" (gopher-object-host obj)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779 (princ (format "Port : %s\n" (gopher-object-port obj)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 (current-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 (shrink-window-if-larger-than-buffer (get-buffer-window "*Gopher object*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784 ;; shrink-window-if-larger-than-buffer screws these up...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785 (set-buffer-modified-p nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786 (setq buffer-read-only t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789 (defun gopher-last-node nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790 "Return to the previous gopher node.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791 By convention, a gopher buffer has the local variable gopher-last which
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792 contains the buffer to which we should return."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794 (let ((oldbuf (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795 (if gopher-last
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797 (switch-to-buffer gopher-last)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798 (kill-buffer oldbuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799 (and (gopher-bookmark-directory-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800 (> gopher-bookmark-modified-tick gopher-bookmark-buffer-tick)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801 (let ((ppos (1- (gopher-directory-n nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802 (gopher-format-bookmarks)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803 (forward-line ppos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
804 (if (> (- (point-max) (point)) 7) (forward-char 7)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805 (if (and gopher-support-bookmarks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806 gopher-bookmarks-modified
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807 (y-or-n-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808 "Changes have been made to the Bookmark directory. Save? "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809 (gopher-save-bookmarks))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810 (kill-buffer oldbuf))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813 (defun gopher-directory-save-bookmarks ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814 "Save the bookmark list."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817 (if (not (gopher-bookmark-directory-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818 (error "This isn't the bookmark directory."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820 (gopher-save-bookmarks))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824 ;;; Gopher clean-up and quit.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 ;;; Originally from Thomas L|fgren <tde9104@abacus.hgs.se>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827 (defun gopher-quit nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828 "Quit gopher, and kill all gopher buffers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829 If there are unsaved changes to your bookmark directory, you will be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830 asked if you want to save them"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832 (if (y-or-n-p "Do you really want to kill all gopher buffers? ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
834 (if (and gopher-support-bookmarks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835 gopher-bookmarks-modified
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836 (y-or-n-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837 "Changes have been made to the Bookmark directory. Save? "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838 (gopher-save-bookmarks))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839 (let ((buflist (buffer-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840 (case-fold-search t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841 (while buflist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842 (if (eq (string-match "\\*gopher" (buffer-name (car buflist))) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843 (kill-buffer (car buflist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 (setq buflist (cdr buflist)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847 ;;;;--------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848 ;;;; bookmarks (Implemented originally by clamen@cs.cmu.edu)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849 ;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852 (defun gopher-read-bookmarks ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853 (cond ((null gopher-support-bookmarks))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854 ((or (equal gopher-support-bookmarks 'unix)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855 (equal gopher-support-bookmarks t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856 (setq gopher-bookmarks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857 (gopher-read-unix-bookmarks)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858 ((stringp gopher-support-bookmarks)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859 (gopher-read-lisp-bookmarks gopher-support-bookmarks))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
860 ((vectorp gopher-support-bookmarks)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
861 (setq gopher-bookmarks gopher-support-bookmarks))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
862 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
863 (message "Illformed gopher-bookmarks, assuming none"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
864
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
865
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
866 (defun gopher-read-unix-bookmarks ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
867 "Read bookmarks out of ~/.gopherrc file."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
868 (let ((rcfile "~/.gopherrc"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
869 (if (file-exists-p rcfile)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
870 (let* ((rcbuf (find-file-noselect rcfile))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
871 (bkmks (gopher-parse-bookmark-buffer rcbuf)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
872 (kill-buffer rcbuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
873 (setq gopher-bookmarks-modified nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
874 (setq gopher-bookmark-modified-tick
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
875 (1+ gopher-bookmark-modified-tick))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
876 bkmks)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
877 (message "No %s exists." rcfile)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
878 nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
879
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
880 (defun gopher-parse-bookmark-buffer (buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
881 "Read buffer containing bookmarks, formatted like ~.gopherrc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
882 in UNIX gopher client."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
883 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
884 (set-buffer buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
885 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
886 (if (re-search-forward "^bookmarks:\n" (point-max) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
887 (let (bkmk bkmks)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
888 (while (setq bkmk (gopher-parse-bookmark))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
889 (setq bkmks (cons bkmk bkmks)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
890 (apply 'vector (reverse bkmks))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
891
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
892 (defun gopher-parse-bookmark-line (regexp end setf bkmk)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
893 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
894 (if (re-search-forward regexp end t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
895 (eval (list setf bkmk
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
896 (buffer-substring (match-beginning 1) (match-end 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
897 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
898
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
899
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
900 (defun gopher-parse-bookmark ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
901 "Read next bookmark. Return a directory object."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
902 (if (looking-at "^#$")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
903 (forward-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
904 (if (not (eobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
905 (let ((end (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
906 (forward-line 5)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
907 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
908 (bkmk (make-vector 5 nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
909 (prog1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
910 (and (gopher-parse-bookmark-line "^Type *= *\\(.+\\) *$" end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
911 'gopher-set-object-type bkmk)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
912 (gopher-parse-bookmark-line "^Name *= *\\(.*\\) *$" end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
913 'gopher-set-object-descr bkmk)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
914 (gopher-parse-bookmark-line "^Path *= *\\(.*\\) *$" end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
915 'gopher-set-object-selector bkmk)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
916 (gopher-parse-bookmark-line "^Host *= *\\(.+\\) *$" end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
917 'gopher-set-object-host bkmk)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
918 (gopher-parse-bookmark-line "^Port *= *\\(.+\\) *$" end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
919 'gopher-set-object-port bkmk)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
920 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
921 (gopher-set-object-type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
922 bkmk (string-to-char (gopher-object-type bkmk)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
923 (gopher-set-object-port
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
924 bkmk (string-to-int (gopher-object-port bkmk)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
925 bkmk))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
926 (goto-char end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
927 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
928
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
929 (defun gopher-format-bookmarks ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
930 "Make the current buffer (which is assumed to be a bookmark buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
931 contain an up-to-date listing of the bookmark list."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
932
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
933 (let ((buffer-read-only nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
934 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
935 (setq gopher-dir gopher-bookmarks)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
936
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
937 ;; Format it for your viewing pleasure.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
938 (gopher-format-directory gopher-dir (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
939 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
940 (if (> (- (point-max) (point)) 7) (forward-char 7))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
941 (setq gopher-bookmark-buffer-tick gopher-bookmark-modified-tick)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
942
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
943 (defun gopher-display-bookmarks ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
944 "Retrieve and display the gopher bookmark directory."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
945 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
946
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
947 (if (> (length gopher-bookmarks) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
948 (let ((oldbuf (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
949 (dirbuf (gopher-get-dir-buf "*Gopher Bookmarks*")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
950
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
951 ;; Store our internal representation in gopher-dir.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
952 (switch-to-buffer dirbuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
953 (gopher-make-local-vars
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
954 'gopher-dir gopher-bookmarks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
955 'gopher-bookmark-directory-p t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
956 'gopher-bookmark-buffer-tick gopher-bookmark-modified-tick
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
957 'gopher-obj 'bookmark
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
958 'gopher-last oldbuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
959
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
960 (gopher-format-bookmarks)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
961
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
962 ;; Turn on directory mode and put the description in the mode line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
963 (gopher-directory-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
964 (setq mode-line-buffer-identification (concat "Gopher: *Bookmarks*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
965 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
966 (error "No bookmarks supported.")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
967
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
968
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
969 (defun gopher-save-bookmarks ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
970 "Save bookmarks."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
971 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
972 ((or (equal gopher-support-bookmarks 'unix)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
973 (equal gopher-support-bookmarks t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
974 (gopher-save-unix-bookmarks))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
975 ((stringp gopher-support-bookmarks)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
976 (gopher-save-lisp-bookmarks gopher-support-bookmarks))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
977 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
978 (message "Illformed gopher-support-bookmarks, assuming none")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
979
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
980 (setq gopher-bookmarks-modified nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
981
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
982
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
983 (defun gopher-save-unix-bookmarks ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
984 "Save bookmarks out to ~/.gopherrc file."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
985 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
986 (let* ((rcfile "~/.gopherrc")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
987 (new-file-p (not (file-exists-p rcfile)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
988 (rcbuf (find-file-noselect rcfile)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
989 (set-buffer rcbuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
990 (if new-file-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
991 (insert "bookmarks:\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
992 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
993 (if (re-search-forward "^bookmarks:\n" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
994 (delete-region (point) (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
995 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
996 (insert "bookmarks:\n")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
997
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
998 ;; Now, insert defined bookmarks into file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
999
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1000 (let ((obj-count 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1001 (while (< obj-count (length gopher-bookmarks))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1002 (let ((obj (aref gopher-bookmarks obj-count)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1003 (insert "#"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1004 "\nType=" (gopher-object-type obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1005 "\nName=" (gopher-object-descr obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1006 "\nPath=" (gopher-object-selector obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1007 "\nHost=" (gopher-object-host obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1008 "\nPort=" (int-to-string (gopher-object-port obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1009 "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1010 (setq obj-count (1+ obj-count)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1011
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1012 (write-file rcfile))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1013
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1014
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1015 (defun gopher-add-bookmark (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1016 "Add current object to menu of bookmarks.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1017 With numeric prefix argument N, add Nth object."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1018 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1019 (if (gopher-bookmark-directory-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1020 (error "That item is already a bookmark!")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1021 (let ((existing-bookmarks gopher-bookmarks)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1022 (new-bookmarks (make-vector (1+ (length gopher-bookmarks)) nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1023 (obj (copy-sequence (gopher-directory-obj arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1024 (l (length gopher-bookmarks)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1025 (gopher-set-object-descr
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1026 obj
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1027 (read-from-minibuffer "Node Name: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1028 (gopher-object-descr obj)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1029 (aset new-bookmarks l obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1030 (while (> l 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1031 (progn (setq l (1- l))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1032 (aset new-bookmarks l (aref existing-bookmarks l))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1033 (setq gopher-bookmarks new-bookmarks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1034 gopher-bookmarks-modified t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1035 gopher-bookmark-modified-tick (1+ gopher-bookmark-modified-tick))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1036 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1037
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1038
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1039 (defun gopher-delete-bookmark (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1040 "Delete current bookmark.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1041 With numeric prefix argument N, delete Nth bookmark."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1042 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1043 (if (not (gopher-bookmark-directory-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1044 (error "Can only delete object in Bookmark directory.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1045 (let ((new-bookmarks (make-vector (1- (length gopher-bookmarks)) nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1046 (pos (1- (gopher-directory-n arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1047 (l (length gopher-bookmarks))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1048 (i 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1049 (while (< i pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1050 (progn (aset new-bookmarks i (aref gopher-bookmarks i))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1051 (setq i (1+ i))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1052 (while (< i (1- l))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1053 (progn (aset new-bookmarks i (aref gopher-bookmarks (1+ i)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1054 (setq i (1+ i))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1055 (setq gopher-killed-bookmark (aref gopher-bookmarks pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1056 gopher-bookmarks new-bookmarks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1057 gopher-dir new-bookmarks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1058 gopher-bookmarks-modified t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1059 gopher-bookmark-modified-tick (1+ gopher-bookmark-modified-tick))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1060 (let ((ppos (1- (gopher-directory-n nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1061 (if (< pos ppos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1062 (setq ppos (1- ppos)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1063 (gopher-format-bookmarks)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1064 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1065 (forward-line ppos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1066 (forward-char 7)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1067 (if (= (point) (point-max)) (previous-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1068 ; (let ((buffer-read-only nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1069 ; (beginning-of-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1070 ; (kill-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1071 ; (if (= (point) (point-max)) (previous-line 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1072 (if (zerop (length gopher-bookmarks))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1073 (gopher-last-node))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1074
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1075
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1076 (defun gopher-yank-bookmark (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1077 "Yank the most recently killed bookmark at the current position.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1078 With numeric prefix argument N, yank into position N."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1079 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1080 (cond ((not (gopher-bookmark-directory-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1081 (error "Can only yank bookmark objects into bookmark directory."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1082 ((null gopher-killed-bookmark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1083 (error "No killed bookmark object"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1084 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1085 (let* ((len (length gopher-bookmarks))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1086 (new-bookmarks (make-vector (1+ len) nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1087 (pos (1- (gopher-directory-n arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1088 i)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1089
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1090 (if (or (< pos 0) (> pos (length gopher-bookmarks)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1091 (error "Out of range."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1092
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1093 (setq i (1- pos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1094 (while (>= i 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1095 (aset new-bookmarks i (aref gopher-bookmarks i))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1096 (setq i (1- i)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1097
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1098 (aset new-bookmarks pos gopher-killed-bookmark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1099
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1100 (setq i pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1101 (while (< i len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1102 (aset new-bookmarks (1+ i) (aref gopher-bookmarks i))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1103 (setq i (1+ i)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1104
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1105 (setq gopher-bookmarks new-bookmarks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1106 gopher-bookmarks-modified t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1107 gopher-killed-bookmark nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1108 gopher-bookmark-modified-tick
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1109 (1+ gopher-bookmark-modified-tick))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1110
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1111 (let ((ppos (1- (gopher-directory-n nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1112 (if (<= pos ppos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1113 (setq ppos (1+ ppos)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1114 (gopher-format-bookmarks)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1115 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1116 (forward-line ppos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1117 (forward-char 7))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1118 ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1119
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1120
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1121 (defun gopher-bookmark-directory-p ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1122 "Return T if currently displaying Bookmark directory."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1123 gopher-bookmark-directory-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1124 ; (equal gopher-dir gopher-bookmarks))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1125
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1126
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1127 (defun gopher-read-lisp-bookmarks (fn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1128 "currently unsupported"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1129 (error "gopher-read-lisp-bookmark is not yet supported. Sorry."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1130
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1131 (defun gopher-save-lisp-bookmarks (fn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1132 "currently unsupported"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1133 (error "gopher-save-lisp-bookmark is not yet supported. Sorry."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1134
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1135
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1136
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1137 ;;;;--------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1138 ;;;; gopher documents
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1139 ;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1140
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1141
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1142 (defun gopher-document-object (obj oldbuf &optional end-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1143 "Retrieve and display a gopher document.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1144 Optional argument END-REGEXP is used if the data will not be ended by `.'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1145
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1146 (let ((docbuf (gopher-get-doc-buf (gopher-object-descr obj))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1147
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1148 ;; Snarf the data into the buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1149 (gopher-retrieve-document-cleanly (docbuf
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1150 (gopher-object-selector obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1151 (gopher-object-host obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1152 (gopher-object-port obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1153 end-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1154
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1155 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1156 (kill-buffer docbuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1157 (error "Problems retrieving document."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1158
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1159 ;; Turn on document mode and put the description in the mode line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1160 (switch-to-buffer docbuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1161 (gopher-make-local-vars
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1162 'gopher-obj obj
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1163 'gopher-last oldbuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1164 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1165 (gopher-document-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1166 (setq mode-line-buffer-identification (concat "Gopher: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1167 (gopher-object-descr obj)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1168 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1169
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1170
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1171 ;; keymap for document mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1172 (suppress-keymap gopher-document-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1173
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1174 ;Virginia Peck <vapeck@cs> Mon Aug 10 21:44:35 1992
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1175 ;;(define-key gopher-document-mode-map "\C-xk" 'gopher-last-node)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1176
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1177 (define-key gopher-document-mode-map "l" 'gopher-last-node)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1178 (define-key gopher-document-mode-map "q" 'gopher-last-node)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1179 (define-key gopher-document-mode-map "u" 'gopher-last-node)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1180 (define-key gopher-document-mode-map " " 'scroll-up)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1181 (define-key gopher-document-mode-map "\C-?" 'scroll-down)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1182 (define-key gopher-document-mode-map "\r" 'gopher-scroll-one-line-up)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1183
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1184
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1185 (defun gopher-document-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1186 "Gopher document mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1187
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1188 \\{gopher-document-mode-map}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1189 "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1190 (use-local-map gopher-document-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1191 (setq major-mode 'gopher-document-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1192 (setq mode-name "gopher doc")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1193 (run-hooks 'gopher-document-mode-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1194 (setq buffer-read-only t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1195
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1196
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1197 ;; from gosmacs.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1198 (defun gopher-scroll-one-line-up (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1199 "Scroll the selected window up (forward in the text) one line (or N lines)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1200 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1201 (scroll-up (or arg 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1202
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1203
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1204 ;;;;--------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1205 ;;;; CSO handling.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1206 ;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1207 ;;;; uses a subset of forms mode to handle data entry.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1208 ;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1209
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1210 (defun gopher-cso-object (obj oldbuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1211 "Display a CSO lookup form."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1212
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1213 ;; The following will create a buffer displaying the form described
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1214 ;; by the list in the last argument (cf. forms-mode). When the user
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1215 ;; accepts the data in the form (by pressing `C-c RET'), the function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1216 ;; gopher-do-cso will be called with the data the user supplied.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1217 (gopher-form (gopher-object-descr obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1218 'gopher-do-cso
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1219 4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1220 '("====== phone directory lookup ======"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1221 "\n Press `C-c RET' to lookup, `C-c l' to return to the last gopher object."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1222 "\n (you must fill in at least one of the first three fields)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1223 "\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1224 "Name : " 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1225 "\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1226 "Phone : " 2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1227 "\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1228 "E-Mail : " 3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1229 "\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1230 "Address : " 4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1231 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1232
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1233 ;; Record gopher-last so gopher-last-node knows where to go.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1234 ;; Record gopher-obj so gopher-do-cso knows what server to query.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1235 (gopher-make-local-vars
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1236 'gopher-last oldbuf
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1237 'gopher-obj obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1238
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1239
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1240 (defconst gopher-cso-fields '("name" "phone" "email" "address")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1241 "Field names to use in CSO queries.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1242
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1243 (defun gopher-do-cso (vals)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1244 "Make a CSO query. VALS is the data the user entered in the form,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1245 as a list of strings."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1246
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1247 ;; Check that the required data was provided.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1248 (if (zerop (+ (length (nth 0 vals))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1249 (length (nth 1 vals))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1250 (length (nth 2 vals))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1251 (error "Must specify name, phone, or email."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1252
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1253 (let ((query "query")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1254 (fields gopher-cso-fields)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1255 (obj gopher-obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1256
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1257 ;; Form the query string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1258 (while vals
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1259
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1260 (if (not (zerop (length (car vals))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1261 (setq query (concat query " " (car fields) "=" (car vals))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1262
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1263 (setq vals (cdr vals))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1264 (setq fields (cdr fields)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1265
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1266 ;; Use this string as the object selector.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1267 (gopher-set-object-selector gopher-obj query)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1268
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1269 ;; Retrieve the data from the server. Unlike gopher, the CSO data
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1270 ;; does not use `.' as a terminator.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1271 (gopher-document-object gopher-obj (current-buffer) "^[2-9]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1272
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1273 ;; Strip CSO control information from the buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1274 (gopher-clean-cso-buffer obj)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1275
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1276
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1277 (defun gopher-clean-cso-buffer (obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1278 "Strip CSO control information from the current buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1279
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1280 (let ((req "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1281 (buffer-read-only nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1282 beg nreq)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1283 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1284 (insert "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1285 (while (not (eobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1286 (cond ((and (>= (following-char) ?3) (<= (following-char) ?9))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1287 (delete-char 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1288 (insert (concat (gopher-object-selector obj) "\n")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1289
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1290 ((eq (following-char) ?-)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1291 (delete-char 5)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1292 (setq beg (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1293 (skip-chars-forward "^:")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1294 (setq nreq (buffer-substring beg (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1295 (goto-char beg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1296 (or (string= req nreq)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1297 (insert (concat "--------------------------"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1298 "-----------------------------\n")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1299 (setq req nreq)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1300 (setq beg (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1301 (skip-chars-forward "^:")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1302 (forward-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1303 (delete-region beg (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1304
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1305 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1306 (setq beg (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1307 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1308 (delete-region beg (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1309 (forward-line -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1310 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1311 (forward-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1312
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1313 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1314 (delete-char 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1315
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1316
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1317 ;;;;--------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1318 ;;;; indices.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1319 ;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1320 ;;;; To query an index, the search string is appended to the selector.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1321 ;;;; The index returns a gopher directory.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1322 ;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1323
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1324
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1325 (defun gopher-index-object (obj oldbuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1326 "Query a gopher directory object."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1327
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1328 ;; Get the search string from the user.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1329 (let ((str (read-from-minibuffer "Key: "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1330 (newobj (copy-sequence obj)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1331
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1332 ;; Append it to the selector and retrieve the modified object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1333 ;; like a directory.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1334 (setq str (gopher-trim-blanks str))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1335 (if (> (length str) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1336 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1337 (gopher-set-object-selector newobj
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1338 (concat (gopher-object-selector obj) "\t"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1339 str))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1340 (gopher-directory-object newobj (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1341 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1342
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1343
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1344
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1345 ;;;;--------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1346 ;;;; telneting.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1347 ;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1348
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1349 (defun gopher-telnet-object (obj oldbuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1350 "Start a telnet session to a gopher object.
108
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 70
diff changeset
1351 If gopher-telnet-command is non-nil, then that is a command to start
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1352 a telnet session in a subprocess. Otherwise, the emacs-lisp telnet
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1353 package is used."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1354
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1355 ;; make the telnet argument string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1356 (let ((arg (gopher-object-host obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1357 (port (gopher-object-port obj)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1358 (if (not (zerop port))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1359 (setq arg (concat arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1360 (if (eq system-type 'vax-vms)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1361 "/port="
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1362 " ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1363 port)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1364
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1365 (if gopher-telnet-command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1366
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1367 ;; start up telnet as a separate process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1368 (save-window-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1369 (gopher-background
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1370 (concat gopher-telnet-command " " arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1371
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1372 ;; use telnet-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1373 (telnet arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1374 ;; set things up so we can get back to the last node.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1375 (gopher-make-local-vars
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1376 'gopher-obj obj
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1377 'gopher-last oldbuf
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1378 'gopher-telnet-process-name (concat arg "-telnet"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1379 (local-set-key "\C-cl" 'gopher-telnet-quit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1380 (local-set-key "\C-xk" 'gopher-telnet-quit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1381 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1382
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1383 ;; show the login info to the user
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1384 (if (not (zerop (length (gopher-object-selector obj))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1385 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1386 (beep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1387 (message (concat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1388 "Login as: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1389 (gopher-object-selector obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1390 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1391 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1392 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1393
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1394
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1395 (defun gopher-telnet-quit nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1396 "Clean up a telnet session and return to the previous gopher node."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1397 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1398 (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1399 (delete-process gopher-telnet-process-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1400 (error t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1401 (gopher-last-node))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1402
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1403
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1404
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1405 ;;;;--------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1406 ;;;; Images/sounds.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1407 ;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1408
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1409 (defun gopher-image-object (obj oldbuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1410 "Retrieve what we hope is an image and show it."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1411 (let (
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1412 (showit (y-or-n-p "Display this item? "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1413 (fname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1414 (buf (gopher-get-doc-buf (gopher-object-descr obj))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1415 (if showit
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1416 (setq fname (make-temp-name "/tmp/gopherimg"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1417 (setq fname(read-file-name "File to save in: ")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1418 (gopher-retrieve-document-cleanly (buf
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1419 (gopher-object-selector obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1420 (gopher-object-host obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1421 (gopher-object-port obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1422 'none)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1423 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1424 (error "Problems retrieving object.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1425 (kill-buffer buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1426
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1427 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1428 (set-buffer buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1429 (write-file fname))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1430 (kill-buffer buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1431 (if (and showit gopher-image-display-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1432
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1433 ;; Spawn a process to display the image.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1434 ;; But modify its sentinel so that the file we wrote
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1435 ;; will get deleted when the process exits.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1436 (save-window-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1437 (let ((p (gopher-background
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1438 (concat gopher-image-display-command " " fname))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1439 (set-process-sentinel p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1440 (` (lambda (process msg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1441 ((, (process-sentinel p)) process msg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1442 (if (not (eq (process-status process) 'run))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1443 (delete-file (, fname)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1444 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1445 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1446 ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1447
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1448
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1449
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1450 ;;;;--------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1451 ;;;; Various opaque objects. Just save them in a file for now.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1452 ;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1453
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1454 (defun gopher-binary-object (obj oldbuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1455 "Retrieve a gopher object and save it to a file,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1456 without trying to interpret it in any way."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1457 (let ((fname (read-file-name "File to save in: "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1458 (buf (gopher-get-doc-buf (gopher-object-descr obj))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1459
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1460 (gopher-retrieve-document-cleanly (buf
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1461 (gopher-object-selector obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1462 (gopher-object-host obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1463 (gopher-object-port obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1464 'none)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1465
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1466 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1467 (error "Problems retrieving object.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1468 (kill-buffer buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1469
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1470 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1471 (set-buffer buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1472 (write-file fname))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1473 (kill-buffer buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1474 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1475
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1476
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1477 ;;;;--------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1478 ;;;; forms stuff
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1479 ;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1480 ;;;; Uses some of the internal routines from forms.el to present
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1481 ;;;; a form which is not associated with a file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1482 ;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1483
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1484 (defun gopher-form (form-name accept-action number-of-fields format-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1485 "Display a buffer containing a form for the user to enter data.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1486 The form is described by NUMBER-OF-FIELDS and FORMAT-LIST (cf. forms-mode).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1487 FORM-NAME is a string to put in the modeline.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1488 When the user accepts the data in the form by pressing `C-c RET', the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1489 function ACCEPT-ACTION is called with a list of the strings which
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1490 the user entered."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1491
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1492 (switch-to-buffer (generate-new-buffer "*gopher form*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1493
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1494 (gopher-make-local-vars
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1495 'forms-format-list format-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1496 'forms-number-of-fields number-of-fields
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1497 'forms-field-sep "\t"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1498 'forms-read-only nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1499 'forms-multi-line nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1500 'forms--number-of-markers nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1501 'forms--markers nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1502 'forms--format nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1503 'forms--parser nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1504 'forms--dynamic-text nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1505 'forms-fields nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1506 'forms-the-record-list nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1507 'forms-accept-action accept-action
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1508 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1509
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1510 (forms--process-format-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1511 (forms--make-format)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1512 (forms--make-parser)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1513
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1514 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1515
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1516 ;; make local variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1517 (make-local-variable 'forms--file-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1518 (make-local-variable 'forms--total-records)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1519 (make-local-variable 'forms--current-record)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1520 (make-local-variable 'forms--the-record-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1521 (make-local-variable 'forms--search-rexexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1522
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1523 ;; set the major mode indicator
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1524 (setq major-mode 'gopher-form-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1525 (setq mode-name "gopher form")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1526
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1527 (set-buffer-modified-p nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1528
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1529 (use-local-map gopher-form-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1530
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1531 (forms--show-record (make-string (1- number-of-fields) ?\t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1532
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1533 (run-hooks 'gopher-form-mode-hooks))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1534
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1535
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1536 (defun gopher-form-accept nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1537 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1538
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1539 (funcall forms-accept-action (forms--parse-form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1540
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1541 (define-key gopher-form-mode-map "\C-c\r" 'gopher-form-accept)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1542 (define-key gopher-form-mode-map "\C-cl" 'gopher-last-node)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1543
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1544
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1545 ;;;;--------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1546 ;;;; low-level communications routines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1547 ;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1548
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1549
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1550 (defun gopher-retrieve-document (buf sel host port &optional end-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1551 "Retrieve a gopher object into BUF.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1552 The object is identified by a SEL HOST PORT triple.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1553 Optional argument END-REGEXP is used for data which is not `.'-terminated.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1554 If END-REGEXP is non-nil and not a string, then it is assumed that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1555 the data is binary, and reading will continue until the sender disconnects.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1556 Returns NIL if an error occured during the attempt to retrieve the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1557 document, otherwise T.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1558 "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1559
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1560 ;; Default is single period termination.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1561 (or end-regexp (setq end-regexp "^\\.\r$"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1562
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1563 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1564 (set-buffer buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1565 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1566
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1567 (let ((h (assoc host gopher-hostname-aliases)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1568 (if h (setq host (cdr h))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1569
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1570 ;; Open the connection to the server.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1571 ;; If we get an unknown service error, try looking the port up in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1572 ;; gopher-port-aliases. If we find it there, try the connect again
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1573 ;; with that translation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1574 (let (wait
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1575 (gopher-server-process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1576 (let (p (try-again t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1577 (while try-again
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1578 (setq try-again nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1579 (condition-case errinfo
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1580 (setq p (open-network-stream "gopher" (current-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1581 host port))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1582 (error (if (and (string-match "^Unknown service .*$"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1583 (nth 1 errinfo))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1584 (setq port (cdr (assoc port
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1585 gopher-port-aliases))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1586 (setq try-again t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1587 (ding)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 30
diff changeset
1588 (message "%s: %s" (nth 0 errinfo) (nth 1 errinfo))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1589 ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1590 p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1591
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1592 (cond (gopher-server-process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1593
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1594 ;; keep the emacs end-of-process status line out of the buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1595 (set-process-sentinel gopher-server-process 'gopher-sentinel)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1596
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1597 ;; send the selector to the server
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1598 (process-send-string gopher-server-process (concat sel "\r\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1599
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1600 ;; receive the response from the server
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1601 ;; based on nntp.el from GNUS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1602 (setq wait t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1603 (while wait
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1604 (if (stringp end-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1605 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1606 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1607 (forward-line -1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1608 (if (and (stringp end-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1609 (looking-at end-regexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1610 (setq wait nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1611 (if (not (memq (process-status gopher-server-process)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1612 '(open run)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1613 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1614 (message "gopher: connection closed")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1615 (setq wait nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1616 (if gopher-debug-read
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1617 (message "gopher: Reading..."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1618 (cond (gopher-buggy-accept
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1619 (sit-for 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1620 ((and (boundp 'epoch::version) epoch::version)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1621 (accept-process-output gopher-server-process 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1622 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1623 (accept-process-output gopher-server-process))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1624 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1625 (if gopher-debug-read
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1626 (message " ")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1627 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1628
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1629 ;; be sure the net connection has gone away...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1630 (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1631 (delete-process gopher-server-process)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1632 (error t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1633
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1634 ;; clean up the text buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1635 (if (stringp end-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1636 (gopher-clean-text))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1637
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1638 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1639
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1640 (t nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1641 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1642
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1643
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1644 ;;; adapted from GNUS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1645 (defun gopher-clean-text ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1646 "Decode text transmitted by gopher.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1647 0. Delete status line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1648 1. Delete `^M' at end of line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1649 2. Delete `.' at end of buffer (end of text mark).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1650 3. Delete `.' at beginning of line. (does gopher want this?)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1651
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1652 ;; Insert newline at end of buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1653 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1654 (if (not (bolp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1655 (insert "\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1656 ;; Delete `^M' at end of line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1657 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1658 (while (re-search-forward "\r[^\n]*$" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1659 (replace-match ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1660 ; (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1661 ; (while (not (eobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1662 ; (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1663 ; (if (= (preceding-char) ?\r)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1664 ; (delete-char -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1665 ; (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1666 ; )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1667 ;; Delete `.' at end of buffer (end of text mark).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1668 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1669 (forward-line -1) ;(beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1670 (while (looking-at "^\\.$")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1671 (delete-region (point) (progn (forward-line 1) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1672 (forward-line -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1673 ;; Replace `..' at beginning of line with `.'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1674 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1675 ;; (replace-regexp "^\\.\\." ".")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1676 (while (search-forward "\n.." nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1677 (delete-char -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1678 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1679
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1680
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1681 (defun gopher-sentinel (proc status)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1682 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1683
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1684 (provide 'gopher)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1685
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1686 ;;; gopher.el ends here
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1687
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1688 ;;;(gopher.el) Local Variables:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1689 ;;;(gopher.el) eval: (put 'gopher-retrieve-document-cleanly 'lisp-indent-hook 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1690 ;;;(gopher.el) End:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1691