complete.el 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123
  1. ;;; complete.el --- partial completion mechanism plus other goodies
  2. ;; Copyright (C) 1990-1993, 1999-2012 Free Software Foundation, Inc.
  3. ;; Author: Dave Gillespie <daveg@synaptics.com>
  4. ;; Keywords: abbrev convenience
  5. ;; Obsolete-since: 24.1
  6. ;;
  7. ;; Special thanks to Hallvard Furuseth for his many ideas and contributions.
  8. ;; This file is part of GNU Emacs.
  9. ;; GNU Emacs is free software: you can redistribute it and/or modify
  10. ;; it under the terms of the GNU General Public License as published by
  11. ;; the Free Software Foundation, either version 3 of the License, or
  12. ;; (at your option) any later version.
  13. ;; GNU Emacs is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17. ;; You should have received a copy of the GNU General Public License
  18. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  19. ;;; Commentary:
  20. ;; Extended completion for the Emacs minibuffer.
  21. ;;
  22. ;; The basic idea is that the command name or other completable text is
  23. ;; divided into words and each word is completed separately, so that
  24. ;; "M-x p-b" expands to "M-x print-buffer". If the entry is ambiguous
  25. ;; each word is completed as much as possible and then the cursor is
  26. ;; left at the first position where typing another letter will resolve
  27. ;; the ambiguity.
  28. ;;
  29. ;; Word separators for this purpose are hyphen, space, and period.
  30. ;; These would most likely occur in command names, Info menu items,
  31. ;; and file names, respectively. But all word separators are treated
  32. ;; alike at all times.
  33. ;;
  34. ;; This completion package replaces the old-style completer's key
  35. ;; bindings for TAB, SPC, RET, and `?'. The old completer is still
  36. ;; available on the Meta versions of those keys. If you set
  37. ;; PC-meta-flag to nil, the old completion keys will be left alone
  38. ;; and the partial completer will use the Meta versions of the keys.
  39. ;; Usage: M-x partial-completion-mode. During completable minibuffer entry,
  40. ;;
  41. ;; TAB means to do a partial completion;
  42. ;; SPC means to do a partial complete-word;
  43. ;; RET means to do a partial complete-and-exit;
  44. ;; ? means to do a partial completion-help.
  45. ;;
  46. ;; If you set PC-meta-flag to nil, then TAB, SPC, RET, and ? perform
  47. ;; original Emacs completions, and M-TAB etc. do partial completion.
  48. ;; To do this, put the command,
  49. ;;
  50. ;; (setq PC-meta-flag nil)
  51. ;;
  52. ;; in your .emacs file. To load partial completion automatically, put
  53. ;;
  54. ;; (partial-completion-mode t)
  55. ;;
  56. ;; in your .emacs file, too. Things will be faster if you byte-compile
  57. ;; this file when you install it.
  58. ;;
  59. ;; As an extra feature, in cases where RET would not normally
  60. ;; complete (such as `C-x b'), the M-RET key will always do a partial
  61. ;; complete-and-exit. Thus `C-x b f.c RET' will select or create a
  62. ;; buffer called "f.c", but `C-x b f.c M-RET' will select the existing
  63. ;; buffer whose name matches that pattern (perhaps "filing.c").
  64. ;; (PC-meta-flag does not affect this behavior; M-RET used to be
  65. ;; undefined in this situation.)
  66. ;;
  67. ;; The regular M-TAB (lisp-complete-symbol) command also supports
  68. ;; partial completion in this package.
  69. ;; In addition, this package includes a feature for accessing include
  70. ;; files. For example, `C-x C-f <sys/time.h> RET' reads the file
  71. ;; /usr/include/sys/time.h. The variable PC-include-file-path is a
  72. ;; list of directories in which to search for include files. Completion
  73. ;; is supported in include file names.
  74. ;;; Code:
  75. (defgroup partial-completion nil
  76. "Partial Completion of items."
  77. :prefix "pc-"
  78. :group 'minibuffer
  79. :group 'convenience)
  80. (defcustom PC-first-char 'find-file
  81. "Control how the first character of a string is to be interpreted.
  82. If nil, the first character of a string is not taken literally if it is a word
  83. delimiter, so that \".e\" matches \"*.e*\".
  84. If t, the first character of a string is always taken literally even if it is a
  85. word delimiter, so that \".e\" matches \".e*\".
  86. If non-nil and non-t, the first character is taken literally only for file name
  87. completion."
  88. :type '(choice (const :tag "delimiter" nil)
  89. (const :tag "literal" t)
  90. (other :tag "find-file" find-file))
  91. :group 'partial-completion)
  92. (defcustom PC-meta-flag t
  93. "If non-nil, TAB means PC completion and M-TAB means normal completion.
  94. Otherwise, TAB means normal completion and M-TAB means Partial Completion."
  95. :type 'boolean
  96. :group 'partial-completion)
  97. (defcustom PC-word-delimiters "-_. "
  98. "A string of characters treated as word delimiters for completion.
  99. Some arcane rules:
  100. If `]' is in this string, it must come first.
  101. If `^' is in this string, it must not come first.
  102. If `-' is in this string, it must come first or right after `]'.
  103. In other words, if S is this string, then `[S]' must be a valid Emacs regular
  104. expression (not containing character ranges like `a-z')."
  105. :type 'string
  106. :group 'partial-completion)
  107. (defcustom PC-include-file-path '("/usr/include" "/usr/local/include")
  108. "A list of directories in which to look for include files.
  109. If nil, means use the colon-separated path in the variable $INCPATH instead."
  110. :type '(repeat directory)
  111. :group 'partial-completion)
  112. (defcustom PC-disable-includes nil
  113. "If non-nil, include-file support in \\[find-file] is disabled."
  114. :type 'boolean
  115. :group 'partial-completion)
  116. (defvar PC-default-bindings t
  117. "If non-nil, default partial completion key bindings are suppressed.")
  118. (defvar PC-env-vars-alist nil
  119. "A list of the environment variable names and values.")
  120. (defun PC-bindings (bind)
  121. (let ((completion-map minibuffer-local-completion-map)
  122. (must-match-map minibuffer-local-must-match-map))
  123. (cond ((not bind)
  124. ;; These bindings are the default bindings. It would be better to
  125. ;; restore the previous bindings.
  126. (define-key read-expression-map "\e\t" 'lisp-complete-symbol)
  127. (define-key completion-map "\t" 'minibuffer-complete)
  128. (define-key completion-map " " 'minibuffer-complete-word)
  129. (define-key completion-map "?" 'minibuffer-completion-help)
  130. (define-key must-match-map "\r" 'minibuffer-complete-and-exit)
  131. (define-key must-match-map "\n" 'minibuffer-complete-and-exit)
  132. (define-key global-map [remap lisp-complete-symbol] nil))
  133. (PC-default-bindings
  134. (define-key read-expression-map "\e\t" 'PC-lisp-complete-symbol)
  135. (define-key completion-map "\t" 'PC-complete)
  136. (define-key completion-map " " 'PC-complete-word)
  137. (define-key completion-map "?" 'PC-completion-help)
  138. (define-key completion-map "\e\t" 'PC-complete)
  139. (define-key completion-map "\e " 'PC-complete-word)
  140. (define-key completion-map "\e\r" 'PC-force-complete-and-exit)
  141. (define-key completion-map "\e\n" 'PC-force-complete-and-exit)
  142. (define-key completion-map "\e?" 'PC-completion-help)
  143. (define-key must-match-map "\r" 'PC-complete-and-exit)
  144. (define-key must-match-map "\n" 'PC-complete-and-exit)
  145. (define-key must-match-map "\e\r" 'PC-complete-and-exit)
  146. (define-key must-match-map "\e\n" 'PC-complete-and-exit)
  147. (define-key global-map [remap lisp-complete-symbol] 'PC-lisp-complete-symbol)))))
  148. (defvar PC-do-completion-end nil
  149. "Internal variable used by `PC-do-completion'.")
  150. (make-variable-buffer-local 'PC-do-completion-end)
  151. (defvar PC-goto-end nil
  152. "Internal variable set in `PC-do-completion', used in
  153. `choose-completion-string-functions'.")
  154. (make-variable-buffer-local 'PC-goto-end)
  155. ;;;###autoload
  156. (define-minor-mode partial-completion-mode
  157. "Toggle Partial Completion mode.
  158. With prefix ARG, turn Partial Completion mode on if ARG is positive.
  159. When Partial Completion mode is enabled, TAB (or M-TAB if `PC-meta-flag' is
  160. nil) is enhanced so that if some string is divided into words and each word is
  161. delimited by a character in `PC-word-delimiters', partial words are completed
  162. as much as possible and `*' characters are treated likewise in file names.
  163. For example, M-x p-c-m expands to M-x partial-completion-mode since no other
  164. command begins with that sequence of characters, and
  165. \\[find-file] f_b.c TAB might complete to foo_bar.c if that file existed and no
  166. other file in that directory begins with that sequence of characters.
  167. Unless `PC-disable-includes' is non-nil, the `<...>' sequence is interpreted
  168. specially in \\[find-file]. For example,
  169. \\[find-file] <sys/time.h> RET finds the file `/usr/include/sys/time.h'.
  170. See also the variable `PC-include-file-path'.
  171. Partial Completion mode extends the meaning of `completion-auto-help' (which
  172. see), so that if it is neither nil nor t, Emacs shows the `*Completions*'
  173. buffer only on the second attempt to complete. That is, if TAB finds nothing
  174. to complete, the first TAB just says \"Next char not unique\" and the
  175. second TAB brings up the `*Completions*' buffer."
  176. :global t :group 'partial-completion
  177. ;; Deal with key bindings...
  178. (PC-bindings partial-completion-mode)
  179. ;; Deal with include file feature...
  180. (cond ((not partial-completion-mode)
  181. (remove-hook 'find-file-not-found-functions 'PC-look-for-include-file))
  182. ((not PC-disable-includes)
  183. (add-hook 'find-file-not-found-functions 'PC-look-for-include-file)))
  184. ;; Adjust the completion selection in *Completion* buffers to the way
  185. ;; we work. The default minibuffer completion code only completes the
  186. ;; text before point and leaves the text after point alone (new in
  187. ;; Emacs-22). In contrast we use the whole text and we even sometimes
  188. ;; move point to a place before EOB, to indicate the first position where
  189. ;; there's a difference, so when the user uses choose-completion, we have
  190. ;; to trick choose-completion into replacing the whole minibuffer text
  191. ;; rather than only the text before point. --Stef
  192. (funcall
  193. (if partial-completion-mode 'add-hook 'remove-hook)
  194. 'choose-completion-string-functions
  195. (lambda (choice buffer &rest ignored)
  196. ;; When completing M-: (lisp- ) with point before the ), it is
  197. ;; not appropriate to go to point-max (unlike the filename case).
  198. (if (and (not PC-goto-end)
  199. (minibufferp buffer))
  200. (goto-char (point-max))
  201. ;; Need a similar hack for the non-minibuffer-case -- gm.
  202. (when PC-do-completion-end
  203. (goto-char PC-do-completion-end)
  204. (setq PC-do-completion-end nil)))
  205. (setq PC-goto-end nil)
  206. nil))
  207. ;; Build the env-completion and mapping table.
  208. (when (and partial-completion-mode (null PC-env-vars-alist))
  209. (setq PC-env-vars-alist
  210. (mapcar (lambda (string)
  211. (let ((d (string-match "=" string)))
  212. (cons (concat "$" (substring string 0 d))
  213. (and d (substring string (1+ d))))))
  214. process-environment))))
  215. (defun PC-complete ()
  216. "Like minibuffer-complete, but allows \"b--di\"-style abbreviations.
  217. For example, \"M-x b--di\" would match `byte-recompile-directory', or any
  218. name which consists of three or more words, the first beginning with \"b\"
  219. and the third beginning with \"di\".
  220. The pattern \"b--d\" is ambiguous for `byte-recompile-directory' and
  221. `beginning-of-defun', so this would produce a list of completions
  222. just like when normal Emacs completions are ambiguous.
  223. Word-delimiters for the purposes of Partial Completion are \"-\", \"_\",
  224. \".\", and SPC."
  225. (interactive)
  226. (if (PC-was-meta-key)
  227. (minibuffer-complete)
  228. ;; If the previous command was not this one,
  229. ;; never scroll, always retry completion.
  230. (or (eq last-command this-command)
  231. (setq minibuffer-scroll-window nil))
  232. (let ((window minibuffer-scroll-window))
  233. ;; If there's a fresh completion window with a live buffer,
  234. ;; and this command is repeated, scroll that window.
  235. (if (and window (window-buffer window)
  236. (buffer-name (window-buffer window)))
  237. (with-current-buffer (window-buffer window)
  238. (if (pos-visible-in-window-p (point-max) window)
  239. (set-window-start window (point-min) nil)
  240. (scroll-other-window)))
  241. (PC-do-completion nil)))))
  242. (defun PC-complete-word ()
  243. "Like `minibuffer-complete-word', but allows \"b--di\"-style abbreviations.
  244. See `PC-complete' for details.
  245. This can be bound to other keys, like `-' and `.', if you wish."
  246. (interactive)
  247. (if (eq (PC-was-meta-key) PC-meta-flag)
  248. (if (eq last-command-event ? )
  249. (minibuffer-complete-word)
  250. (self-insert-command 1))
  251. (self-insert-command 1)
  252. (if (eobp)
  253. (PC-do-completion 'word))))
  254. (defun PC-complete-space ()
  255. "Like `minibuffer-complete-word', but allows \"b--di\"-style abbreviations.
  256. See `PC-complete' for details.
  257. This is suitable for binding to other keys which should act just like SPC."
  258. (interactive)
  259. (if (eq (PC-was-meta-key) PC-meta-flag)
  260. (minibuffer-complete-word)
  261. (insert " ")
  262. (if (eobp)
  263. (PC-do-completion 'word))))
  264. (defun PC-complete-and-exit ()
  265. "Like `minibuffer-complete-and-exit', but allows \"b--di\"-style abbreviations.
  266. See `PC-complete' for details."
  267. (interactive)
  268. (if (eq (PC-was-meta-key) PC-meta-flag)
  269. (minibuffer-complete-and-exit)
  270. (PC-do-complete-and-exit)))
  271. (defun PC-force-complete-and-exit ()
  272. "Like `minibuffer-complete-and-exit', but allows \"b--di\"-style abbreviations.
  273. See `PC-complete' for details."
  274. (interactive)
  275. (let ((minibuffer-completion-confirm nil))
  276. (PC-do-complete-and-exit)))
  277. (defun PC-do-complete-and-exit ()
  278. (cond
  279. ((= (point-max) (minibuffer-prompt-end))
  280. ;; Duplicate the "bug" that Info-menu relies on...
  281. (exit-minibuffer))
  282. ((eq minibuffer-completion-confirm 'confirm)
  283. (if (or (eq last-command this-command)
  284. (test-completion (field-string)
  285. minibuffer-completion-table
  286. minibuffer-completion-predicate))
  287. (exit-minibuffer)
  288. (PC-temp-minibuffer-message " [Confirm]")))
  289. ((eq minibuffer-completion-confirm 'confirm-after-completion)
  290. ;; Similar to the above, but only if trying to exit immediately
  291. ;; after typing TAB (this catches most minibuffer typos).
  292. (if (and (memq last-command minibuffer-confirm-exit-commands)
  293. (not (test-completion (field-string)
  294. minibuffer-completion-table
  295. minibuffer-completion-predicate)))
  296. (PC-temp-minibuffer-message " [Confirm]")
  297. (exit-minibuffer)))
  298. (t
  299. (let ((flag (PC-do-completion 'exit)))
  300. (and flag
  301. (if (or (eq flag 'complete)
  302. (not minibuffer-completion-confirm))
  303. (exit-minibuffer)
  304. (PC-temp-minibuffer-message " [Confirm]")))))))
  305. (defun PC-completion-help ()
  306. "Like `minibuffer-completion-help', but allows \"b--di\"-style abbreviations.
  307. See `PC-complete' for details."
  308. (interactive)
  309. (if (eq (PC-was-meta-key) PC-meta-flag)
  310. (minibuffer-completion-help)
  311. (PC-do-completion 'help)))
  312. (defun PC-was-meta-key ()
  313. (or (/= (length (this-command-keys)) 1)
  314. (let ((key (aref (this-command-keys) 0)))
  315. (if (integerp key)
  316. (>= key 128)
  317. (not (null (memq 'meta (event-modifiers key))))))))
  318. (defvar PC-ignored-extensions 'empty-cache)
  319. (defvar PC-delims 'empty-cache)
  320. (defvar PC-ignored-regexp nil)
  321. (defvar PC-word-failed-flag nil)
  322. (defvar PC-delim-regex nil)
  323. (defvar PC-ndelims-regex nil)
  324. (defvar PC-delims-list nil)
  325. (defvar PC-completion-as-file-name-predicate
  326. (lambda () minibuffer-completing-file-name)
  327. "A function testing whether a minibuffer completion now will work filename-style.
  328. The function takes no arguments, and typically looks at the value
  329. of `minibuffer-completion-table' and the minibuffer contents.")
  330. ;; Returns the sequence of non-delimiter characters that follow regexp in string.
  331. (defun PC-chunk-after (string regexp)
  332. (if (not (string-match regexp string))
  333. (let ((message "String %s didn't match regexp %s"))
  334. (message message string regexp)
  335. (error message string regexp)))
  336. (let ((result (substring string (match-end 0))))
  337. ;; result may contain multiple chunks
  338. (if (string-match PC-delim-regex result)
  339. (setq result (substring result 0 (match-beginning 0))))
  340. result))
  341. (defun test-completion-ignore-case (str table pred)
  342. "Like `test-completion', but ignores case when possible."
  343. ;; Binding completion-ignore-case to nil ensures, for compatibility with
  344. ;; standard completion, that the return value is exactly one of the
  345. ;; possibilities. Do this binding only if pred is nil, out of paranoia;
  346. ;; perhaps it is safe even if pred is non-nil.
  347. (if pred
  348. (test-completion str table pred)
  349. (let ((completion-ignore-case nil))
  350. (test-completion str table pred))))
  351. ;; The following function is an attempt to work around two problems:
  352. ;; (1) When complete.el was written, (try-completion "" '(("") (""))) used to
  353. ;; return the value "". With a change from 2002-07-07 it returns t which caused
  354. ;; `PC-lisp-complete-symbol' to fail with a "Wrong type argument: sequencep, t"
  355. ;; error. `PC-try-completion' returns STRING in this case.
  356. ;; (2) (try-completion "" '((""))) returned t before the above-mentioned change.
  357. ;; Since `PC-chop-word' operates on the return value of `try-completion' this
  358. ;; case might have provoked a similar error as in (1). `PC-try-completion'
  359. ;; returns "" instead. I don't know whether this is a real problem though.
  360. ;; Since `PC-try-completion' is not a guaranteed to fix these bugs reliably, you
  361. ;; should try to look at the following discussions when you encounter problems:
  362. ;; - emacs-pretest-bug ("Partial Completion" starting 2007-02-23),
  363. ;; - emacs-devel ("[address-of-OP: Partial completion]" starting 2007-02-24),
  364. ;; - emacs-devel ("[address-of-OP: EVAL and mouse selection in *Completions*]"
  365. ;; starting 2007-03-05).
  366. (defun PC-try-completion (string alist &optional predicate)
  367. "Like `try-completion' but return STRING instead of t."
  368. (let ((result (try-completion string alist predicate)))
  369. (if (eq result t) string result)))
  370. ;; TODO document MODE magic...
  371. (defun PC-do-completion (&optional mode beg end goto-end)
  372. "Internal function to do the work of partial completion.
  373. Text to be completed lies between BEG and END. Normally when
  374. replacing text in the minibuffer, this function replaces up to
  375. point-max (as is appropriate for completing a file name). If
  376. GOTO-END is non-nil, however, it instead replaces up to END."
  377. (or beg (setq beg (minibuffer-prompt-end)))
  378. (or end (setq end (point-max)))
  379. (let* ((table (if (eq minibuffer-completion-table 'read-file-name-internal)
  380. 'PC-read-file-name-internal
  381. minibuffer-completion-table))
  382. (pred minibuffer-completion-predicate)
  383. (filename (funcall PC-completion-as-file-name-predicate))
  384. (dirname nil) ; non-nil only if a filename is being completed
  385. ;; The following used to be "(dirlength 0)" which caused the erasure of
  386. ;; the entire buffer text before `point' when inserting a completion
  387. ;; into a buffer.
  388. dirlength
  389. (str (buffer-substring beg end))
  390. (incname (and filename (string-match "<\\([^\"<>]*\\)>?$" str)))
  391. (ambig nil)
  392. basestr origstr
  393. env-on
  394. regex
  395. p offset
  396. abbreviated
  397. (poss nil)
  398. helpposs
  399. (case-fold-search completion-ignore-case))
  400. ;; Check if buffer contents can already be considered complete
  401. (if (and (eq mode 'exit)
  402. (test-completion str table pred))
  403. 'complete
  404. ;; Do substitutions in directory names
  405. (and filename
  406. (setq basestr (or (file-name-directory str) ""))
  407. (setq dirlength (length basestr))
  408. ;; Do substitutions in directory names
  409. (setq p (substitute-in-file-name basestr))
  410. (not (string-equal basestr p))
  411. (setq str (concat p (file-name-nondirectory str)))
  412. (progn
  413. (delete-region beg end)
  414. (insert str)
  415. (setq end (+ beg (length str)))))
  416. ;; Prepare various delimiter strings
  417. (or (equal PC-word-delimiters PC-delims)
  418. (setq PC-delims PC-word-delimiters
  419. PC-delim-regex (concat "[" PC-delims "]")
  420. PC-ndelims-regex (concat "[^" PC-delims "]*")
  421. PC-delims-list (append PC-delims nil)))
  422. ;; Add wildcards if necessary
  423. (and filename
  424. (let ((dir (file-name-directory str))
  425. (file (file-name-nondirectory str))
  426. ;; The base dir for file-completion was passed in `predicate'.
  427. (default-directory (if (stringp pred) (expand-file-name pred)
  428. default-directory)))
  429. (while (and (stringp dir) (not (file-directory-p dir)))
  430. (setq dir (directory-file-name dir))
  431. (setq file (concat (replace-regexp-in-string
  432. PC-delim-regex "*\\&"
  433. (file-name-nondirectory dir))
  434. "*/" file))
  435. (setq dir (file-name-directory dir)))
  436. (setq origstr str str (concat dir file))))
  437. ;; Look for wildcard expansions in directory name
  438. (and filename
  439. (string-match "\\*.*/" str)
  440. (let ((pat str)
  441. ;; The base dir for file-completion was passed in `predicate'.
  442. (default-directory (if (stringp pred) (expand-file-name pred)
  443. default-directory))
  444. files)
  445. (setq p (1+ (string-match "/[^/]*\\'" pat)))
  446. (while (setq p (string-match PC-delim-regex pat p))
  447. (setq pat (concat (substring pat 0 p)
  448. "*"
  449. (substring pat p))
  450. p (+ p 2)))
  451. (setq files (file-expand-wildcards (concat pat "*")))
  452. (if files
  453. (let ((dir (file-name-directory (car files)))
  454. (p files))
  455. (while (and (setq p (cdr p))
  456. (equal dir (file-name-directory (car p)))))
  457. (if p
  458. (setq filename nil table nil
  459. pred (if (stringp pred) nil pred)
  460. ambig t)
  461. (delete-region beg end)
  462. (setq str (concat dir (file-name-nondirectory str)))
  463. (insert str)
  464. (setq end (+ beg (length str)))))
  465. (if origstr
  466. ;; If the wildcards were introduced by us, it's
  467. ;; possible that PC-read-file-name-internal can
  468. ;; still find matches for the original string
  469. ;; even if we couldn't, so remove the added
  470. ;; wildcards.
  471. (setq str origstr)
  472. (setq filename nil table nil
  473. pred (if (stringp pred) nil pred))))))
  474. ;; Strip directory name if appropriate
  475. (if filename
  476. (if incname
  477. (setq basestr (substring str incname)
  478. dirname (substring str 0 incname))
  479. (setq basestr (file-name-nondirectory str)
  480. dirname (file-name-directory str))
  481. ;; Make sure str is consistent with its directory and basename
  482. ;; parts. This is important on DOZe'NT systems when str only
  483. ;; includes a drive letter, like in "d:".
  484. (setq str (concat dirname basestr)))
  485. (setq basestr str))
  486. ;; Convert search pattern to a standard regular expression
  487. (setq regex (regexp-quote basestr)
  488. offset (if (and (> (length regex) 0)
  489. (not (eq (aref basestr 0) ?\*))
  490. (or (eq PC-first-char t)
  491. (and PC-first-char filename))) 1 0)
  492. p offset)
  493. (while (setq p (string-match PC-delim-regex regex p))
  494. (if (eq (aref regex p) ? )
  495. (setq regex (concat (substring regex 0 p)
  496. PC-ndelims-regex
  497. PC-delim-regex
  498. (substring regex (1+ p)))
  499. p (+ p (length PC-ndelims-regex) (length PC-delim-regex)))
  500. (let ((bump (if (memq (aref regex p)
  501. '(?$ ?^ ?\. ?* ?+ ?? ?[ ?] ?\\))
  502. -1 0)))
  503. (setq regex (concat (substring regex 0 (+ p bump))
  504. PC-ndelims-regex
  505. (substring regex (+ p bump)))
  506. p (+ p (length PC-ndelims-regex) 1)))))
  507. (setq p 0)
  508. (if filename
  509. (while (setq p (string-match "\\\\\\*" regex p))
  510. (setq regex (concat (substring regex 0 p)
  511. "[^/]*"
  512. (substring regex (+ p 2))))))
  513. ;;(setq the-regex regex)
  514. (setq regex (concat "\\`" regex))
  515. (and (> (length basestr) 0)
  516. (= (aref basestr 0) ?$)
  517. (setq env-on t
  518. table PC-env-vars-alist
  519. pred nil))
  520. ;; Find an initial list of possible completions
  521. (unless (setq p (string-match (concat PC-delim-regex
  522. (if filename "\\|\\*" ""))
  523. str
  524. (+ (length dirname) offset)))
  525. ;; Minibuffer contains no hyphens -- simple case!
  526. (setq poss (all-completions (if env-on basestr str)
  527. table
  528. pred))
  529. (unless (or poss (string-equal str ""))
  530. ;; Try completion as an abbreviation, e.g. "mvb" ->
  531. ;; "m-v-b" -> "multiple-value-bind", but only for
  532. ;; non-empty strings.
  533. (setq origstr str
  534. abbreviated t)
  535. (if filename
  536. (cond
  537. ;; "alpha" or "/alpha" -> expand whole path.
  538. ((string-match "^/?\\([A-Za-z0-9]+\\)$" str)
  539. (setq
  540. basestr ""
  541. p nil
  542. poss (file-expand-wildcards
  543. (concat "/"
  544. (mapconcat #'list (match-string 1 str) "*/")
  545. "*"))
  546. beg (1- beg)))
  547. ;; Alphanumeric trailer -> expand trailing file
  548. ((string-match "^\\(.+/\\)\\([A-Za-z0-9]+\\)$" str)
  549. (setq regex (concat "\\`"
  550. (mapconcat #'list
  551. (match-string 2 str)
  552. "[A-Za-z0-9]*[^A-Za-z0-9]"))
  553. p (1+ (length (match-string 1 str))))))
  554. (setq regex (concat "\\`" (mapconcat (lambda (c)
  555. (regexp-quote (string c)))
  556. str "[^-]*-"))
  557. p 1))))
  558. (when p
  559. ;; Use all-completions to do an initial cull. This is a big win,
  560. ;; since all-completions is written in C!
  561. (let ((compl (all-completions (if env-on
  562. (file-name-nondirectory (substring str 0 p))
  563. (substring str 0 p))
  564. table
  565. pred)))
  566. (setq p compl)
  567. (when (and compl abbreviated)
  568. (if filename
  569. (progn
  570. (setq p nil)
  571. (dolist (x compl)
  572. (when (string-match regex x)
  573. (push x p)))
  574. (setq basestr (try-completion "" p)))
  575. (setq basestr (mapconcat 'list str "-"))
  576. (delete-region beg end)
  577. (setq end (+ beg (length basestr)))
  578. (insert basestr))))
  579. (while p
  580. (and (string-match regex (car p))
  581. (progn
  582. (set-text-properties 0 (length (car p)) '() (car p))
  583. (setq poss (cons (car p) poss))))
  584. (setq p (cdr p))))
  585. ;; If table had duplicates, they can be here.
  586. (delete-dups poss)
  587. ;; Handle completion-ignored-extensions
  588. (and filename
  589. (not (eq mode 'help))
  590. (let ((p2 poss))
  591. ;; Build a regular expression representing the extensions list
  592. (or (equal completion-ignored-extensions PC-ignored-extensions)
  593. (setq PC-ignored-regexp
  594. (concat "\\("
  595. (mapconcat
  596. 'regexp-quote
  597. (setq PC-ignored-extensions
  598. completion-ignored-extensions)
  599. "\\|")
  600. "\\)\\'")))
  601. ;; Check if there are any without an ignored extension.
  602. ;; Also ignore `.' and `..'.
  603. (setq p nil)
  604. (while p2
  605. (or (string-match PC-ignored-regexp (car p2))
  606. (string-match "\\(\\`\\|/\\)[.][.]?/?\\'" (car p2))
  607. (setq p (cons (car p2) p)))
  608. (setq p2 (cdr p2)))
  609. ;; If there are "good" names, use them
  610. (and p (setq poss p))))
  611. ;; Now we have a list of possible completions
  612. (cond
  613. ;; No valid completions found
  614. ((null poss)
  615. (if (and (eq mode 'word)
  616. (not PC-word-failed-flag))
  617. (let ((PC-word-failed-flag t))
  618. (delete-char -1)
  619. (PC-do-completion 'word))
  620. (when abbreviated
  621. (delete-region beg end)
  622. (insert origstr))
  623. (beep)
  624. (PC-temp-minibuffer-message (if ambig
  625. " [Ambiguous dir name]"
  626. (if (eq mode 'help)
  627. " [No completions]"
  628. " [No match]")))
  629. nil))
  630. ;; More than one valid completion found
  631. ((or (cdr (setq helpposs poss))
  632. (memq mode '(help word)))
  633. ;; Is the actual string one of the possible completions?
  634. (setq p (and (not (eq mode 'help)) poss))
  635. (while (and p
  636. (not (string-equal (car p) basestr)))
  637. (setq p (cdr p)))
  638. (and p (null mode)
  639. (PC-temp-minibuffer-message " [Complete, but not unique]"))
  640. (if (and p
  641. (not (and (null mode)
  642. (eq this-command last-command))))
  643. t
  644. ;; If ambiguous, try for a partial completion
  645. (let ((improved nil)
  646. prefix
  647. (pt nil)
  648. (skip "\\`"))
  649. ;; Check if next few letters are the same in all cases
  650. (if (and (not (eq mode 'help))
  651. (setq prefix (PC-try-completion
  652. (PC-chunk-after basestr skip) poss)))
  653. (let ((first t) i)
  654. (if (eq mode 'word)
  655. (setq prefix (PC-chop-word prefix basestr)))
  656. (goto-char (+ beg (length dirname)))
  657. (while (and (progn
  658. (setq i 0) ; index into prefix string
  659. (while (< i (length prefix))
  660. (if (and (< (point) end)
  661. (or (eq (downcase (aref prefix i))
  662. (downcase (following-char)))
  663. (and (looking-at " ")
  664. (memq (aref prefix i)
  665. PC-delims-list))))
  666. ;; replace " " by the actual delimiter
  667. ;; or input char by prefix char
  668. (progn
  669. (delete-char 1)
  670. (insert (substring prefix i (1+ i))))
  671. ;; insert a new character
  672. (progn
  673. (and filename (looking-at "\\*")
  674. (progn
  675. (delete-char 1)
  676. (setq end (1- end))))
  677. (setq improved t)
  678. (insert (substring prefix i (1+ i)))
  679. (setq end (1+ end))))
  680. (setq i (1+ i)))
  681. (or pt (setq pt (point)))
  682. (looking-at PC-delim-regex))
  683. (setq skip (concat skip
  684. (regexp-quote prefix)
  685. PC-ndelims-regex)
  686. prefix (PC-try-completion
  687. (PC-chunk-after
  688. ;; not basestr, because that does
  689. ;; not reflect insertions
  690. (buffer-substring
  691. (+ beg (length dirname)) end)
  692. skip)
  693. (mapcar
  694. (lambda (x)
  695. (when (string-match skip x)
  696. (substring x (match-end 0))))
  697. poss)))
  698. (or (> i 0) (> (length prefix) 0))
  699. (or (not (eq mode 'word))
  700. (and first (> (length prefix) 0)
  701. (setq first nil
  702. prefix (substring prefix 0 1))))))
  703. (goto-char (if (eq mode 'word) end
  704. (or pt beg)))))
  705. (if (and (eq mode 'word)
  706. (not PC-word-failed-flag))
  707. (if improved
  708. ;; We changed it... would it be complete without the space?
  709. (if (test-completion (buffer-substring
  710. (field-beginning) (1- end))
  711. table pred)
  712. (delete-region (1- end) end)))
  713. (if improved
  714. ;; We changed it... enough to be complete?
  715. (and (eq mode 'exit)
  716. (test-completion-ignore-case (field-string) table pred))
  717. ;; If totally ambiguous, display a list of completions
  718. (if (or (eq completion-auto-help t)
  719. (and completion-auto-help
  720. (eq last-command this-command))
  721. (eq mode 'help))
  722. (let ((prompt-end (minibuffer-prompt-end)))
  723. (with-output-to-temp-buffer "*Completions*"
  724. (display-completion-list (sort helpposs 'string-lessp))
  725. (setq PC-do-completion-end end
  726. PC-goto-end goto-end)
  727. (with-current-buffer standard-output
  728. ;; Record which part of the buffer we are completing
  729. ;; so that choosing a completion from the list
  730. ;; knows how much old text to replace.
  731. ;; This was briefly nil in the non-dirname case.
  732. ;; However, if one calls PC-lisp-complete-symbol
  733. ;; on "(ne-f" with point on the hyphen, PC offers
  734. ;; all completions starting with "(ne", some of
  735. ;; which do not match the "-f" part (maybe it
  736. ;; should not, but it does). In such cases,
  737. ;; completion gets confused trying to figure out
  738. ;; how much to replace, so we tell it explicitly
  739. ;; (ie, the number of chars in the buffer before beg).
  740. ;;
  741. ;; Note that choose-completion-string-functions
  742. ;; plays around with point.
  743. (setq completion-base-size (if dirname
  744. dirlength
  745. (- beg prompt-end))))))
  746. (PC-temp-minibuffer-message " [Next char not unique]"))
  747. ;; Expansion of filenames is not reversible,
  748. ;; so just keep the prefix.
  749. (when (and abbreviated filename)
  750. (delete-region (point) end))
  751. nil)))))
  752. ;; Only one possible completion
  753. (t
  754. (if (and (equal basestr (car poss))
  755. (not (and env-on filename))
  756. (not abbreviated))
  757. (if (null mode)
  758. (PC-temp-minibuffer-message " [Sole completion]"))
  759. (delete-region beg end)
  760. (insert (format "%s"
  761. (if filename
  762. (substitute-in-file-name (concat dirname (car poss)))
  763. (car poss)))))
  764. t)))))
  765. (defun PC-chop-word (new old)
  766. (let ((i -1)
  767. (j -1))
  768. (while (and (setq i (string-match PC-delim-regex old (1+ i)))
  769. (setq j (string-match PC-delim-regex new (1+ j)))))
  770. (if (and j
  771. (or (not PC-word-failed-flag)
  772. (setq j (string-match PC-delim-regex new (1+ j)))))
  773. (substring new 0 (1+ j))
  774. new)))
  775. (defvar PC-not-minibuffer nil)
  776. (defun PC-temp-minibuffer-message (message)
  777. "A Lisp version of `temp_minibuffer_message' from minibuf.c."
  778. (cond (PC-not-minibuffer
  779. (message "%s" message)
  780. (sit-for 2)
  781. (message ""))
  782. ((fboundp 'temp-minibuffer-message)
  783. (temp-minibuffer-message message))
  784. (t
  785. (let ((point-max (point-max)))
  786. (save-excursion
  787. (goto-char point-max)
  788. (insert message))
  789. (let ((inhibit-quit t))
  790. (sit-for 2)
  791. (delete-region point-max (point-max))
  792. (when quit-flag
  793. (setq quit-flag nil
  794. unread-command-events '(7))))))))
  795. ;; Does not need to be buffer-local (?) because only used when one
  796. ;; PC-l-c-s immediately follows another.
  797. (defvar PC-lisp-complete-end nil
  798. "Internal variable used by `PC-lisp-complete-symbol'.")
  799. (defun PC-lisp-complete-symbol ()
  800. "Perform completion on Lisp symbol preceding point.
  801. That symbol is compared against the symbols that exist
  802. and any additional characters determined by what is there
  803. are inserted.
  804. If the symbol starts just after an open-parenthesis,
  805. only symbols with function definitions are considered.
  806. Otherwise, all symbols with function definitions, values
  807. or properties are considered."
  808. (interactive)
  809. (let* ((end
  810. (save-excursion
  811. (with-syntax-table lisp-mode-syntax-table
  812. (skip-syntax-forward "_w")
  813. (point))))
  814. (beg (save-excursion
  815. (with-syntax-table lisp-mode-syntax-table
  816. (backward-sexp 1)
  817. (while (= (char-syntax (following-char)) ?\')
  818. (forward-char 1))
  819. (point))))
  820. (minibuffer-completion-table obarray)
  821. (minibuffer-completion-predicate
  822. (if (eq (char-after (1- beg)) ?\()
  823. 'fboundp
  824. (function (lambda (sym)
  825. (or (boundp sym) (fboundp sym)
  826. (symbol-plist sym))))))
  827. (PC-not-minibuffer t))
  828. ;; http://lists.gnu.org/archive/html/emacs-devel/2007-03/msg01211.html
  829. ;;
  830. ;; This deals with cases like running PC-l-c-s on "M-: (n-f".
  831. ;; The first call to PC-l-c-s expands this to "(ne-f", and moves
  832. ;; point to the hyphen [1]. If one calls PC-l-c-s immediately after,
  833. ;; then without the last-command check, one is offered all
  834. ;; completions of "(ne", which is presumably not what one wants.
  835. ;;
  836. ;; This is arguably (at least, it seems to be the existing intended
  837. ;; behavior) what one _does_ want if point has been explicitly
  838. ;; positioned on the hyphen. Note that if PC-do-completion (qv) binds
  839. ;; completion-base-size to nil, then completion does not replace the
  840. ;; correct amount of text in such cases.
  841. ;;
  842. ;; Neither of these problems occur when using PC for filenames in the
  843. ;; minibuffer, because in that case PC-do-completion is called without
  844. ;; an explicit value for END, and so uses (point-max). This is fine for
  845. ;; a filename, because the end of the filename must be at the end of
  846. ;; the minibuffer. The same is not true for lisp symbols.
  847. ;;
  848. ;; [1] An alternate fix would be to not move point to the hyphen
  849. ;; in such cases, but that would make the behavior different from
  850. ;; that for filenames. It seems PC moves point to the site of the
  851. ;; first difference between the possible completions.
  852. ;;
  853. ;; Alternatively alternatively, maybe end should be computed in
  854. ;; the same way as beg. That would change the behavior though.
  855. (if (equal last-command 'PC-lisp-complete-symbol)
  856. (PC-do-completion nil beg PC-lisp-complete-end t)
  857. (if PC-lisp-complete-end
  858. (move-marker PC-lisp-complete-end end)
  859. (setq PC-lisp-complete-end (copy-marker end t)))
  860. (PC-do-completion nil beg end t))))
  861. (defun PC-complete-as-file-name ()
  862. "Perform completion on file names preceding point.
  863. Environment vars are converted to their values."
  864. (interactive)
  865. (let* ((end (point))
  866. (beg (if (re-search-backward "[^\\][ \t\n\"\`\'][^ \t\n\"\`\']"
  867. (point-min) t)
  868. (+ (point) 2)
  869. (point-min)))
  870. (minibuffer-completion-table 'PC-read-file-name-internal)
  871. (minibuffer-completion-predicate nil)
  872. (PC-not-minibuffer t))
  873. (goto-char end)
  874. (PC-do-completion nil beg end)))
  875. ;; Facilities for loading C header files. This is independent from the
  876. ;; main completion code. See also the variable `PC-include-file-path'
  877. ;; at top of this file.
  878. (defun PC-look-for-include-file ()
  879. (if (string-match "[\"<]\\([^\"<>]*\\)[\">]?$" (buffer-file-name))
  880. (let ((name (substring (buffer-file-name)
  881. (match-beginning 1) (match-end 1)))
  882. (punc (aref (buffer-file-name) (match-beginning 0)))
  883. (path nil)
  884. new-buf)
  885. (kill-buffer (current-buffer))
  886. (if (equal name "")
  887. (with-current-buffer (car (buffer-list))
  888. (save-excursion
  889. (beginning-of-line)
  890. (if (looking-at
  891. "[ \t]*#[ \t]*include[ \t]+[<\"]\\(.+\\)[>\"][ \t]*[\n/]")
  892. (setq name (buffer-substring (match-beginning 1)
  893. (match-end 1))
  894. punc (char-after (1- (match-beginning 1))))
  895. ;; Suggested by Frank Siebenlist:
  896. (if (or (looking-at
  897. "[ \t]*([ \t]*load[ \t]+\"\\([^\"]+\\)\"")
  898. (looking-at
  899. "[ \t]*([ \t]*load-library[ \t]+\"\\([^\"]+\\)\"")
  900. (looking-at
  901. "[ \t]*([ \t]*require[ \t]+'\\([^\t )]+\\)[\t )]"))
  902. (progn
  903. (setq name (buffer-substring (match-beginning 1)
  904. (match-end 1))
  905. punc ?\<
  906. path load-path)
  907. (if (string-match "\\.elc$" name)
  908. (setq name (substring name 0 -1))
  909. (or (string-match "\\.el$" name)
  910. (setq name (concat name ".el")))))
  911. (error "Not on an #include line"))))))
  912. (or (string-match "\\.[[:alnum:]]+$" name)
  913. (setq name (concat name ".h")))
  914. (if (eq punc ?\<)
  915. (let ((path (or path (PC-include-file-path))))
  916. (while (and path
  917. (not (file-exists-p
  918. (concat (file-name-as-directory (car path))
  919. name))))
  920. (setq path (cdr path)))
  921. (if path
  922. (setq name (concat (file-name-as-directory (car path)) name))
  923. (error "No such include file: <%s>" name)))
  924. (let ((dir (with-current-buffer (car (buffer-list))
  925. default-directory)))
  926. (if (file-exists-p (concat dir name))
  927. (setq name (concat dir name))
  928. (error "No such include file: `%s'" name))))
  929. (setq new-buf (get-file-buffer name))
  930. (if new-buf
  931. ;; no need to verify last-modified time for this!
  932. (set-buffer new-buf)
  933. (set-buffer (create-file-buffer name))
  934. (erase-buffer)
  935. (insert-file-contents name t))
  936. ;; Returning non-nil with the new buffer current
  937. ;; is sufficient to tell find-file to use it.
  938. t)
  939. nil))
  940. (defun PC-include-file-path ()
  941. (or PC-include-file-path
  942. (let ((env (getenv "INCPATH"))
  943. (path nil)
  944. pos)
  945. (or env (error "No include file path specified"))
  946. (while (setq pos (string-match ":[^:]+$" env))
  947. (setq path (cons (substring env (1+ pos)) path)
  948. env (substring env 0 pos)))
  949. path)))
  950. ;; This is adapted from lib-complete.el, by Mike Williams.
  951. (defun PC-include-file-all-completions (file search-path &optional full)
  952. "Return all completions for FILE in any directory on SEARCH-PATH.
  953. If optional third argument FULL is non-nil, returned pathnames should be
  954. absolute rather than relative to some directory on the SEARCH-PATH."
  955. (setq search-path
  956. (mapcar (lambda (dir)
  957. (if dir (file-name-as-directory dir) default-directory))
  958. search-path))
  959. (if (file-name-absolute-p file)
  960. ;; It's an absolute file name, so don't need search-path
  961. (progn
  962. (setq file (expand-file-name file))
  963. (file-name-all-completions
  964. (file-name-nondirectory file) (file-name-directory file)))
  965. (let ((subdir (file-name-directory file))
  966. (ndfile (file-name-nondirectory file))
  967. file-lists)
  968. ;; Append subdirectory part to each element of search-path
  969. (if subdir
  970. (setq search-path
  971. (mapcar (lambda (dir) (concat dir subdir))
  972. search-path)
  973. file ))
  974. ;; Make list of completions in each directory on search-path
  975. (while search-path
  976. (let* ((dir (car search-path))
  977. (subdir (if full dir subdir)))
  978. (if (file-directory-p dir)
  979. (progn
  980. (setq file-lists
  981. (cons
  982. (mapcar (lambda (file) (concat subdir file))
  983. (file-name-all-completions ndfile
  984. (car search-path)))
  985. file-lists))))
  986. (setq search-path (cdr search-path))))
  987. ;; Compress out duplicates while building complete list (slloooow!)
  988. (let ((sorted (sort (apply 'nconc file-lists)
  989. (lambda (x y) (not (string-lessp x y)))))
  990. compressed)
  991. (while sorted
  992. (if (equal (car sorted) (car compressed)) nil
  993. (setq compressed (cons (car sorted) compressed)))
  994. (setq sorted (cdr sorted)))
  995. compressed))))
  996. (defun PC-read-file-name-internal (string pred action)
  997. "Extend `read-file-name-internal' to handle include files.
  998. This is only used by "
  999. (if (string-match "<\\([^\"<>]*\\)>?\\'" string)
  1000. (let* ((name (match-string 1 string))
  1001. (str2 (substring string (match-beginning 0)))
  1002. (completion-table
  1003. (mapcar (lambda (x)
  1004. (format (if (string-match "/\\'" x) "<%s" "<%s>") x))
  1005. (PC-include-file-all-completions
  1006. name (PC-include-file-path)))))
  1007. (cond
  1008. ((not completion-table) nil)
  1009. ((eq action 'lambda) (test-completion str2 completion-table nil))
  1010. ((eq action nil) (PC-try-completion str2 completion-table nil))
  1011. ((eq action t) (all-completions str2 completion-table nil))))
  1012. (read-file-name-internal string pred action)))
  1013. (provide 'complete)
  1014. ;;; complete.el ends here