0
|
1 ;;; list-mode.el
|
|
2 ;; Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc.
|
|
3 ;; Copyright (C) 1996 Ben Wing.
|
|
4
|
|
5 ;; This file is part of XEmacs.
|
|
6
|
|
7 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
8 ;; under the terms of the GNU General Public License as published by
|
|
9 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
10 ;; any later version.
|
|
11
|
|
12 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
13 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
15 ;; General Public License for more details.
|
|
16
|
|
17 ;; You should have received a copy of the GNU General Public License
|
16
|
18 ;; along with XEmacs; see the file COPYING. If not, write to the
|
|
19 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
20 ;; Boston, MA 02111-1307, USA.
|
0
|
21
|
|
22 ;; Cleanup, merging with FSF by Ben Wing, January 1996
|
|
23
|
|
24 (defvar list-mode-extent nil)
|
|
25 (make-variable-buffer-local 'list-mode-extent)
|
|
26
|
|
27 (defvar list-mode-map nil
|
|
28 "Local map for buffers containing lists of items.")
|
|
29 (or list-mode-map
|
|
30 (let ((map (setq list-mode-map (make-sparse-keymap 'list-mode-map))))
|
|
31 (suppress-keymap map)
|
|
32 (define-key map 'button2up 'list-mode-item-mouse-selected)
|
|
33 (define-key map 'button2 'undefined)
|
|
34 (define-key map "\C-m" 'list-mode-item-keyboard-selected)
|
|
35 (substitute-key-definition 'forward-char 'next-list-mode-item map
|
|
36 global-map)
|
|
37 (substitute-key-definition 'backward-char 'previous-list-mode-item map
|
|
38 global-map)))
|
|
39
|
|
40 (defun list-mode ()
|
|
41 "Major mode for buffer containing lists of items."
|
|
42 (interactive)
|
|
43 (kill-all-local-variables)
|
|
44 (use-local-map list-mode-map)
|
|
45 (setq mode-name "List")
|
|
46 (setq major-mode 'list-mode)
|
|
47 (make-local-hook 'post-command-hook)
|
|
48 (add-hook 'post-command-hook 'set-list-mode-extent nil t)
|
|
49 (make-local-hook 'pre-command-hook)
|
|
50 (add-hook 'pre-command-hook 'list-mode-extent-pre-hook nil t)
|
|
51 (make-local-variable 'next-line-add-newlines)
|
|
52 (setq next-line-add-newlines nil)
|
|
53 (setq list-mode-extent nil)
|
|
54 (set-specifier text-cursor-visible-p nil (current-buffer))
|
|
55 (setq buffer-read-only t)
|
|
56 (goto-char (point-min))
|
|
57 (run-hooks 'list-mode-hook))
|
|
58
|
|
59 ;; List mode is suitable only for specially formatted data.
|
|
60 (put 'list-mode 'mode-class 'special)
|
|
61
|
|
62 (defvar list-mode-extent-old-point nil
|
|
63 "The value of point when pre-command-hook is called.
|
|
64 Used to determine the direction of motion.")
|
|
65 (make-variable-buffer-local 'list-mode-extent-old-point)
|
|
66
|
|
67 (defun list-mode-extent-pre-hook ()
|
|
68 (setq list-mode-extent-old-point (point))
|
|
69 ;(setq atomic-extent-goto-char-p nil)
|
|
70 )
|
|
71
|
|
72 (defun set-list-mode-extent ()
|
|
73 "Move to the closest list item and set up the extent for it.
|
|
74 This is called from `post-command-hook'."
|
|
75 (cond ((get-char-property (point) 'list-mode-item))
|
|
76 ((and (> (point) (point-min))
|
|
77 (get-char-property (1- (point)) 'list-mode-item))
|
|
78 (goto-char (1- (point))))
|
|
79 (t
|
|
80 (let ((pos (point))
|
|
81 dirflag)
|
|
82 ;this fucks things up more than it helps.
|
|
83 ;atomic-extent-goto-char-p as currently defined is all broken,
|
|
84 ;since it will be triggered if the command *ever* runs goto-char!
|
|
85 ;(if atomic-extent-goto-char-p
|
|
86 ; (setq dirflag 1)
|
|
87 (if (and list-mode-extent-old-point
|
|
88 (> pos list-mode-extent-old-point))
|
|
89 (setq dirflag 1)
|
|
90 (setq dirflag -1))
|
|
91 (next-list-mode-item dirflag)
|
|
92 (or (get-char-property (point) 'list-mode-item)
|
|
93 (next-list-mode-item (- dirflag))))))
|
|
94 (or (and list-mode-extent
|
|
95 (eq (current-buffer) (extent-object list-mode-extent)))
|
|
96 (progn
|
|
97 (setq list-mode-extent (make-extent nil nil (current-buffer)))
|
|
98 (set-extent-face list-mode-extent 'list-mode-item-selected)))
|
|
99 (let ((ex (extent-at (point) nil 'list-mode-item nil 'at)))
|
|
100 (if ex
|
|
101 (progn
|
|
102 (set-extent-endpoints list-mode-extent
|
|
103 (extent-start-position ex)
|
|
104 (extent-end-position ex))
|
|
105 (auto-show-make-region-visible (extent-start-position ex)
|
|
106 (extent-end-position ex)))
|
|
107 (detach-extent list-mode-extent))))
|
|
108
|
|
109 (defun previous-list-mode-item (n)
|
|
110 "Move to the previous item in list-mode."
|
|
111 (interactive "p")
|
|
112 (next-list-mode-item (- n)))
|
|
113
|
|
114 (defun next-list-mode-item (n)
|
|
115 "Move to the next item in list-mode.
|
108
|
116 With prefix argument N, move N items (negative N means move backward)."
|
0
|
117 (interactive "p")
|
|
118 (while (and (> n 0) (not (eobp)))
|
|
119 (let ((prop (get-char-property (point) 'list-mode-item))
|
|
120 (end (point-max)))
|
|
121 ;; If in a completion, move to the end of it.
|
|
122 (if prop
|
|
123 (goto-char (next-single-property-change (point) 'list-mode-item
|
|
124 nil end)))
|
|
125 ;; Move to start of next one.
|
|
126 (goto-char (next-single-property-change (point)
|
|
127 'list-mode-item nil end)))
|
|
128 (setq n (1- n)))
|
|
129 (while (and (< n 0) (not (bobp)))
|
|
130 (let ((prop (get-char-property (1- (point)) 'list-mode-item))
|
|
131 (end (point-min)))
|
|
132 ;; If in a completion, move to the start of it.
|
|
133 (if prop
|
|
134 (goto-char (previous-single-property-change
|
|
135 (point) 'list-mode-item nil end)))
|
|
136 ;; Move to end of the previous completion.
|
|
137 (goto-char (previous-single-property-change (point) 'list-mode-item
|
|
138 nil end))
|
|
139 ;; Move to the start of that one.
|
|
140 (goto-char (previous-single-property-change (point) 'list-mode-item nil
|
|
141 end)))
|
|
142 (setq n (1+ n))))
|
|
143
|
|
144 (defun list-mode-item-selected-1 (extent event)
|
|
145 (let ((func (extent-property extent 'list-mode-item-activate-callback))
|
|
146 (user-data (extent-property extent 'list-mode-item-user-data)))
|
|
147 (if func
|
|
148 (funcall func event extent user-data))))
|
|
149
|
|
150 ;; we could make these two be just one function, but we want to be
|
|
151 ;; able to refer to them in DOC strings.
|
|
152
|
|
153 (defun list-mode-item-keyboard-selected ()
|
|
154 (interactive)
|
|
155 (list-mode-item-selected-1 (extent-at (point) (current-buffer)
|
|
156 'list-mode-item nil 'at)
|
|
157 nil))
|
|
158
|
|
159 (defun list-mode-item-mouse-selected (event)
|
|
160 (interactive "e")
|
124
|
161 ;; Sometimes event-closest-point returns nil.
|
|
162 ;; So beep instead of bombing.
|
2
|
163 (let ((point (event-closest-point event)))
|
124
|
164 (if point
|
|
165 (list-mode-item-selected-1 (extent-at point
|
|
166 (event-buffer event)
|
|
167 'list-mode-item nil 'at)
|
|
168 event)
|
|
169 (ding))))
|
0
|
170
|
|
171 (defun add-list-mode-item (start end &optional buffer activate-callback
|
|
172 user-data)
|
|
173 "Add a new list item in list-mode, from START to END in BUFFER.
|
|
174 BUFFER defaults to the current buffer.
|
|
175 This works by creating an extent for the span of text in question.
|
|
176 If ACTIVATE-CALLBACK is non-nil, it should be a function of three
|
|
177 arguments (EVENT EXTENT USER-DATA) that will be called when button2
|
|
178 is pressed on the extent. USER-DATA comes from the optional
|
|
179 USER-DATA argument."
|
|
180 (let ((extent (make-extent start end buffer)))
|
|
181 (set-extent-property extent 'list-mode-item t)
|
|
182 (set-extent-property extent 'start-open t)
|
|
183 (if activate-callback
|
|
184 (progn
|
|
185 (set-extent-property extent 'mouse-face 'highlight)
|
|
186 (set-extent-property extent 'list-mode-item-activate-callback
|
|
187 activate-callback)
|
|
188 (set-extent-property extent 'list-mode-item-user-data user-data)))
|
|
189 extent))
|
|
190
|
|
191
|
|
192 ;; Define the major mode for lists of completions.
|
|
193
|
|
194
|
|
195 (defvar completion-highlight-first-word-only nil
|
108
|
196 "*Completion will only highlight the first blank delimited word if t.
|
0
|
197 If the variable in not t or nil, the string is taken as a regexp to match for end
|
|
198 of highlight")
|
|
199
|
|
200 (defvar completion-setup-hook nil
|
|
201 "Normal hook run at the end of setting up the text of a completion buffer.")
|
|
202
|
|
203 ; Unnecessary FSFmacs crock. We frob the extents directly in
|
|
204 ; display-completion-list, so no "heuristics" like this are necessary.
|
|
205 ;(defvar completion-fixup-function nil
|
|
206 ; "A function to customize how completions are identified in completion lists.
|
|
207 ;`completion-setup-function' calls this function with no arguments
|
|
208 ;each time it has found what it thinks is one completion.
|
|
209 ;Point is at the end of the completion in the completion list buffer.
|
|
210 ;If this function moves point, it can alter the end of that completion.")
|
|
211
|
|
212 (defvar completion-default-help-string
|
|
213 '(concat
|
|
214 (if (device-on-window-system-p)
|
|
215 (substitute-command-keys
|
|
216 "Click \\<list-mode-map>\\[list-mode-item-mouse-selected] on a completion to select it.\n") "")
|
|
217 (substitute-command-keys
|
|
218 "Type \\<minibuffer-local-completion-map>\\[advertised-switch-to-completions] or \\[switch-to-completions] to move to this buffer, for keyboard selection.\n\n"))
|
|
219 "Form the evaluate to get a help string for completion lists.
|
|
220 This string is inserted at the beginning of the buffer.
|
|
221 See `display-completion-list'.")
|
|
222
|
|
223 (defun display-completion-list (completions &rest cl-keys)
|
|
224 "Display the list of completions, COMPLETIONS, using `standard-output'.
|
|
225 Each element may be just a symbol or string or may be a list of two
|
|
226 strings to be printed as if concatenated.
|
|
227 Frob a mousable extent onto each completion. This extent has properties
|
|
228 'mouse-face (so it highlights when the mouse passes over it) and
|
|
229 'list-mode-item (so it can be located).
|
|
230
|
|
231 Keywords:
|
|
232 :activate-callback (default is `default-choose-completion')
|
|
233 See `add-list-mode-item'.
|
|
234 :user-data
|
|
235 Value passed to activation callback.
|
|
236 :window-width
|
|
237 If non-nil, width to use in displaying the list, instead of the
|
|
238 actual window's width.
|
|
239 :help-string (default is the value of `completion-default-help-string')
|
|
240 Form to evaluate to get a string to insert at the beginning of
|
|
241 the completion list buffer. This is evaluated when that buffer
|
|
242 is the current buffer and after it has been put into
|
|
243 completion-list-mode.
|
|
244 :reference-buffer (default is the current buffer)
|
|
245 This specifies the value of `completion-reference-buffer' in
|
|
246 the completion buffer. This specifies the buffer (normally a
|
|
247 minibuffer) that `default-choose-completion' will insert the
|
|
248 completion into.
|
|
249
|
|
250 At the end, run the normal hook `completion-setup-hook'.
|
|
251 It can find the completion buffer in `standard-output'.
|
|
252 If `completion-highlight-first-word-only' is non-nil, then only the start
|
|
253 of the string is highlighted."
|
|
254 ;; #### I18N3 should set standard-output to be (temporarily)
|
|
255 ;; output-translating.
|
|
256 (cl-parsing-keywords
|
|
257 ((:activate-callback 'default-choose-completion)
|
|
258 :user-data
|
|
259 :reference-buffer
|
|
260 (:help-string completion-default-help-string)
|
|
261 :window-width)
|
|
262 ()
|
|
263 (let ((old-buffer (current-buffer))
|
|
264 (bufferp (bufferp standard-output)))
|
|
265 (if bufferp
|
|
266 (set-buffer standard-output))
|
|
267 (if (null completions)
|
|
268 (princ (gettext
|
|
269 "There are no possible completions of what you have typed."))
|
|
270 (let ((win-width
|
|
271 (or cl-window-width
|
|
272 (if bufferp
|
|
273 ;; This needs fixing for the case of windows
|
|
274 ;; that aren't the same width's the frame.
|
|
275 ;; Sadly, the window it will appear in is not known
|
|
276 ;; until after the text has been made.
|
|
277
|
|
278 ;; We have to use last-nonminibuf-frame here
|
|
279 ;; and not selected-frame because if a
|
|
280 ;; minibuffer-only frame is being used it will
|
|
281 ;; be the selected-frame at the point this is
|
|
282 ;; run. We keep the selected-frame call around
|
|
283 ;; just in case.
|
|
284 (frame-width (or (last-nonminibuf-frame)
|
|
285 (selected-frame)))
|
|
286 80))))
|
|
287 (let ((count 0)
|
|
288 (max-width 0))
|
|
289 ;; Find longest completion
|
|
290 (let ((tail completions))
|
|
291 (while tail
|
|
292 (let* ((elt (car tail))
|
|
293 (len (cond ((stringp elt)
|
|
294 (length elt))
|
|
295 ((and (consp elt)
|
|
296 (stringp (car elt))
|
|
297 (stringp (car (cdr elt))))
|
|
298 (+ (length (car elt))
|
|
299 (length (car (cdr elt)))))
|
|
300 (t
|
|
301 (signal 'wrong-type-argument
|
|
302 (list 'stringp elt))))))
|
|
303 (if (> len max-width)
|
|
304 (setq max-width len))
|
|
305 (setq count (1+ count)
|
|
306 tail (cdr tail)))))
|
|
307
|
|
308 (setq max-width (+ 2 max-width)) ; at least two chars between cols
|
|
309 (let ((rows (let ((cols (min (/ win-width max-width) count)))
|
|
310 (if (<= cols 1)
|
|
311 count
|
|
312 (progn
|
|
313 ;; re-space the columns
|
|
314 (setq max-width (/ win-width cols))
|
|
315 (if (/= (% count cols) 0) ; want ceiling...
|
|
316 (1+ (/ count cols))
|
|
317 (/ count cols)))))))
|
|
318 (princ (gettext "Possible completions are:"))
|
|
319 (let ((tail completions)
|
|
320 (r 0)
|
|
321 (regexp-string
|
|
322 (if (eq t
|
|
323 completion-highlight-first-word-only)
|
|
324 "[ \t]"
|
|
325 completion-highlight-first-word-only)))
|
|
326 (while (< r rows)
|
|
327 (terpri)
|
|
328 (let ((indent 0)
|
|
329 (column 0)
|
|
330 (tail2 tail))
|
|
331 (while tail2
|
|
332 (let ((elt (car tail2)))
|
|
333 (if (/= indent 0)
|
|
334 (if bufferp
|
|
335 (indent-to indent 2)
|
|
336 (while (progn (write-char ?\ )
|
|
337 (setq column (1+ column))
|
|
338 (< column indent)))))
|
|
339 (setq indent (+ indent max-width))
|
|
340 (let ((start (point))
|
|
341 end)
|
|
342 ;; Frob some mousable extents in there too!
|
|
343 (if (consp elt)
|
|
344 (progn
|
|
345 (princ (car elt))
|
|
346 (princ (car (cdr elt)))
|
|
347 (or bufferp
|
|
348 (setq column
|
|
349 (+ column
|
|
350 (length (car elt))
|
|
351 (length (car (cdr elt)))))))
|
|
352 (progn
|
|
353 (princ elt)
|
|
354 (or bufferp
|
|
355 (setq column (+ column (length
|
|
356 elt))))))
|
|
357 (add-list-mode-item
|
|
358 start
|
|
359 (progn
|
|
360 (setq end (point))
|
|
361 (or
|
|
362 (and completion-highlight-first-word-only
|
|
363 (goto-char start)
|
|
364 (re-search-forward regexp-string end t)
|
|
365 (match-beginning 0))
|
|
366 end))
|
|
367 nil cl-activate-callback cl-user-data)
|
|
368 (goto-char end)))
|
|
369 (setq tail2 (nthcdr rows tail2)))
|
|
370 (setq tail (cdr tail)
|
|
371 r (1+ r)))))))))
|
|
372 (if bufferp
|
|
373 (set-buffer old-buffer)))
|
|
374 (save-excursion
|
|
375 (let ((mainbuf (or cl-reference-buffer (current-buffer))))
|
|
376 (set-buffer standard-output)
|
|
377 (completion-list-mode)
|
|
378 (make-local-variable 'completion-reference-buffer)
|
|
379 (setq completion-reference-buffer mainbuf)
|
|
380 ;;; The value 0 is right in most cases, but not for file name completion.
|
|
381 ;;; so this has to be turned off.
|
|
382 ;;; (setq completion-base-size 0)
|
|
383 (goto-char (point-min))
|
|
384 (let ((buffer-read-only nil))
|
|
385 (insert (eval cl-help-string)))
|
|
386 ;; unnecessary FSFmacs crock
|
|
387 ;;(forward-line 1)
|
|
388 ;;(while (re-search-forward "[^ \t\n]+\\( [^ \t\n]+\\)*" nil t)
|
|
389 ;; (let ((beg (match-beginning 0))
|
|
390 ;; (end (point)))
|
|
391 ;; (if completion-fixup-function
|
|
392 ;; (funcall completion-fixup-function))
|
|
393 ;; (put-text-property beg (point) 'mouse-face 'highlight)
|
|
394 ;; (put-text-property beg (point) 'list-mode-item t)
|
|
395 ;; (goto-char end)))))
|
|
396 ))
|
|
397 (run-hooks 'completion-setup-hook)))
|
|
398
|
|
399 (defvar completion-display-completion-list-function 'display-completion-list
|
|
400 "Function to set up the list of completions in the completion buffer.
|
|
401 The function is called with one argument, the sorted list of completions.
|
|
402 Particular minibuffer interface functions (e.g. `read-file-name') may
|
|
403 want to change this. To do that, set a local value for this variable
|
|
404 in the minibuffer; that ensures that other minibuffer invocations will
|
|
405 not be affected.")
|
|
406
|
|
407 (defun minibuffer-completion-help ()
|
|
408 "Display a list of possible completions of the current minibuffer contents.
|
|
409 The list of completions is determined by calling `all-completions',
|
|
410 passing it the current minibuffer contents, the value of
|
|
411 `minibuffer-completion-table', and the value of
|
|
412 `minibuffer-completion-predicate'. The list is displayed by calling
|
|
413 the value of `completion-display-completion-list-function' on the sorted
|
|
414 list of completions, with the standard output set to the completion
|
|
415 buffer."
|
|
416 (interactive)
|
|
417 (message "Making completion list...")
|
|
418 (let ((completions (all-completions (buffer-string)
|
|
419 minibuffer-completion-table
|
|
420 minibuffer-completion-predicate)))
|
|
421 (message nil)
|
|
422 (if (null completions)
|
|
423 (progn
|
|
424 (ding nil 'no-completion)
|
|
425 (temp-minibuffer-message " [No completions]"))
|
|
426 (with-output-to-temp-buffer "*Completions*"
|
|
427 (funcall completion-display-completion-list-function
|
|
428 (sort completions #'string-lessp))))))
|
|
429
|
|
430 (define-derived-mode completion-list-mode list-mode
|
|
431 "Completion List"
|
|
432 "Major mode for buffers showing lists of possible completions.
|
|
433 Type \\<completion-list-mode-map>\\[choose-completion] in the completion list\
|
|
434 to select the completion near point.
|
|
435 Use \\<completion-list-mode-map>\\[mouse-choose-completion] to select one\
|
|
436 with the mouse."
|
|
437 (make-local-variable 'completion-base-size)
|
|
438 (setq completion-base-size nil))
|
|
439
|
|
440 (let ((map completion-list-mode-map))
|
|
441 (define-key map "\e\e\e" 'delete-completion-window)
|
|
442 (define-key map "\C-g" 'minibuffer-keyboard-quit)
|
|
443 (define-key map "q" 'abort-recursive-edit)
|
|
444 (define-key map " " (lambda () (interactive)
|
|
445 (select-window (minibuffer-window))))
|
|
446 (define-key map "\t" (lambda () (interactive)
|
|
447 (select-window (minibuffer-window)))))
|
|
448
|
|
449 (defvar completion-reference-buffer nil
|
|
450 "Record the buffer that was current when the completion list was requested.
|
|
451 This is a local variable in the completion list buffer.
|
|
452 Initial value is nil to avoid some compiler warnings.")
|
|
453
|
|
454 (defvar completion-base-size nil
|
|
455 "Number of chars at beginning of minibuffer not involved in completion.
|
|
456 This is a local variable in the completion list buffer
|
|
457 but it talks about the buffer in `completion-reference-buffer'.
|
|
458 If this is nil, it means to compare text to determine which part
|
|
459 of the tail end of the buffer's text is involved in completion.")
|
|
460
|
|
461 (defun delete-completion-window ()
|
|
462 "Delete the completion list window.
|
|
463 Go to the window from which completion was requested."
|
|
464 (interactive)
|
|
465 (let ((buf completion-reference-buffer))
|
|
466 (delete-window (selected-window))
|
|
467 (if (get-buffer-window buf)
|
|
468 (select-window (get-buffer-window buf)))))
|
|
469
|
|
470 (defun completion-do-in-minibuffer ()
|
|
471 (interactive "_")
|
|
472 (save-excursion
|
|
473 (set-buffer (window-buffer (minibuffer-window)))
|
|
474 (call-interactively (key-binding (this-command-keys)))))
|
|
475
|
|
476 (defun default-choose-completion (event extent buffer)
|
|
477 "Click on an alternative in the `*Completions*' buffer to choose it."
|
|
478 (and (button-event-p event)
|
|
479 ;; Give temporary modes such as isearch a chance to turn off.
|
|
480 (run-hooks 'mouse-leave-buffer-hook))
|
|
481 (or buffer (setq buffer (symbol-value-in-buffer
|
|
482 'completion-reference-buffer
|
|
483 (or (and (button-event-p event)
|
|
484 (event-buffer event))
|
|
485 (current-buffer)))))
|
|
486 (save-selected-window
|
|
487 (and (button-event-p event)
|
|
488 (select-window (event-window event)))
|
|
489 (if (and (one-window-p t 'selected-frame)
|
|
490 (window-dedicated-p (selected-window)))
|
|
491 ;; This is a special buffer's frame
|
|
492 (iconify-frame (selected-frame))
|
|
493 (or (window-dedicated-p (selected-window))
|
|
494 (bury-buffer))))
|
|
495 (choose-completion-string (extent-string extent)
|
|
496 buffer
|
|
497 completion-base-size))
|
|
498
|
|
499 ;; Delete the longest partial match for STRING
|
|
500 ;; that can be found before POINT.
|
|
501 (defun choose-completion-delete-max-match (string)
|
|
502 (let ((len (min (length string)
|
|
503 (- (point) (point-min)))))
|
|
504 (goto-char (- (point) (length string)))
|
|
505 (if completion-ignore-case
|
|
506 (setq string (downcase string)))
|
|
507 (while (and (> len 0)
|
|
508 (let ((tail (buffer-substring (point)
|
|
509 (+ (point) len))))
|
|
510 (if completion-ignore-case
|
|
511 (setq tail (downcase tail)))
|
|
512 (not (string= tail (substring string 0 len)))))
|
|
513 (setq len (1- len))
|
|
514 (forward-char 1))
|
|
515 (delete-char len)))
|
|
516
|
|
517 ;; Switch to BUFFER and insert the completion choice CHOICE.
|
|
518 ;; BASE-SIZE, if non-nil, says how many characters of BUFFER's text
|
|
519 ;; to keep. If it is nil, use choose-completion-delete-max-match instead.
|
|
520 (defun choose-completion-string (choice &optional buffer base-size)
|
|
521 (let ((buffer (or buffer completion-reference-buffer)))
|
|
522 ;; If BUFFER is a minibuffer, barf unless it's the currently
|
|
523 ;; active minibuffer.
|
|
524 (if (and (string-match "\\` \\*Minibuf-[0-9]+\\*\\'" (buffer-name buffer))
|
|
525 (or (not (active-minibuffer-window))
|
|
526 (not (equal buffer
|
|
527 (window-buffer (active-minibuffer-window))))))
|
|
528 (error "Minibuffer is not active for completion")
|
|
529 ;; Insert the completion into the buffer where completion was requested.
|
|
530 (set-buffer buffer)
|
|
531 (if base-size
|
|
532 (delete-region (+ base-size (point-min)) (point))
|
|
533 (choose-completion-delete-max-match choice))
|
|
534 (insert choice)
|
|
535 (remove-text-properties (- (point) (length choice)) (point)
|
|
536 '(highlight nil))
|
|
537 ;; Update point in the window that BUFFER is showing in.
|
|
538 (let ((window (get-buffer-window buffer t)))
|
|
539 (set-window-point window (point)))
|
|
540 ;; If completing for the minibuffer, exit it with this choice.
|
|
541 (and (equal buffer (window-buffer (minibuffer-window)))
|
|
542 minibuffer-completion-table
|
|
543 (exit-minibuffer)))))
|
|
544
|
|
545 (define-key minibuffer-local-completion-map [prior]
|
|
546 'switch-to-completions)
|
|
547 (define-key minibuffer-local-must-match-map [prior]
|
|
548 'switch-to-completions)
|
|
549 (define-key minibuffer-local-completion-map "\M-v"
|
|
550 'advertised-switch-to-completions)
|
|
551 (define-key minibuffer-local-must-match-map "\M-v"
|
|
552 'advertised-switch-to-completions)
|
|
553
|
|
554 (defalias 'advertised-switch-to-completions 'switch-to-completions)
|
|
555 (defun switch-to-completions ()
|
|
556 "Select the completion list window."
|
|
557 (interactive)
|
|
558 ;; Make sure we have a completions window.
|
|
559 (or (get-buffer-window "*Completions*")
|
|
560 (minibuffer-completion-help))
|
|
561 (if (not (get-buffer-window "*Completions*"))
|
|
562 nil
|
|
563 (select-window (get-buffer-window "*Completions*"))
|
|
564 (goto-char (next-single-property-change (point-min) 'list-mode-item nil
|
|
565 (point-max)))))
|