Klimi's new dotfiles with stow.
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

604 рядки
24 KiB

5 роки тому
  1. (require 'slime)
  2. (require 'slime-repl)
  3. (require 'slime-c-p-c)
  4. (require 'cl-lib)
  5. (define-slime-contrib slime-fuzzy
  6. "Fuzzy symbol completion."
  7. (:authors "Brian Downing <bdowning@lavos.net>"
  8. "Tobias C. Rittweiler <tcr@freebits.de>"
  9. "Attila Lendvai <attila.lendvai@gmail.com>")
  10. (:license "GPL")
  11. (:swank-dependencies swank-fuzzy)
  12. (:on-load
  13. (define-key slime-mode-map "\C-c\M-i" 'slime-fuzzy-complete-symbol)
  14. (when (featurep 'slime-repl)
  15. (define-key slime-repl-mode-map "\C-c\M-i"
  16. 'slime-fuzzy-complete-symbol))))
  17. (defcustom slime-fuzzy-completion-in-place t
  18. "When non-NIL the fuzzy symbol completion is done in place as
  19. opposed to moving the point to the completion buffer."
  20. :group 'slime-mode
  21. :type 'boolean)
  22. (defcustom slime-fuzzy-completion-limit 300
  23. "Only return and present this many symbols from swank."
  24. :group 'slime-mode
  25. :type 'integer)
  26. (defcustom slime-fuzzy-completion-time-limit-in-msec 1500
  27. "Limit the time spent (given in msec) in swank while gathering
  28. completions."
  29. :group 'slime-mode
  30. :type 'integer)
  31. (defcustom slime-when-complete-filename-expand nil
  32. "Use comint-replace-by-expanded-filename instead of
  33. comint-filename-completion to complete file names"
  34. :group 'slime-mode
  35. :type 'boolean)
  36. (defvar slime-fuzzy-target-buffer nil
  37. "The buffer that is the target of the completion activities.")
  38. (defvar slime-fuzzy-saved-window-configuration nil
  39. "The saved window configuration before the fuzzy completion
  40. buffer popped up.")
  41. (defvar slime-fuzzy-start nil
  42. "The beginning of the completion slot in the target buffer.
  43. This is a non-advancing marker.")
  44. (defvar slime-fuzzy-end nil
  45. "The end of the completion slot in the target buffer.
  46. This is an advancing marker.")
  47. (defvar slime-fuzzy-original-text nil
  48. "The original text that was in the completion slot in the
  49. target buffer. This is what is put back if completion is
  50. aborted.")
  51. (defvar slime-fuzzy-text nil
  52. "The text that is currently in the completion slot in the
  53. target buffer. If this ever doesn't match, the target buffer has
  54. been modified and we abort without touching it.")
  55. (defvar slime-fuzzy-first nil
  56. "The position of the first completion in the completions buffer.
  57. The descriptive text and headers are above this.")
  58. (defvar slime-fuzzy-last nil
  59. "The position of the last completion in the completions buffer.
  60. If the time limit has exhausted during generation possible completion
  61. choices inside SWANK, an indication is printed below this.")
  62. (defvar slime-fuzzy-current-completion nil
  63. "The current completion object. If this is the same before and
  64. after point moves in the completions buffer, the text is not
  65. replaced in the target for efficiency.")
  66. (defvar slime-fuzzy-current-completion-overlay nil
  67. "The overlay representing the current completion in the completion
  68. buffer. This is used to hightlight the text.")
  69. ;;;;;;; slime-target-buffer-fuzzy-completions-mode
  70. ;; NOTE: this mode has to be able to override key mappings in slime-mode
  71. (defvar slime-target-buffer-fuzzy-completions-map
  72. (let ((map (make-sparse-keymap)))
  73. (cl-labels ((def (keys command)
  74. (unless (listp keys)
  75. (setq keys (list keys)))
  76. (dolist (key keys)
  77. (define-key map key command))))
  78. (def `([remap keyboard-quit]
  79. ,(kbd "C-g"))
  80. 'slime-fuzzy-abort)
  81. (def `([remap slime-fuzzy-indent-and-complete-symbol]
  82. [remap slime-indent-and-complete-symbol]
  83. ,(kbd "<tab>"))
  84. 'slime-fuzzy-select-or-update-completions)
  85. (def `([remap previous-line]
  86. ,(kbd "<up>"))
  87. 'slime-fuzzy-prev)
  88. (def `([remap next-line]
  89. ,(kbd "<down>"))
  90. 'slime-fuzzy-next)
  91. (def `([remap isearch-forward]
  92. ,(kbd "C-s"))
  93. 'slime-fuzzy-continue-isearch-in-fuzzy-buffer)
  94. ;; some unconditional direct bindings
  95. (def (list (kbd "<return>") (kbd "RET") (kbd "<SPC>") "(" ")" "[" "]")
  96. 'slime-fuzzy-select-and-process-event-in-target-buffer))
  97. map)
  98. "Keymap for slime-target-buffer-fuzzy-completions-mode.
  99. This will override the key bindings in the target buffer
  100. temporarily during completion.")
  101. ;; Make sure slime-fuzzy-target-buffer-completions-mode's map is
  102. ;; before everything else.
  103. (setf minor-mode-map-alist
  104. (cl-stable-sort minor-mode-map-alist
  105. (lambda (a b)
  106. (eq a 'slime-fuzzy-target-buffer-completions-mode))
  107. :key #'car))
  108. (defun slime-fuzzy-continue-isearch-in-fuzzy-buffer ()
  109. (interactive)
  110. (select-window (get-buffer-window (slime-get-fuzzy-buffer)))
  111. (call-interactively 'isearch-forward))
  112. (define-minor-mode slime-fuzzy-target-buffer-completions-mode
  113. "This minor mode is intented to override key bindings during
  114. fuzzy completions in the target buffer. Most of the bindings will
  115. do an implicit select in the completion window and let the
  116. keypress be processed in the target buffer."
  117. nil
  118. nil
  119. slime-target-buffer-fuzzy-completions-map)
  120. (add-to-list 'minor-mode-alist
  121. '(slime-fuzzy-target-buffer-completions-mode
  122. " Fuzzy Target Buffer Completions"))
  123. (defvar slime-fuzzy-completions-map
  124. (let ((map (make-sparse-keymap)))
  125. (cl-labels ((def (keys command)
  126. (unless (listp keys)
  127. (setq keys (list keys)))
  128. (dolist (key keys)
  129. (define-key map key command))))
  130. (def `([remap keyboard-quit]
  131. "q"
  132. ,(kbd "C-g"))
  133. 'slime-fuzzy-abort)
  134. (def `([remap previous-line]
  135. "p"
  136. "\M-p"
  137. ,(kbd "<up>"))
  138. 'slime-fuzzy-prev)
  139. (def `([remap next-line]
  140. "n"
  141. "\M-n"
  142. ,(kbd "<down>"))
  143. 'slime-fuzzy-next)
  144. (def "\d" 'scroll-down)
  145. (def `([remap slime-fuzzy-indent-and-complete-symbol]
  146. [remap slime-indent-and-complete-symbol]
  147. ,(kbd "<tab>"))
  148. 'slime-fuzzy-select)
  149. (def (kbd "<mouse-2>") 'slime-fuzzy-select/mouse)
  150. (def `(,(kbd "RET")
  151. ,(kbd "<SPC>"))
  152. 'slime-fuzzy-select))
  153. map)
  154. "Keymap for slime-fuzzy-completions-mode when in the completion buffer.")
  155. (define-derived-mode slime-fuzzy-completions-mode
  156. fundamental-mode "Fuzzy Completions"
  157. "Major mode for presenting fuzzy completion results.
  158. When you run `slime-fuzzy-complete-symbol', the symbol token at
  159. point is completed using the Fuzzy Completion algorithm; this
  160. means that the token is taken as a sequence of characters and all
  161. the various possibilities that this sequence could meaningfully
  162. represent are offered as selectable choices, sorted by how well
  163. they deem to be a match for the token. (For instance, the first
  164. choice of completing on \"mvb\" would be \"multiple-value-bind\".)
  165. Therefore, a new buffer (*Fuzzy Completions*) will pop up that
  166. contains the different completion choices. Simultaneously, a
  167. special minor-mode will be temporarily enabled in the original
  168. buffer where you initiated fuzzy completion (also called the
  169. ``target buffer'') in order to navigate through the *Fuzzy
  170. Completions* buffer without leaving.
  171. With focus in *Fuzzy Completions*:
  172. Type `n' and `p' (`UP', `DOWN') to navigate between completions.
  173. Type `RET' or `TAB' to select the completion near point.
  174. Type `q' to abort.
  175. With focus in the target buffer:
  176. Type `UP' and `DOWN' to navigate between completions.
  177. Type a character that does not constitute a symbol name
  178. to insert the current choice and then that character (`(', `)',
  179. `SPACE', `RET'.) Use `TAB' to simply insert the current choice.
  180. Use C-g to abort.
  181. Alternatively, you can click <mouse-2> on a completion to select it.
  182. Complete listing of keybindings within the target buffer:
  183. \\<slime-target-buffer-fuzzy-completions-map>\
  184. \\{slime-target-buffer-fuzzy-completions-map}
  185. Complete listing of keybindings with *Fuzzy Completions*:
  186. \\<slime-fuzzy-completions-map>\
  187. \\{slime-fuzzy-completions-map}"
  188. (use-local-map slime-fuzzy-completions-map)
  189. (set (make-local-variable 'slime-fuzzy-current-completion-overlay)
  190. (make-overlay (point) (point) nil t nil)))
  191. (defun slime-fuzzy-completions (prefix &optional default-package)
  192. "Get the list of sorted completion objects from completing
  193. `prefix' in `package' from the connected Lisp."
  194. (let ((prefix (cl-etypecase prefix
  195. (symbol (symbol-name prefix))
  196. (string prefix))))
  197. (slime-eval `(swank:fuzzy-completions ,prefix
  198. ,(or default-package
  199. (slime-current-package))
  200. :limit ,slime-fuzzy-completion-limit
  201. :time-limit-in-msec
  202. ,slime-fuzzy-completion-time-limit-in-msec))))
  203. (defun slime-fuzzy-selected (prefix completion)
  204. "Tell the connected Lisp that the user selected completion
  205. `completion' as the completion for `prefix'."
  206. (let ((no-properties (copy-sequence prefix)))
  207. (set-text-properties 0 (length no-properties) nil no-properties)
  208. (slime-eval `(swank:fuzzy-completion-selected ,no-properties
  209. ',completion))))
  210. (defun slime-fuzzy-indent-and-complete-symbol ()
  211. "Indent the current line and perform fuzzy symbol completion. First
  212. indent the line. If indenting doesn't move point, complete the
  213. symbol. If there's no symbol at the point, show the arglist for the
  214. most recently enclosed macro or function."
  215. (interactive)
  216. (let ((pos (point)))
  217. (unless (get-text-property (line-beginning-position) 'slime-repl-prompt)
  218. (lisp-indent-line))
  219. (when (= pos (point))
  220. (cond ((save-excursion (re-search-backward "[^() \n\t\r]+\\=" nil t))
  221. (slime-fuzzy-complete-symbol))
  222. ((memq (char-before) '(?\t ?\ ))
  223. (slime-echo-arglist))))))
  224. (cl-defun slime-fuzzy-complete-symbol ()
  225. "Fuzzily completes the abbreviation at point into a symbol."
  226. (interactive)
  227. (when (save-excursion (re-search-backward "\"[^ \t\n]+\\=" nil t))
  228. (cl-return-from slime-fuzzy-complete-symbol
  229. ;; don't add space after completion
  230. (let ((comint-completion-addsuffix '("/" . "")))
  231. (if slime-when-complete-filename-expand
  232. (comint-replace-by-expanded-filename)
  233. ;; FIXME: use `comint-filename-completion' when dropping emacs23
  234. (funcall (if (>= emacs-major-version 24)
  235. 'comint-filename-completion
  236. 'comint-dynamic-complete-as-filename))))))
  237. (let* ((end (move-marker (make-marker) (slime-symbol-end-pos)))
  238. (beg (move-marker (make-marker) (slime-symbol-start-pos)))
  239. (prefix (buffer-substring-no-properties beg end)))
  240. (cl-destructuring-bind (completion-set interrupted-p)
  241. (slime-fuzzy-completions prefix)
  242. (if (null completion-set)
  243. (progn (slime-minibuffer-respecting-message
  244. "Can't find completion for \"%s\"" prefix)
  245. (ding)
  246. (slime-fuzzy-done))
  247. (goto-char end)
  248. (cond ((slime-length= completion-set 1)
  249. ;; insert completed string
  250. (insert-and-inherit (caar completion-set))
  251. (delete-region beg end)
  252. (goto-char (+ beg (length (caar completion-set))))
  253. (slime-minibuffer-respecting-message "Sole completion")
  254. (slime-fuzzy-done))
  255. ;; Incomplete
  256. (t
  257. (slime-fuzzy-choices-buffer completion-set interrupted-p
  258. beg end)
  259. (slime-minibuffer-respecting-message
  260. "Complete but not unique")))))))
  261. (defun slime-get-fuzzy-buffer ()
  262. (get-buffer-create "*Fuzzy Completions*"))
  263. (defvar slime-fuzzy-explanation
  264. "For help on how the use this buffer, see `slime-fuzzy-completions-mode'.
  265. Flags: boundp fboundp generic-function class macro special-operator package
  266. \n"
  267. "The explanation that gets inserted at the beginning of the
  268. *Fuzzy Completions* buffer.")
  269. (defun slime-fuzzy-insert-completion-choice (completion max-length)
  270. "Inserts the completion object `completion' as a formatted
  271. completion choice into the current buffer, and mark it with the
  272. proper text properties."
  273. (cl-destructuring-bind (symbol-name score chunks classification-string)
  274. completion
  275. (let ((start (point))
  276. (end))
  277. (insert symbol-name)
  278. (setq end (point))
  279. (dolist (chunk chunks)
  280. (put-text-property (+ start (cl-first chunk))
  281. (+ start (cl-first chunk)
  282. (length (cl-second chunk)))
  283. 'face 'bold))
  284. (put-text-property start (point) 'mouse-face 'highlight)
  285. (dotimes (i (- max-length (- end start)))
  286. (insert " "))
  287. (insert (format " %s %s\n"
  288. classification-string
  289. score))
  290. (put-text-property start (point) 'completion completion))))
  291. (defun slime-fuzzy-insert (text)
  292. "Inserts `text' into the target buffer in the completion slot.
  293. If the buffer has been modified in the meantime, abort the
  294. completion process. Otherwise, update all completion variables
  295. so that the new text is present."
  296. (with-current-buffer slime-fuzzy-target-buffer
  297. (cond
  298. ((not (string-equal slime-fuzzy-text
  299. (buffer-substring slime-fuzzy-start
  300. slime-fuzzy-end)))
  301. (slime-fuzzy-done)
  302. (beep)
  303. (message "Target buffer has been modified!"))
  304. (t
  305. (goto-char slime-fuzzy-start)
  306. (delete-region slime-fuzzy-start slime-fuzzy-end)
  307. (insert-and-inherit text)
  308. (setq slime-fuzzy-text text)
  309. (goto-char slime-fuzzy-end)))))
  310. (defun slime-minibuffer-p (buffer)
  311. (if (featurep 'xemacs)
  312. (eq buffer (window-buffer (minibuffer-window)))
  313. (minibufferp buffer)))
  314. (defun slime-fuzzy-choices-buffer (completions interrupted-p start end)
  315. "Creates (if neccessary), populates, and pops up the *Fuzzy
  316. Completions* buffer with the completions from `completions' and
  317. the completion slot in the current buffer bounded by `start' and
  318. `end'. This saves the window configuration before popping the
  319. buffer so that it can possibly be restored when the user is
  320. done."
  321. (let ((new-completion-buffer (not slime-fuzzy-target-buffer))
  322. (connection (slime-connection)))
  323. (when new-completion-buffer
  324. (setq slime-fuzzy-saved-window-configuration
  325. (current-window-configuration)))
  326. (slime-fuzzy-enable-target-buffer-completions-mode)
  327. (setq slime-fuzzy-target-buffer (current-buffer))
  328. (setq slime-fuzzy-start (move-marker (make-marker) start))
  329. (setq slime-fuzzy-end (move-marker (make-marker) end))
  330. (set-marker-insertion-type slime-fuzzy-end t)
  331. (setq slime-fuzzy-original-text (buffer-substring start end))
  332. (setq slime-fuzzy-text slime-fuzzy-original-text)
  333. (slime-fuzzy-fill-completions-buffer completions interrupted-p)
  334. (pop-to-buffer (slime-get-fuzzy-buffer))
  335. (slime-fuzzy-next)
  336. (setq slime-buffer-connection connection)
  337. (when new-completion-buffer
  338. ;; Hook to nullify window-config restoration if the user changes
  339. ;; the window configuration himself.
  340. (when (boundp 'window-configuration-change-hook)
  341. (add-hook 'window-configuration-change-hook
  342. 'slime-fuzzy-window-configuration-change))
  343. (add-hook 'kill-buffer-hook 'slime-fuzzy-abort 'append t)
  344. (set (make-local-variable 'cursor-type) nil)
  345. (setq buffer-quit-function 'slime-fuzzy-abort)) ; M-Esc Esc
  346. (when slime-fuzzy-completion-in-place
  347. ;; switch back to the original buffer
  348. (if (slime-minibuffer-p slime-fuzzy-target-buffer)
  349. (select-window (minibuffer-window))
  350. (switch-to-buffer-other-window slime-fuzzy-target-buffer)))))
  351. (defun slime-fuzzy-fill-completions-buffer (completions interrupted-p)
  352. "Erases and fills the completion buffer with the given completions."
  353. (with-current-buffer (slime-get-fuzzy-buffer)
  354. (setq buffer-read-only nil)
  355. (erase-buffer)
  356. (slime-fuzzy-completions-mode)
  357. (insert slime-fuzzy-explanation)
  358. (let ((max-length 12))
  359. (dolist (completion completions)
  360. (setf max-length (max max-length (length (cl-first completion)))))
  361. (insert "Completion:")
  362. (dotimes (i (- max-length 10)) (insert " "))
  363. ;; Flags: Score:
  364. ;; ... ------- --------
  365. ;; bfgctmsp
  366. (let* ((example-classification-string (cl-fourth (cl-first completions)))
  367. (classification-length (length example-classification-string))
  368. (spaces (- classification-length (length "Flags:"))))
  369. (insert "Flags:")
  370. (dotimes (i spaces) (insert " "))
  371. (insert " Score:\n")
  372. (dotimes (i max-length) (insert "-"))
  373. (insert " ")
  374. (dotimes (i classification-length) (insert "-"))
  375. (insert " --------\n")
  376. (setq slime-fuzzy-first (point)))
  377. (dolist (completion completions)
  378. (setq slime-fuzzy-last (point)) ; will eventually become the last entry
  379. (slime-fuzzy-insert-completion-choice completion max-length))
  380. (when interrupted-p
  381. (insert "...\n")
  382. (insert "[Interrupted: time limit exhausted]"))
  383. (setq buffer-read-only t))
  384. (setq slime-fuzzy-current-completion
  385. (caar completions))
  386. (goto-char 0)))
  387. (defun slime-fuzzy-enable-target-buffer-completions-mode ()
  388. "Store the target buffer's local map, so that we can restore it."
  389. (unless slime-fuzzy-target-buffer-completions-mode
  390. ; (slime-log-event "Enabling target buffer completions mode")
  391. (slime-fuzzy-target-buffer-completions-mode 1)))
  392. (defun slime-fuzzy-disable-target-buffer-completions-mode ()
  393. "Restores the target buffer's local map when completion is finished."
  394. (when slime-fuzzy-target-buffer-completions-mode
  395. ; (slime-log-event "Disabling target buffer completions mode")
  396. (slime-fuzzy-target-buffer-completions-mode 0)))
  397. (defun slime-fuzzy-insert-from-point ()
  398. "Inserts the completion that is under point in the completions
  399. buffer into the target buffer. If the completion in question had
  400. already been inserted, it does nothing."
  401. (with-current-buffer (slime-get-fuzzy-buffer)
  402. (let ((current-completion (get-text-property (point) 'completion)))
  403. (when (and current-completion
  404. (not (eq slime-fuzzy-current-completion
  405. current-completion)))
  406. (slime-fuzzy-insert
  407. (cl-first (get-text-property (point) 'completion)))
  408. (setq slime-fuzzy-current-completion
  409. current-completion)))))
  410. (defun slime-fuzzy-post-command-hook ()
  411. "The post-command-hook for the *Fuzzy Completions* buffer.
  412. This makes sure the completion slot in the target buffer matches
  413. the completion that point is on in the completions buffer."
  414. (condition-case err
  415. (when slime-fuzzy-target-buffer
  416. (slime-fuzzy-insert-from-point))
  417. (error
  418. ;; Because this is called on the post-command-hook, we mustn't let
  419. ;; errors propagate.
  420. (message "Error in slime-fuzzy-post-command-hook: %S" err))))
  421. (defun slime-fuzzy-next ()
  422. "Moves point directly to the next completion in the completions
  423. buffer."
  424. (interactive)
  425. (with-current-buffer (slime-get-fuzzy-buffer)
  426. (let ((point (next-single-char-property-change
  427. (point) 'completion nil slime-fuzzy-last)))
  428. (set-window-point (get-buffer-window (current-buffer)) point)
  429. (goto-char point))
  430. (slime-fuzzy-highlight-current-completion)))
  431. (defun slime-fuzzy-prev ()
  432. "Moves point directly to the previous completion in the
  433. completions buffer."
  434. (interactive)
  435. (with-current-buffer (slime-get-fuzzy-buffer)
  436. (let ((point (previous-single-char-property-change
  437. (point)
  438. 'completion nil slime-fuzzy-first)))
  439. (set-window-point (get-buffer-window (current-buffer)) point)
  440. (goto-char point))
  441. (slime-fuzzy-highlight-current-completion)))
  442. (defun slime-fuzzy-highlight-current-completion ()
  443. "Highlights the current completion,
  444. so that the user can see it on the screen."
  445. (let ((pos (point)))
  446. (when (overlayp slime-fuzzy-current-completion-overlay)
  447. (move-overlay slime-fuzzy-current-completion-overlay
  448. (point) (1- (search-forward " ")))
  449. (overlay-put slime-fuzzy-current-completion-overlay
  450. 'face 'secondary-selection))
  451. (goto-char pos)))
  452. (defun slime-fuzzy-abort ()
  453. "Aborts the completion process, setting the completions slot in
  454. the target buffer back to its original contents."
  455. (interactive)
  456. (when slime-fuzzy-target-buffer
  457. (slime-fuzzy-done)))
  458. (defun slime-fuzzy-select ()
  459. "Selects the current completion, making sure that it is inserted
  460. into the target buffer. This tells the connected Lisp what completion
  461. was selected."
  462. (interactive)
  463. (when slime-fuzzy-target-buffer
  464. (with-current-buffer (slime-get-fuzzy-buffer)
  465. (let ((completion (get-text-property (point) 'completion)))
  466. (when completion
  467. (slime-fuzzy-insert (cl-first completion))
  468. (slime-fuzzy-selected slime-fuzzy-original-text
  469. completion)
  470. (slime-fuzzy-done))))))
  471. (defun slime-fuzzy-select-or-update-completions ()
  472. "If there were no changes since the last time fuzzy completion was started
  473. this function will select the current completion.
  474. Otherwise refreshes the completion list based on the changes made."
  475. (interactive)
  476. ; (slime-log-event "Selecting or updating completions")
  477. (if (string-equal slime-fuzzy-original-text
  478. (buffer-substring slime-fuzzy-start
  479. slime-fuzzy-end))
  480. (slime-fuzzy-select)
  481. (slime-fuzzy-complete-symbol)))
  482. (defun slime-fuzzy-process-event-in-completions-buffer ()
  483. "Simply processes the event in the target buffer"
  484. (interactive)
  485. (with-current-buffer (slime-get-fuzzy-buffer)
  486. (push last-input-event unread-command-events)))
  487. (defun slime-fuzzy-select-and-process-event-in-target-buffer ()
  488. "Selects the current completion, making sure that it is inserted
  489. into the target buffer and processes the event in the target buffer."
  490. (interactive)
  491. ; (slime-log-event "Selecting and processing event in target buffer")
  492. (when slime-fuzzy-target-buffer
  493. (let ((buff slime-fuzzy-target-buffer))
  494. (slime-fuzzy-select)
  495. (with-current-buffer buff
  496. (slime-fuzzy-disable-target-buffer-completions-mode)
  497. (push last-input-event unread-command-events)))))
  498. (defun slime-fuzzy-select/mouse (event)
  499. "Handle a mouse-2 click on a completion choice as if point were
  500. on the completion choice and the slime-fuzzy-select command was
  501. run."
  502. (interactive "e")
  503. (with-current-buffer (window-buffer (posn-window (event-end event)))
  504. (save-excursion
  505. (goto-char (posn-point (event-end event)))
  506. (when (get-text-property (point) 'mouse-face)
  507. (slime-fuzzy-insert-from-point)
  508. (slime-fuzzy-select)))))
  509. (defun slime-fuzzy-done ()
  510. "Cleans up after the completion process. This removes all hooks,
  511. and attempts to restore the window configuration. If this fails,
  512. it just burys the completions buffer and leaves the window
  513. configuration alone."
  514. (when slime-fuzzy-target-buffer
  515. (set-buffer slime-fuzzy-target-buffer)
  516. (slime-fuzzy-disable-target-buffer-completions-mode)
  517. (if (slime-fuzzy-maybe-restore-window-configuration)
  518. (bury-buffer (slime-get-fuzzy-buffer))
  519. ;; We couldn't restore the windows, so just bury the fuzzy
  520. ;; completions buffer and let something else fill it in.
  521. (pop-to-buffer (slime-get-fuzzy-buffer))
  522. (bury-buffer))
  523. (if (slime-minibuffer-p slime-fuzzy-target-buffer)
  524. (select-window (minibuffer-window))
  525. (pop-to-buffer slime-fuzzy-target-buffer))
  526. (goto-char slime-fuzzy-end)
  527. (setq slime-fuzzy-target-buffer nil)
  528. (remove-hook 'window-configuration-change-hook
  529. 'slime-fuzzy-window-configuration-change)))
  530. (defun slime-fuzzy-maybe-restore-window-configuration ()
  531. "Restores the saved window configuration if it has not been
  532. nullified."
  533. (when (boundp 'window-configuration-change-hook)
  534. (remove-hook 'window-configuration-change-hook
  535. 'slime-fuzzy-window-configuration-change))
  536. (if (not slime-fuzzy-saved-window-configuration)
  537. nil
  538. (set-window-configuration slime-fuzzy-saved-window-configuration)
  539. (setq slime-fuzzy-saved-window-configuration nil)
  540. t))
  541. (defun slime-fuzzy-window-configuration-change ()
  542. "Called on window-configuration-change-hook. Since the window
  543. configuration was changed, we nullify our saved configuration."
  544. (setq slime-fuzzy-saved-window-configuration nil))
  545. (provide 'slime-fuzzy)