annotate lisp/progmodes/sym-comp.el @ 105593:1987d1800365

(vc-git-dir-extra-headers): Set the branch name correctly in the detached head case. (vc-git-print-log): Remove unused binding.
author Dan Nicolaescu <dann@ics.uci.edu>
date Wed, 14 Oct 2009 06:28:00 +0000
parents 1d5c75e6a226
children aef9a4af6024
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
92054
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1 ;;; sym-comp.el --- mode-dependent symbol completion
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
2
100908
a9dc0e7c3f2b Add 2009 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 94673
diff changeset
3 ;; Copyright (C) 2004, 2008, 2009 Free Software Foundation, Inc.
92054
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
4
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
5 ;; Author: Dave Love <fx@gnu.org>
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
6 ;; Keywords: extensions
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
7 ;; URL: http://www.loveshack.ukfsn.org/emacs
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
8
92256
bae32624018f Standardize license text.
Glenn Morris <rgm@gnu.org>
parents: 92250
diff changeset
9 ;; This file is part of GNU Emacs.
bae32624018f Standardize license text.
Glenn Morris <rgm@gnu.org>
parents: 92250
diff changeset
10
94673
52b7a8c22af5 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 92256
diff changeset
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
92054
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
94673
52b7a8c22af5 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 92256
diff changeset
13 ;; the Free Software Foundation, either version 3 of the License, or
52b7a8c22af5 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 92256
diff changeset
14 ;; (at your option) any later version.
92054
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
15
92256
bae32624018f Standardize license text.
Glenn Morris <rgm@gnu.org>
parents: 92250
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
92054
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
19 ;; GNU General Public License for more details.
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
20
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
94673
52b7a8c22af5 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 92256
diff changeset
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
92054
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
23
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
24 ;;; Commentary:
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
25
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
26 ;; This defines `symbol-complete', which is a generalization of the
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
27 ;; old `lisp-complete-symbol'. It provides the following hooks to
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
28 ;; allow major modes to set up completion appropriate for the mode:
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
29 ;; `symbol-completion-symbol-function',
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
30 ;; `symbol-completion-completions-function',
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
31 ;; `symbol-completion-predicate-function',
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
32 ;; `symbol-completion-transform-function'. Typically it is only
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
33 ;; necessary for a mode to set
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
34 ;; `symbol-completion-completions-function' locally and to bind
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
35 ;; `symbol-complete' appropriately.
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
36
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
37 ;; It's unfortunate that there doesn't seem to be a good way of
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
38 ;; combining this with `complete-symbol'.
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
39
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
40 ;; There is also `symbol-completion-try-complete', for use with
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
41 ;; Hippie-exp.
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
42
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
43 ;;; Code:
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
44
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
45 ;;;; Mode-dependent symbol completion.
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
46
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
47 (defun symbol-completion-symbol ()
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
48 "Default `symbol-completion-symbol-function'.
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
49 Uses `current-word' with the buffer narrowed to the part before
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
50 point."
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
51 (save-restriction
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
52 ;; Narrow in case point is in the middle of a symbol -- we want
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
53 ;; just the preceeding part.
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
54 (narrow-to-region (point-min) (point))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
55 (current-word)))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
56
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
57 (defvar symbol-completion-symbol-function 'symbol-completion-symbol
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
58 "Function to return a partial symbol before point for completion.
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
59 The value it returns should be a string (or nil).
104760
1d5c75e6a226 (displayed-completions): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
60 Major modes may set this locally if the default isn't appropriate.
1d5c75e6a226 (displayed-completions): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
61
1d5c75e6a226 (displayed-completions): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
62 Beware: the length of the string STR returned need to be equal to the length
1d5c75e6a226 (displayed-completions): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
63 of text before point that's subject to completion. Typically, this amounts
1d5c75e6a226 (displayed-completions): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
64 to saying that STR is equal to
1d5c75e6a226 (displayed-completions): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
65 \(buffer-substring (- (point) (length STR)) (point)).")
92054
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
66
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
67 (defvar symbol-completion-completions-function nil
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
68 "Function to return possible symbol completions.
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
69 It takes an argument which is the string to be completed and
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
70 returns a value suitable for the second argument of
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
71 `try-completion'. This value need not use the argument, i.e. it
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
72 may be all possible completions, such as `obarray' in the case of
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
73 Emacs Lisp.
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
74
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
75 Major modes may set this locally to allow them to support
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
76 `symbol-complete'. See also `symbol-completion-symbol-function',
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
77 `symbol-completion-predicate-function' and
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
78 `symbol-completion-transform-function'.")
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
79
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
80 (defvar symbol-completion-predicate-function nil
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
81 "If non-nil, function to return a predicate for selecting symbol completions.
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
82 The function gets two args, the positions of the beginning and
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
83 end of the symbol to be completed.
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
84
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
85 Major modes may set this locally if the default isn't
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
86 appropriate. This is a function returning a predicate so that
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
87 the predicate can be context-dependent, e.g. to select only
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
88 function names if point is at a function call position. The
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
89 function's args may be useful for determining the context.")
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
90
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
91 (defvar symbol-completion-transform-function nil
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
92 "If non-nil, function to transform symbols in the symbol-completion buffer.
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
93 E.g., for Lisp, it may annotate the symbol as being a function,
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
94 not a variable.
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
95
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
96 The function takes the symbol name as argument. If it needs to
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
97 annotate this, it should return a value suitable as an element of
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
98 the list passed to `display-completion-list'.
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
99
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
100 The predicate being used for selecting completions (from
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
101 `symbol-completion-predicate-function') is available
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
102 dynamically-bound as `symbol-completion-predicate' in case the
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
103 transform needs it.")
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
104
104760
1d5c75e6a226 (displayed-completions): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
105 (defvar symbol-completion-predicate)
92054
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
106
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
107 ;;;###autoload
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
108 (defun symbol-complete (&optional predicate)
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
109 "Perform completion of the symbol preceding point.
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
110 This is done in a way appropriate to the current major mode,
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
111 perhaps by interrogating an inferior interpreter. Compare
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
112 `complete-symbol'.
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
113 If no characters can be completed, display a list of possible completions.
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
114 Repeating the command at that point scrolls the list.
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
115
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
116 When called from a program, optional arg PREDICATE is a predicate
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
117 determining which symbols are considered.
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
118
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
119 This function requires `symbol-completion-completions-function'
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
120 to be set buffer-locally. Variables `symbol-completion-symbol-function',
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
121 `symbol-completion-predicate-function' and
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
122 `symbol-completion-transform-function' are also consulted."
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
123 (interactive)
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
124 ;; Fixme: Punt to `complete-symbol' in this case?
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
125 (unless (functionp symbol-completion-completions-function)
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
126 (error "symbol-completion-completions-function not defined"))
104760
1d5c75e6a226 (displayed-completions): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
127 (let* ((pattern (or (funcall symbol-completion-symbol-function)
1d5c75e6a226 (displayed-completions): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
128 (error "No preceding symbol to complete")))
1d5c75e6a226 (displayed-completions): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
129 ;; FIXME: We assume below that `pattern' holds the text just
1d5c75e6a226 (displayed-completions): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
130 ;; before point. This is a problem in the way
1d5c75e6a226 (displayed-completions): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
131 ;; symbol-completion-symbol-function was defined.
1d5c75e6a226 (displayed-completions): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
132 (predicate (or predicate
1d5c75e6a226 (displayed-completions): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
133 (if symbol-completion-predicate-function
1d5c75e6a226 (displayed-completions): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
134 (funcall symbol-completion-predicate-function
1d5c75e6a226 (displayed-completions): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
135 (- (point) (length pattern))
1d5c75e6a226 (displayed-completions): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
136 (point)))))
1d5c75e6a226 (displayed-completions): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
137 (completions (funcall symbol-completion-completions-function
1d5c75e6a226 (displayed-completions): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
138 pattern))
1d5c75e6a226 (displayed-completions): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
139 ;; In case the transform needs to access it.
1d5c75e6a226 (displayed-completions): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
140 (symbol-completion-predicate predicate)
1d5c75e6a226 (displayed-completions): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
141 (completion-annotate-function
1d5c75e6a226 (displayed-completions): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
142 (if (functionp symbol-completion-transform-function)
1d5c75e6a226 (displayed-completions): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
143 (lambda (str)
1d5c75e6a226 (displayed-completions): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
144 (car-safe (cdr-safe
1d5c75e6a226 (displayed-completions): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
145 (funcall symbol-completion-transform-function
1d5c75e6a226 (displayed-completions): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
146 str))))))
1d5c75e6a226 (displayed-completions): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
147 (minibuffer-completion-table completions)
1d5c75e6a226 (displayed-completions): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
148 (minibuffer-completion-predicate predicate)
1d5c75e6a226 (displayed-completions): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
149 (ol (make-overlay (- (point) (length pattern)) (point) nil nil t)))
1d5c75e6a226 (displayed-completions): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
150 (overlay-put ol 'field 'sym-comp)
1d5c75e6a226 (displayed-completions): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
151 (unwind-protect
1d5c75e6a226 (displayed-completions): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
152 (call-interactively 'minibuffer-complete)
1d5c75e6a226 (displayed-completions): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
153 (delete-overlay ol))))
92054
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
154
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
155 (eval-when-compile (require 'hippie-exp))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
156
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
157 ;;;###autoload
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
158 (defun symbol-completion-try-complete (old)
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
159 "Completion function for use with `hippie-expand'.
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
160 Uses `symbol-completion-symbol-function' and
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
161 `symbol-completion-completions-function'. It is intended to be
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
162 used something like this in a major mode which provides symbol
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
163 completion:
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
164
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
165 (if (featurep 'hippie-exp)
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
166 (set (make-local-variable 'hippie-expand-try-functions-list)
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
167 (cons 'symbol-completion-try-complete
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
168 hippie-expand-try-functions-list)))"
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
169 (when (and symbol-completion-symbol-function
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
170 symbol-completion-completions-function)
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
171 (unless old
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
172 (let ((symbol (funcall symbol-completion-symbol-function)))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
173 (he-init-string (- (point) (length symbol)) (point))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
174 (if (not (he-string-member he-search-string he-tried-table))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
175 (push he-search-string he-tried-table))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
176 (setq he-expand-list
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
177 (and symbol
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
178 (funcall symbol-completion-completions-function symbol)))))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
179 (while (and he-expand-list
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
180 (he-string-member (car he-expand-list) he-tried-table))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
181 (pop he-expand-list))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
182 (if he-expand-list
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
183 (progn
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
184 (he-substitute-string (pop he-expand-list))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
185 t)
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
186 (if old (he-reset-string))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
187 nil)))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
188
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
189 ;;; Emacs Lisp symbol completion.
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
190
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
191 (defun lisp-completion-symbol ()
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
192 "`symbol-completion-symbol-function' for Lisp."
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
193 (let ((end (point))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
194 (beg (with-syntax-table emacs-lisp-mode-syntax-table
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
195 (save-excursion
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
196 (backward-sexp 1)
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
197 (while (= (char-syntax (following-char)) ?\')
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
198 (forward-char 1))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
199 (point)))))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
200 (buffer-substring-no-properties beg end)))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
201
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
202 (defun lisp-completion-predicate (beg end)
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
203 "`symbol-completion-predicate-function' for Lisp."
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
204 (save-excursion
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
205 (goto-char beg)
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
206 (if (not (eq (char-before) ?\())
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
207 (lambda (sym) ;why not just nil ? -sm
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
208 ;To avoid interned symbols with
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
209 ;no slots. -- fx
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
210 (or (boundp sym) (fboundp sym)
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
211 (symbol-plist sym)))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
212 ;; Looks like a funcall position. Let's double check.
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
213 (if (condition-case nil
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
214 (progn (up-list -2) (forward-char 1)
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
215 (eq (char-after) ?\())
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
216 (error nil))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
217 ;; If the first element of the parent list is an open
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
218 ;; parenthesis we are probably not in a funcall position.
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
219 ;; Maybe a `let' varlist or something.
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
220 nil
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
221 ;; Else, we assume that a function name is expected.
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
222 'fboundp))))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
223
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
224 (defun lisp-symbol-completion-transform ()
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
225 "`symbol-completion-transform-function' for Lisp."
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
226 (lambda (elt)
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
227 (if (and (not (eq 'fboundp symbol-completion-predicate))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
228 (fboundp (intern elt)))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
229 (list elt " <f>")
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
230 elt)))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
231
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
232 (provide 'sym-comp)
92123
e670b615aad9 Add arch tagline
Miles Bader <miles@gnu.org>
parents: 92054
diff changeset
233
e670b615aad9 Add arch tagline
Miles Bader <miles@gnu.org>
parents: 92054
diff changeset
234 ;; arch-tag: 6fcce616-f3c4-4751-94b4-710e83144124
92054
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
235 ;;; sym-comp.el ends here