annotate lisp/progmodes/sym-comp.el @ 92594:674c88622bd9

Move many autoloads to separate file, cal-loaddefs.el. Move defcustoms to start and re-order. (calendar-month-name-array, calendar-starred-day): No need to declare for compiler. (cal-loaddefs): Require it. (appt, chinese-calendar, calendar-tex): Move custom groups to the appropriate file. (diary-entry-marker, calendar-today-marker, calendar-holiday-marker): Reverse logic. (diary-face, diary-file-name-prefix-function, diary-include-string) (diary-glob-file-regexp-prefix, diary-face-attrs) (diary-file-name-prefix, sexp-diary-entry-symbol) (print-diary-entries-hook, list-diary-entries-hook) (nongregorian-diary-listing-hook, mark-diary-entries-hook) (nongregorian-diary-marking-hook, diary-list-include-blanks): Move to diary-lib. (all-christian-calendar-holidays, all-islamic-calendar-holidays) (all-bahai-calendar-holidays): Doc fix. (calendar-mark-ring): Add doc-string. (calendar-starred-day): Defvar it. (calendar-mode): Make calendar-starred-day local. (calendar-star-date): No need to make calendar-starred-day local.
author Glenn Morris <rgm@gnu.org>
date Sat, 08 Mar 2008 03:47:03 +0000
parents bae32624018f
children 52b7a8c22af5
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
92250
a2c5eb229cdf Change copyright to FSF, per the author's statement:
Glenn Morris <rgm@gnu.org>
parents: 92229
diff changeset
3 ;; Copyright (C) 2004, 2008 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
bae32624018f Standardize license text.
Glenn Morris <rgm@gnu.org>
parents: 92250
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
92229
a917f8addf17 Remove RCS keywords
Miles Bader <miles@gnu.org>
parents: 92123
diff changeset
13 ;; the Free Software Foundation; either version 3, or (at your option)
92054
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
14 ;; any later version.
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
92256
bae32624018f Standardize license text.
Glenn Morris <rgm@gnu.org>
parents: 92250
diff changeset
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
92250
a2c5eb229cdf Change copyright to FSF, per the author's statement:
Glenn Morris <rgm@gnu.org>
parents: 92229
diff changeset
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
a2c5eb229cdf Change copyright to FSF, per the author's statement:
Glenn Morris <rgm@gnu.org>
parents: 92229
diff changeset
24 ;; Boston, MA 02110-1301, USA.
92054
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
25
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
26 ;;; Commentary:
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
27
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
28 ;; This defines `symbol-complete', which is a generalization of the
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
29 ;; old `lisp-complete-symbol'. It provides the following hooks to
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
30 ;; allow major modes to set up completion appropriate for the mode:
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
31 ;; `symbol-completion-symbol-function',
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
32 ;; `symbol-completion-completions-function',
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
33 ;; `symbol-completion-predicate-function',
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
34 ;; `symbol-completion-transform-function'. Typically it is only
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
35 ;; necessary for a mode to set
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
36 ;; `symbol-completion-completions-function' locally and to bind
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
37 ;; `symbol-complete' appropriately.
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
38
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
39 ;; 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
40 ;; combining this with `complete-symbol'.
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
41
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
42 ;; There is also `symbol-completion-try-complete', for use with
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
43 ;; Hippie-exp.
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
44
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
45 ;;; Code:
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
46
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
47 ;;;; Mode-dependent symbol completion.
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
48
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
49 (defun symbol-completion-symbol ()
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
50 "Default `symbol-completion-symbol-function'.
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
51 Uses `current-word' with the buffer narrowed to the part before
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
52 point."
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
53 (save-restriction
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
54 ;; Narrow in case point is in the middle of a symbol -- we want
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
55 ;; just the preceeding part.
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
56 (narrow-to-region (point-min) (point))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
57 (current-word)))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
58
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
59 (defvar symbol-completion-symbol-function 'symbol-completion-symbol
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
60 "Function to return a partial symbol before point for completion.
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
61 The value it returns should be a string (or nil).
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
62 Major modes may set this locally if the default isn't appropriate.")
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
63
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
64 (defvar symbol-completion-completions-function nil
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
65 "Function to return possible symbol completions.
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
66 It takes an argument which is the string to be completed and
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
67 returns a value suitable for the second argument of
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
68 `try-completion'. This value need not use the argument, i.e. it
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
69 may be all possible completions, such as `obarray' in the case of
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
70 Emacs Lisp.
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
71
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
72 Major modes may set this locally to allow them to support
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
73 `symbol-complete'. See also `symbol-completion-symbol-function',
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
74 `symbol-completion-predicate-function' and
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
75 `symbol-completion-transform-function'.")
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
76
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
77 (defvar symbol-completion-predicate-function nil
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
78 "If non-nil, function to return a predicate for selecting symbol completions.
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
79 The function gets two args, the positions of the beginning and
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
80 end of the symbol to be completed.
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
81
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
82 Major modes may set this locally if the default isn't
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
83 appropriate. This is a function returning a predicate so that
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
84 the predicate can be context-dependent, e.g. to select only
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
85 function names if point is at a function call position. The
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
86 function's args may be useful for determining the context.")
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
87
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
88 (defvar symbol-completion-transform-function nil
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
89 "If non-nil, function to transform symbols in the symbol-completion buffer.
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
90 E.g., for Lisp, it may annotate the symbol as being a function,
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
91 not a variable.
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
92
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
93 The function takes the symbol name as argument. If it needs to
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
94 annotate this, it should return a value suitable as an element of
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
95 the list passed to `display-completion-list'.
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
96
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
97 The predicate being used for selecting completions (from
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
98 `symbol-completion-predicate-function') is available
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
99 dynamically-bound as `symbol-completion-predicate' in case the
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
100 transform needs it.")
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
101
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
102 (defvar displayed-completions)
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
103
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
104 ;;;###autoload
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
105 (defun symbol-complete (&optional predicate)
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
106 "Perform completion of the symbol preceding point.
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
107 This is done in a way appropriate to the current major mode,
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
108 perhaps by interrogating an inferior interpreter. Compare
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
109 `complete-symbol'.
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
110 If no characters can be completed, display a list of possible completions.
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
111 Repeating the command at that point scrolls the list.
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
112
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
113 When called from a program, optional arg PREDICATE is a predicate
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
114 determining which symbols are considered.
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
115
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
116 This function requires `symbol-completion-completions-function'
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
117 to be set buffer-locally. Variables `symbol-completion-symbol-function',
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
118 `symbol-completion-predicate-function' and
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
119 `symbol-completion-transform-function' are also consulted."
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
120 (interactive)
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
121 ;; Fixme: Punt to `complete-symbol' in this case?
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
122 (unless (functionp symbol-completion-completions-function)
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
123 (error "symbol-completion-completions-function not defined"))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
124 (let ((window (get-buffer-window "*Completions*")))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
125 (let* ((pattern (or (funcall symbol-completion-symbol-function)
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
126 (error "No preceding symbol to complete")))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
127 (predicate (or predicate
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
128 (if symbol-completion-predicate-function
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
129 (funcall symbol-completion-predicate-function
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
130 (- (point) (length pattern))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
131 (point)))))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
132 (completions (funcall symbol-completion-completions-function
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
133 pattern))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
134 (completion (try-completion pattern completions predicate)))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
135 ;; If this command was repeated, and there's a fresh completion
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
136 ;; window with a live buffer and a displayed completion list
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
137 ;; matching the current completions, then scroll the window.
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
138 (unless (and (eq last-command this-command)
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
139 window (window-live-p window) (window-buffer window)
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
140 (buffer-name (window-buffer window))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
141 (with-current-buffer (window-buffer window)
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
142 (if (equal displayed-completions
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
143 (all-completions pattern completions predicate))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
144 (progn
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
145 (if (pos-visible-in-window-p (point-max) window)
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
146 (set-window-start window (point-min))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
147 (save-selected-window
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
148 (select-window window)
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
149 (scroll-up)))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
150 t))))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
151 ;; Otherwise, do completion.
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
152 (cond ((eq completion t))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
153 ((null completion)
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
154 (message "Can't find completion for \"%s\"" pattern)
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
155 (ding))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
156 ((not (string= pattern completion))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
157 (delete-region (- (point) (length pattern)) (point))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
158 (insert completion))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
159 (t
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
160 (message "Making completion list...")
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
161 (let* ((list (all-completions pattern completions predicate))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
162 ;; In case the transform needs to access it.
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
163 (symbol-completion-predicate predicate)
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
164 ;; Copy since list is side-effected by sorting.
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
165 (copy (copy-sequence list)))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
166 (setq list (sort list 'string<))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
167 (if (functionp symbol-completion-transform-function)
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
168 (setq list
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
169 (mapcar (funcall
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
170 symbol-completion-transform-function)
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
171 list)))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
172 (with-output-to-temp-buffer "*Completions*"
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
173 (condition-case ()
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
174 (display-completion-list list pattern) ; Emacs 22
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
175 (error (display-completion-list list))))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
176 ;; Record the list for determining whether to scroll
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
177 ;; (above).
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
178 (with-current-buffer "*Completions*"
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
179 (set (make-local-variable 'displayed-completions) copy)))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
180 (message "Making completion list...%s" "done")))))))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
181
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
182 (eval-when-compile (require 'hippie-exp))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
183
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
184 ;;;###autoload
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
185 (defun symbol-completion-try-complete (old)
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
186 "Completion function for use with `hippie-expand'.
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
187 Uses `symbol-completion-symbol-function' and
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
188 `symbol-completion-completions-function'. It is intended to be
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
189 used something like this in a major mode which provides symbol
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
190 completion:
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
191
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
192 (if (featurep 'hippie-exp)
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
193 (set (make-local-variable 'hippie-expand-try-functions-list)
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
194 (cons 'symbol-completion-try-complete
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
195 hippie-expand-try-functions-list)))"
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
196 (when (and symbol-completion-symbol-function
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
197 symbol-completion-completions-function)
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
198 (unless old
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
199 (let ((symbol (funcall symbol-completion-symbol-function)))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
200 (he-init-string (- (point) (length symbol)) (point))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
201 (if (not (he-string-member he-search-string he-tried-table))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
202 (push he-search-string he-tried-table))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
203 (setq he-expand-list
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
204 (and symbol
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
205 (funcall symbol-completion-completions-function symbol)))))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
206 (while (and he-expand-list
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
207 (he-string-member (car he-expand-list) he-tried-table))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
208 (pop he-expand-list))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
209 (if he-expand-list
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
210 (progn
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
211 (he-substitute-string (pop he-expand-list))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
212 t)
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
213 (if old (he-reset-string))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
214 nil)))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
215
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
216 ;;; Emacs Lisp symbol completion.
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
217
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
218 (defun lisp-completion-symbol ()
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
219 "`symbol-completion-symbol-function' for Lisp."
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
220 (let ((end (point))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
221 (beg (with-syntax-table emacs-lisp-mode-syntax-table
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
222 (save-excursion
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
223 (backward-sexp 1)
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
224 (while (= (char-syntax (following-char)) ?\')
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
225 (forward-char 1))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
226 (point)))))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
227 (buffer-substring-no-properties beg end)))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
228
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
229 (defun lisp-completion-predicate (beg end)
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
230 "`symbol-completion-predicate-function' for Lisp."
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
231 (save-excursion
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
232 (goto-char beg)
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
233 (if (not (eq (char-before) ?\())
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
234 (lambda (sym) ;why not just nil ? -sm
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
235 ;To avoid interned symbols with
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
236 ;no slots. -- fx
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
237 (or (boundp sym) (fboundp sym)
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
238 (symbol-plist sym)))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
239 ;; Looks like a funcall position. Let's double check.
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
240 (if (condition-case nil
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
241 (progn (up-list -2) (forward-char 1)
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
242 (eq (char-after) ?\())
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
243 (error nil))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
244 ;; If the first element of the parent list is an open
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
245 ;; parenthesis we are probably not in a funcall position.
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
246 ;; Maybe a `let' varlist or something.
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
247 nil
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
248 ;; Else, we assume that a function name is expected.
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
249 'fboundp))))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
250
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
251 (defvar symbol-completion-predicate)
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
252
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
253 (defun lisp-symbol-completion-transform ()
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
254 "`symbol-completion-transform-function' for Lisp."
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
255 (lambda (elt)
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
256 (if (and (not (eq 'fboundp symbol-completion-predicate))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
257 (fboundp (intern elt)))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
258 (list elt " <f>")
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
259 elt)))
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
260
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
261 (provide 'sym-comp)
92123
e670b615aad9 Add arch tagline
Miles Bader <miles@gnu.org>
parents: 92054
diff changeset
262
e670b615aad9 Add arch tagline
Miles Bader <miles@gnu.org>
parents: 92054
diff changeset
263 ;; arch-tag: 6fcce616-f3c4-4751-94b4-710e83144124
92054
6d77acc71bc0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
264 ;;; sym-comp.el ends here