Klimi's new dotfiles with stow.
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

137 行
4.4 KiB

  1. ;;; ac-slime.el --- An auto-complete source using slime completions
  2. ;; Copyright (C) 2010-2017 Steve Purcell
  3. ;; Author: Steve Purcell <steve@sanityinc.com>
  4. ;; URL: https://github.com/purcell/ac-slime
  5. ;; Package-Version: 20171027.2100
  6. ;; Package-X-Original-Version: 0
  7. ;; Package-Requires: ((auto-complete "1.4") (slime "2.9") (cl-lib "0.5"))
  8. ;; This file is not part of GNU Emacs.
  9. ;; This program 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. ;; This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
  19. ;;; Commentary:
  20. ;; Usage:
  21. ;; (require 'ac-slime)
  22. ;; (add-hook 'slime-mode-hook 'set-up-slime-ac)
  23. ;; (add-hook 'slime-repl-mode-hook 'set-up-slime-ac)
  24. ;; (eval-after-load "auto-complete"
  25. ;; '(add-to-list 'ac-modes 'slime-repl-mode))
  26. ;;
  27. ;;; Code:
  28. (require 'cl-lib)
  29. (require 'slime)
  30. (require 'auto-complete)
  31. (defgroup ac-slime nil
  32. "Slime auto-complete customizations"
  33. :prefix "ac-slime-"
  34. :group 'slime)
  35. (defcustom ac-slime-show-flags t
  36. "When non-nil, show completion result flags during fuzzy completion."
  37. :group 'ac-slime)
  38. (defun ac-source-slime-fuzzy-candidates ()
  39. "Return a possibly-empty list of fuzzy completions for the symbol at point."
  40. (when (slime-connected-p)
  41. (let ((slime-fuzzy-completion-limit 50))
  42. (mapcar (lambda (result)
  43. (let ((sym (car result))
  44. (flags (car (last result))))
  45. (if ac-slime-show-flags
  46. (propertize sym 'summary flags)
  47. sym)))
  48. (car (slime-fuzzy-completions (substring-no-properties ac-prefix)))))))
  49. (defun ac-source-slime-simple-candidates ()
  50. "Return a possibly-empty list of completions for the symbol at point."
  51. (when (slime-connected-p)
  52. (let ((completions (slime-simple-completions (substring-no-properties ac-prefix))))
  53. (if (listp (car completions))
  54. (car completions)
  55. completions))))
  56. (defun ac-source-slime-case-correcting-completions (name collection)
  57. (mapcar #'(lambda (completion)
  58. ;; FIXME
  59. (cl-replace completion name))
  60. (all-completions (downcase name) collection)))
  61. (defvar ac-slime-current-doc nil "Holds slime docstring for current symbol.")
  62. (defun ac-slime-documentation (symbol-name)
  63. "Return a documentation string for SYMBOL-NAME."
  64. (let ((symbol-name (substring-no-properties symbol-name)))
  65. (slime-eval `(swank:documentation-symbol ,symbol-name))))
  66. (defun ac-slime-init ()
  67. "Called when completion source is initialized."
  68. (setq ac-slime-current-doc nil))
  69. ;;;###autoload
  70. (defface ac-slime-menu-face
  71. '((t (:inherit ac-candidate-face)))
  72. "Face for slime candidate menu."
  73. :group 'auto-complete)
  74. ;;;###autoload
  75. (defface ac-slime-selection-face
  76. '((t (:inherit ac-selection-face)))
  77. "Face for the slime selected candidate."
  78. :group 'auto-complete)
  79. ;;;###autoload
  80. (defvar ac-source-slime-fuzzy
  81. '((init . ac-slime-init)
  82. (candidates . ac-source-slime-fuzzy-candidates)
  83. (candidate-face . ac-slime-menu-face)
  84. (selection-face . ac-slime-selection-face)
  85. (prefix . slime-symbol-start-pos)
  86. (symbol . "l")
  87. (match . (lambda (prefix candidates) candidates))
  88. (document . ac-slime-documentation))
  89. "Source for fuzzy slime completion.")
  90. ;;;###autoload
  91. (defvar ac-source-slime-simple
  92. '((init . ac-slime-init)
  93. (candidates . ac-source-slime-simple-candidates)
  94. (candidate-face . ac-slime-menu-face)
  95. (selection-face . ac-slime-selection-face)
  96. (prefix . slime-symbol-start-pos)
  97. (symbol . "l")
  98. (document . ac-slime-documentation)
  99. (match . ac-source-slime-case-correcting-completions))
  100. "Source for slime completion.")
  101. ;;;###autoload
  102. (defun set-up-slime-ac (&optional fuzzy)
  103. "Add an optionally FUZZY slime completion source to `ac-sources'."
  104. (interactive)
  105. (add-to-list 'ac-sources
  106. (if fuzzy
  107. 'ac-source-slime-fuzzy
  108. 'ac-source-slime-simple)))
  109. (provide 'ac-slime)
  110. ;;; ac-slime.el ends here