annotate lisp/modes/list-mode.el @ 0:376386a54a3c r19-14

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