annotate lisp/ilisp/ilisp-cmp.el @ 4:b82b59fe008d r19-15b3

Import from CVS: tag r19-15b3
author cvs
date Mon, 13 Aug 2007 08:46:56 +0200
parents 376386a54a3c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; -*- Mode: Emacs-Lisp -*-
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;;; ilisp-cmp.el --
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;;; This file is part of ILISP.
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
6 ;;; Version: 5.8
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;;; Copyright (C) 1990, 1991, 1992, 1993 Chris McConnell
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;;; 1993, 1994 Ivan Vasquez
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
10 ;;; 1994, 1995, 1996 Marco Antoniotti and Rick Busdiecker
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
11 ;;; 1996 Marco Antoniotti and Rick Campbell
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;;; Other authors' names for which this Copyright notice also holds
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;;; may appear later in this file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;;;
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
16 ;;; Send mail to 'ilisp-request@naggum.no' to be included in the
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
17 ;;; ILISP mailing list. 'ilisp@naggum.no' is the general ILISP
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;;; mailing list were bugs and improvements are discussed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;;; ILISP is freely redistributable under the terms found in the file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;;; COPYING.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;;; ILISP completion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;;;%Completion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;;; The basic idea behind the completion stuff is to use as much of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;;; the standard Emacs stuff as possible. The extensions here go out
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;;; to the inferior LISP to complete symbols if necessary.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 (defun ilisp-display-choices (symbol choices)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 "Display the possible choices for SYMBOL in alist CHOICES."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 (with-output-to-temp-buffer "*Completions*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 (display-completion-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 (sort
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 (all-completions (lisp-symbol-name symbol) choices)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 'string-lessp))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 ;;;%%ilisp-can-complete
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 (defun ilisp-can-complete (symbol function-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 "Return T if ilisp completion can complete SYMBOL from the current table."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 (and ilisp-original
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 (string= (lisp-symbol-package ilisp-original)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (lisp-symbol-package symbol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 (string= (lisp-symbol-delimiter ilisp-original)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 (lisp-symbol-delimiter symbol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (lisp-prefix-p (lisp-symbol-name ilisp-original)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 (lisp-symbol-name symbol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 (eq function-p ilisp-original-function-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ;;;%%ilisp-complete
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 (defun ilisp-complete (symbol &optional function-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 "Return a list of the possible completions for symbol from the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 inferior LISP. If FUNCTION-P is T, only symbols with function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 bindings will be considered. If no package is specified the buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 package will be used."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (let* ((choices
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (ilisp-send
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 (format (ilisp-value 'ilisp-complete-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 (lisp-symbol-name symbol) (lisp-symbol-package symbol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 function-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (string= (lisp-symbol-delimiter symbol) ":")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 ilisp-prefix-match)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (if (not ilisp-complete)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (concat "Complete "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (if function-p "function ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (lisp-buffer-symbol symbol)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 'complete)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (if (ilisp-value 'comint-errorp t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (progn (lisp-display-output choices)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (error "Error completing %s" (lisp-buffer-symbol symbol)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (setq choices (read choices)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 choices (if (eq choices 'NIL) nil choices)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (setq ilisp-original symbol
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 ilisp-original-function-p function-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 ilisp-original-table choices)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 ;;;%%ilisp-completion-table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (defun ilisp-completion-table (symbol function-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 "Return the completion table for SYMBOL trying to use the current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 one. If FUNCTION-P is T, only symbols with function cells will be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 returned."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (if (ilisp-can-complete symbol function-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 ilisp-original-table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (ilisp-complete symbol function-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 ;;;%%Minibuffer completion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (defun ilisp-restore-prefix ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 "Restore the prefix from ilisp-mini-prefix at the start of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 minibuffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (if ilisp-mini-prefix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (insert ilisp-mini-prefix)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (setq ilisp-mini-prefix nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (defun ilisp-current-choice ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 "Set up the minibuffer completion table for the current symbol.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 If there is a paren at the start of the minibuffer, or there is not an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 ilisp-table, this will be from the inferior LISP. Otherwise, it will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 be the ilisp-table."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (if (or (null ilisp-table) (eq (char-after 1) ?\())
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (let* ((symbol-info (lisp-previous-symbol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (symbol (car symbol-info)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (setq minibuffer-completion-table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (ilisp-completion-table symbol ilisp-completion-function-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (skip-chars-backward "^: \(")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (setq ilisp-mini-prefix (buffer-substring (point-min) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (delete-region (point-min) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 ;; Nothing can match this table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (if (not minibuffer-completion-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (setq minibuffer-completion-table '((" ")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (setq minibuffer-completion-table ilisp-table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 minibuffer-completion-predicate nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 ;;;%%Commands
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (defvar ilisp-completion-help
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (lookup-key minibuffer-local-must-match-map "?"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (defun ilisp-completion-help ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 "Inferior LISP minibuffer completion help."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (ilisp-current-choice)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (funcall ilisp-completion-help)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (ilisp-restore-prefix))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (defvar ilisp-completion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (lookup-key minibuffer-local-must-match-map "\t"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (defun ilisp-completion ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 "Inferior LISP minibuffer complete."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (ilisp-current-choice)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (funcall ilisp-completion)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (ilisp-restore-prefix))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (defvar ilisp-completion-word
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (lookup-key minibuffer-local-must-match-map " "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (defun ilisp-completion-word ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 "Inferior LISP minibuffer complete word."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (if (eq (char-after 1) ?\()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (insert " ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (ilisp-current-choice)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (funcall ilisp-completion-word)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (ilisp-restore-prefix)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (defun ilisp-completion-paren ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 "Only allow a paren if ilisp-paren is T."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (if ilisp-paren
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (if (or (eq last-input-char ?\() (eq (char-after 1) ?\())
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 (insert last-input-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (beep))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 (beep)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (defvar ilisp-completion-exit
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (lookup-key minibuffer-local-must-match-map "\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (defun ilisp-completion-exit ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 "Inferior LISP completion complete and exit."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (if (eq (char-after 1) ?\()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (progn (find-unbalanced-lisp nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (exit-minibuffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (if ilisp-no-complete
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (exit-minibuffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (if (= (point-min) (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 (exit-minibuffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 (ilisp-current-choice)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (unwind-protect (funcall ilisp-completion-exit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (ilisp-restore-prefix))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 ;;;%%ilisp-completer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 (defun ilisp-completer (symbol function-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 "Complete SYMBOL from the inferior LISP using only function symbols
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 if FUNCTION-P is T. Return (SYMBOL LCS-SYMBOL CHOICES UNIQUEP)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 (let* ((name (lisp-symbol-name symbol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (table (ilisp-completion-table symbol function-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (choice (and table (try-completion name table))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 (cond ((eq choice t) ;Name is it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (list symbol symbol nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 ((string= name choice) ;Name is LCS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 (list symbol symbol (all-completions name table) nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 (choice ;New LCS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (let ((symbol
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (lisp-symbol (lisp-symbol-package symbol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (lisp-symbol-delimiter symbol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 choice)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 (list symbol symbol (all-completions choice table) nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 ((and (not ilisp-prefix-match) table) ;Try partial matches
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 (let ((matches
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (completer name table nil (regexp-quote completer-words))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (cons (lisp-symbol (lisp-symbol-package symbol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 (lisp-symbol-delimiter symbol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (car matches))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 (cons (lisp-symbol (lisp-symbol-package symbol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (lisp-symbol-delimiter symbol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 (car (cdr matches)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (cdr (cdr matches)))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 ;;;%%ilisp-read
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (defun ilisp-completion-map ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 "Set up the ilisp-completion-map from lisp-mode-map for the ilisp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 readers and return it."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (if (not ilisp-completion-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 (if (fboundp 'set-keymap-parent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 (setq ilisp-completion-map (make-sparse-keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 (set-keymap-parent ilisp-completion-map lisp-mode-map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (setq ilisp-completion-map (copy-keymap lisp-mode-map)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 (define-key ilisp-completion-map " " 'ilisp-completion-word)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 (define-key ilisp-completion-map "\t" 'ilisp-completion)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 (define-key ilisp-completion-map "?" 'ilisp-completion-help)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (define-key ilisp-completion-map "\M-\t" 'ilisp-completion)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (define-key ilisp-completion-map "\n" 'ilisp-completion-exit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 (define-key ilisp-completion-map "\r" 'ilisp-completion-exit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (define-key ilisp-completion-map "\C-g" 'abort-recursive-edit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (define-key ilisp-completion-map "(" 'ilisp-completion-paren)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 (define-key ilisp-completion-map ")" 'ilisp-completion-paren)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 (define-key ilisp-completion-map "'" nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (define-key ilisp-completion-map "#" nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (define-key ilisp-completion-map "\"" nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 ilisp-completion-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (defun ilisp-read (prompt &optional initial-contents)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 "PROMPT in the minibuffer with optional INITIAL-CONTENTS and return
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 the result. Completion of symbols though the inferior LISP is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 allowed."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (let ((ilisp-complete t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (ilisp-paren t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 (ilisp-no-complete t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (ilisp-completion-package (lisp-buffer-package)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (read-from-minibuffer prompt initial-contents
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 (ilisp-completion-map))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 ;;;%%lisp-read-program
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 (defvar lisp-program-map nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 "Minibuffer map for reading a program and arguments.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 (defun lisp-read-program (prompt &optional initial)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 "Read a program with PROMPT and INITIAL. TAB or Esc-TAB will complete
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 filenames."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (if (null lisp-program-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 (if (fboundp 'set-keymap-parent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (setq lisp-program-map (make-sparse-keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 (set-keymap-parent lisp-program-map minibuffer-local-map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (setq lisp-program-map (copy-keymap minibuffer-local-map)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (define-key lisp-program-map "\M-\t" 'comint-dynamic-complete)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 (define-key lisp-program-map "\t" 'comint-dynamic-complete)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (define-key lisp-program-map "?" 'comint-dynamic-list-completions)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 (read-from-minibuffer prompt initial lisp-program-map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 ;;;%%ilisp-read-symbol
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (defun ilisp-read-symbol (prompt &optional default function-p no-complete)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 "PROMPT in the minibuffer with optional DEFAULT and return a symbol
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 from the inferior LISP. If FUNCTION-P is T, only symbols with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 function values will be returned. If NO-COMPLETE is T, then
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 uncompleted symbols will be allowed."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 (let* ((ilisp-complete t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 (ilisp-no-complete no-complete)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 (ilisp-completion-package (lisp-buffer-package))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (ilisp-completion-function-p function-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 (string (read-from-minibuffer prompt nil (ilisp-completion-map))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 (if (equal string "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 (lisp-string-to-symbol string))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 ;;;%%ilisp-completing-read
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 (defun ilisp-completing-read (prompt table &optional default)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 "Read with PROMPT from an alist of TABLE. No input returns DEFAULT.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 Symbols are from table, other specs are in parentheses."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 (let* ((ilisp-complete t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 (ilisp-table table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 (ilisp-completion-package (lisp-buffer-package))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 (ilisp-paren
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 (let ((entry table) (done nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 (while (and entry (not done))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 (setq done (= (elt (car (car entry)) 0) ?\()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 entry (cdr entry)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 done))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 (string (read-from-minibuffer prompt nil (ilisp-completion-map))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 (if (string= string "") default string)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 ;;;%%complete-lisp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 (autoload 'complete "completion" "Complete previous symbol." t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 (defun complete-lisp (mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 "Complete the current symbol using information from the current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 ILISP buffer. If in a string, complete as a filename. If called with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 a positive prefix force all symbols to be considered. If called with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 a negative prefix, undo the last completion. Partial completion is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 allowed unless ilisp-prefix-match is T. If a symbol starts after a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 left paren or #', then only function symbols will be considered.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 Package specifications are also allowed and the distinction between
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 internal and exported symbols is considered."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 (if (< (prefix-numeric-value mode) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 (completer-undo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 (let* ((filep
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 (skip-chars-backward "^ \t\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 (= (char-after (point)) ?\"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 (if filep
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 (comint-dynamic-complete)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 (let* ((symbol-info (lisp-previous-symbol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 (symbol (car symbol-info))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 (name (lisp-symbol-name symbol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 (choice (ilisp-completer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 symbol
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 (if (not mode) (car (cdr symbol-info)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 (match (lisp-buffer-symbol (car choice)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 (lcs (lisp-buffer-symbol (car (cdr choice))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 (choices (car (cdr (cdr choice))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 (unique (car (cdr (cdr (cdr choice))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 (skip-chars-backward " \t\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 (completer-goto match lcs choices unique
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 (ilisp-value 'ilisp-symbol-delimiters)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 completer-words)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 (message "Completed"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335