Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 
 

245 lignes
8.7 KiB

  1. (require 'cl-lib)
  2. (require 'company)
  3. ;; "= . args"
  4. ;; "> . args"
  5. ;; ">= . args"
  6. ;; "< . args"
  7. ;; "<= . args"
  8. ;; "+ . args"
  9. ;; "- . args"
  10. ;; "* . args"
  11. ;; "/ . args"
  12. ;; "** a b"
  13. ;; "% a b"
  14. ;; "get-random-between a b"
  15. ;; "assert test"
  16. ;; "define-macro form (:doc \"\") . body"
  17. ;; "define definee (:doc \"\") . body"
  18. ;; "mutate target source"
  19. ;; "vector-length v"
  20. ;; "vector-ref vec idx"
  21. ;; "vector-set! vec idx val"
  22. ;; "set! sym val"
  23. ;; "set-car! target source"
  24. ;; "set-cdr! target source"
  25. ;; "if test then_part else_part"
  26. ;; "quote datum"
  27. ;; "quasiquote expr"
  28. ;; "and . args"
  29. ;; "or . args"
  30. ;; "not test"
  31. ;; "lambda args . body"
  32. ;; "apply fun args"
  33. ;; "eval expr"
  34. ;; "begin . args"
  35. ;; "list . args"
  36. ;; "pair car cdr"
  37. ;; "first seq"
  38. ;; "rest seq"
  39. ;; "set-type! node new_type"
  40. ;; "delete-type! n"
  41. ;; "type n"
  42. ;; "mem-reset"
  43. ;; "info n"
  44. ;; "show n"
  45. ;; "addr-of var"
  46. ;; "generate-docs-file file_name"
  47. ;; "print (:sep \" \") (:end \"\\n\") . things"
  48. ;; "read (:prompt \">\""
  49. ;; "exit (:code 0)"
  50. ;; "break"
  51. ;; "memstat"
  52. ;; "mytry try_part catch_part"
  53. ;; "load file"
  54. ;; "import f"
  55. ;; "copy obj"
  56. ;; "error type message"
  57. ;; "symbol->keyword sym"
  58. ;; "string->symbol str"
  59. ;; "symbol->string sym"
  60. ;; "concat-strings . strings"
  61. (defconst slime-built-ins
  62. '("=" ">" ">=" "<" "<=" "+" "-" "*" "/" "**" "%" "get-random-between"
  63. "assert" "define" "define-macro" "mutate" "if" "vector-length"
  64. "vector-ref" "vector-set!" "set!" "set-car!" "set-cdr!"
  65. "quote" "quasiquote" "unquote" "unquote-splicing" "and" "or" "not" "let"
  66. "lambda" "apply" "eval" "begin" "list" "pair" "create-hash-map"
  67. "hash-map-get" "hash-map-set!" "hash-map-delete!" "vector"
  68. "first" "rest" "set-type!" "delete-type!" "type" "info" "mem-reset"
  69. "show" "addr-of" "generate-docs-file" "print" "read" "exit" "break" "memstat"
  70. "mytry" "load" "import" "copy" "error" "symbol->keyword" "string->symbol"
  71. "symbol->string" "concat-strings"))
  72. (defun get-args (s)
  73. (cond
  74. ((string= s "=") ". objects")
  75. ((string= s ">") ". objects")
  76. ((string= s ">=") ". objects")
  77. ((string= s "<") ". objects")
  78. ((string= s "<=") ". objects")
  79. ((string= s "+") ". objects")
  80. ((string= s "-") ". objects")
  81. ((string= s "*") ". objects")
  82. ((string= s "/") ". objects")
  83. ((string= s "**") "a b")
  84. ((string= s "%") "a b")
  85. ((string= s "get-random-between") "a b")
  86. ((string= s "assert") "test")
  87. ((string= s "define") "definee (:doc \"\") . body")
  88. ((string= s "define-macro") "form (:doc \"\") . body")
  89. ((string= s "mutate!") "(mutate! <expression> <expression>)")
  90. ((string= s "if") "(if <test> <consequence> <alternative>)")
  91. (t '())))
  92. (defun sample-meta (s)
  93. (message "%s%s%s%s"
  94. (propertize "(" 'face '(:foreground "orange"))
  95. (propertize s 'face '(:foreground "#859900"))
  96. (let ((args (get-args s)))
  97. (if args
  98. (concat " " args)
  99. ""))
  100. (propertize ")" 'face '(:foreground "orange"))
  101. ))
  102. (defun my-slime-eldoc-function ()
  103. (let ((sexp-text (thing-at-point 'sexp)))
  104. (when sexp-text
  105. (let* ((sexp (read sexp-text))
  106. (symbol (if (listp sexp)
  107. (symbol-name (car sexp))
  108. (symbol-name sexp))))
  109. (when (member symbol slime-built-ins)
  110. (sample-meta symbol))))))
  111. (add-to-list 'auto-mode-alist '("\\.slime\\'" . slime-mode))
  112. (put 'lambda 'doc-string-elt 2)
  113. (put 'special-lambda 'doc-string-elt 2)
  114. (put 'define 'doc-string-elt 2)
  115. (put 'define-macro 'doc-string-elt 2)
  116. (define-derived-mode slime-mode prog-mode "(slime)"
  117. "Major mode for editing slime code."
  118. :group 'lisp
  119. (defvar project-vc-external-roots-function)
  120. (set-syntax-table lisp-mode-syntax-table)
  121. (setq-local lisp-mode-symbol-regexp "\\(?:\\sw\\|\\s_\\|\\\\.\\|?\\)+")
  122. (setq-local paragraph-ignore-fill-prefix t)
  123. (setq-local fill-paragraph-function 'lisp-fill-paragraph)
  124. (setq-local adaptive-fill-function #'lisp-adaptive-fill)
  125. ;; Adaptive fill mode gets in the way of auto-fill,
  126. ;; and should make no difference for explicit fill
  127. ;; because lisp-fill-paragraph should do the job.
  128. ;; I believe that newcomment's auto-fill code properly deals with it -stef
  129. ;;(set (make-local-variable 'adaptive-fill-mode) nil)
  130. (setq-local indent-line-function 'lisp-indent-line)
  131. (setq-local indent-region-function 'lisp-indent-region)
  132. (setq-local comment-indent-function #'lisp-comment-indent)
  133. ;; (setq-local outline-regexp ";;;\\(;* [^ \t\n]\\|###autoload\\)\\|(")
  134. (setq-local outline-level 'lisp-outline-level)
  135. (setq-local add-log-current-defun-function #'lisp-current-defun-name)
  136. (setq-local comment-start ";")
  137. (setq-local comment-start-skip ";+ *")
  138. (setq-local comment-add 1) ;default to `;;' in comment-region
  139. (setq-local comment-column 40)
  140. (setq-local comment-use-syntax t)
  141. (setq-local imenu-generic-expression lisp-imenu-generic-expression)
  142. (setq-local multibyte-syntax-as-symbol t)
  143. (defconst yess
  144. (append
  145. `((,(concat "\\(define\\)\\s-*(\\(\\_<[^ )]*\\)")
  146. (1 font-lock-keyword-face)
  147. (2 font-lock-function-name-face)
  148. ))
  149. `((,(concat "(\\s-*\\_<"
  150. (regexp-opt
  151. slime-built-ins) "\\_>")
  152. (0 font-lock-keyword-face)))
  153. `((,(concat "[`‘]\\(\\(?:\\sw\\|\\s_\\|\\\\.\\)"
  154. lisp-mode-symbol-regexp "\\)['’]")
  155. (1 font-lock-constant-face prepend))
  156. ;; Constant values.
  157. (,(concat "\\_<:" lisp-mode-symbol-regexp "\\_>")
  158. (0 font-lock-builtin-face)))
  159. ))
  160. (setq font-lock-defaults
  161. `((yess)
  162. nil nil nil nil
  163. (font-lock-mark-block-function . mark-defun)
  164. (font-lock-extra-managed-props help-echo)
  165. (font-lock-syntactic-face-function
  166. . lisp-font-lock-syntactic-face-function)))
  167. ;; (setq font-lock-defaults '((;; ads
  168. ;; ;; lisp-el-font-lock-keywords-1
  169. ;; ;; lisp-el-font-lock-keywords-2
  170. ;; )
  171. ;; nil nil nil nil
  172. ;; (font-lock-mark-block-function . mark-defun)
  173. ;; (font-lock-extra-managed-props help-echo)
  174. ;; (font-lock-syntactic-face-function
  175. ;; . lisp-font-lock-syntactic-face-function)))
  176. (setq-local prettify-symbols-alist lisp-prettify-symbols-alist)
  177. (setq-local electric-pair-skip-whitespace 'chomp)
  178. (setq-local electric-pair-open-newline-between-pairs nil)
  179. (add-hook 'after-load-functions #'elisp--font-lock-flush-elisp-buffers)
  180. (unless noninteractive
  181. (require 'elec-pair)
  182. (defvar electric-pair-text-pairs)
  183. (setq-local electric-pair-text-pairs
  184. (append '((?\` . ?\') (?‘ . ?’)) electric-pair-text-pairs))
  185. (setq-local electric-quote-string t))
  186. (setq imenu-case-fold-search nil)
  187. (add-function :before-until (local 'eldoc-documentation-function)
  188. #'my-slime-eldoc-function)
  189. (add-hook 'xref-backend-functions #'elisp--xref-backend nil t)
  190. (setq-local project-vc-external-roots-function #'elisp-load-path-roots)
  191. (add-hook 'completion-at-point-functions #'elisp-completion-at-point nil 'local)
  192. (add-hook 'flymake-diagnostic-functions #'elisp-flymake-checkdoc nil t)
  193. (add-hook 'flymake-diagnostic-functions #'elisp-flymake-byte-compile nil t)
  194. (modify-syntax-entry ?\{ "(}")
  195. (modify-syntax-entry ?\} "){")
  196. (modify-syntax-entry ?\[ "(]")
  197. (modify-syntax-entry ?\] ")["))
  198. (defun company-simple-backend (command &optional arg &rest ignored)
  199. (interactive (list 'interactive))
  200. (cl-case command
  201. (interactive (company-begin-backend 'company-simple-backend))
  202. (prefix (when (looking-back "foo\\>")
  203. (match-string 0)))
  204. (candidates (when (equal arg "foo")
  205. (list "foobar" "foobaz" "foobarbaz")))
  206. (meta (format "This value is named %s" arg))))
  207. (defun company-sample-backend (command &optional arg &rest ignored)
  208. (interactive (list 'interactive))
  209. (cl-case command
  210. (interactive (company-begin-backend 'company-sample-backend))
  211. (prefix (and (eq major-mode 'slime-mode)
  212. (company-grab-symbol)))
  213. (candidates
  214. (remove-if-not
  215. (lambda (c) (string-prefix-p arg c))
  216. slime-built-ins))
  217. (meta (sample-meta arg))))
  218. (add-hook 'slime-mode-hook
  219. (lambda ()
  220. (set (make-local-variable 'eldoc-documentation-function) 'my-slime-eldoc-function)
  221. (set (make-local-variable 'company-backends) '(company-sample-backend))))
  222. (provide 'slime-mode)