You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

163 lines
6.6 KiB

  1. (require 'cl-lib)
  2. (require 'company)
  3. (defconst slime-built-ins
  4. '("=" ">" ">=" "<" "<=" "+" "-" "*" "/" "**" "%"
  5. "assert" "define" "define-syntax" "mutate" "if"
  6. "quote" "quasiquote" "unquote" "unquote-splicing" "and" "or" "not" "while" "let"
  7. "lambda" "special-lambda" "eval" "begin" "list" "pair"
  8. "first" "rest" "set-type" "delete-type" "type" "info"
  9. "show" "addr-of" "generate-docs" "print" "read" "exit" "break" "memstat" "try"
  10. "load" "import" "copy" "error" "symbol->keyword" "string->symbol"
  11. "symbol->string" "concat-strings"))
  12. (defun my-slime-eldoc-function ()
  13. (let ((symbol (symbol-name (car (read (thing-at-point 'sexp))))))
  14. (if (member symbol slime-built-ins)
  15. (sample-meta symbol)
  16. (concat symbol " ?"))))
  17. (defun sample-meta (s)
  18. (cond
  19. ((string= s "=") "(= :rest <objects>)")
  20. ((string= s ">") "(> :rest <numbers>)")
  21. ((string= s ">=") "(>= :rest <numbers>)")
  22. ((string= s "<") "(< :rest <numbers>)")
  23. ((string= s "<=") "(<= :rest <numbers>)")
  24. ((string= s "+") "(+ :rest <numbers>)")
  25. ((string= s "-") "(- :rest <numbers>)")
  26. ((string= s "*") "(* :rest <numbers>)")
  27. ((string= s "/") "(/ :rest <numbers>)")
  28. ((string= s "**") "(** <number> <exponent>)")
  29. ((string= s "assert") "(assert <condition>)")
  30. ((string= s "define") "(define <name-or-lambda-list> [doc-string] <expression-or-bodx>)")
  31. ((string= s "define-syntax") "(define-syntax <name-and-lambda-list> [doc-string] <bodx>)")
  32. ((string= s "mutate") "(mutate <expression> <expression>)")
  33. ((string= s "if") "(if <test> <consequence> <alternative>)")
  34. (t "")))
  35. (add-to-list 'auto-mode-alist '("\\.slime\\'" . slime-mode))
  36. (put 'lambda 'doc-string-elt 2)
  37. (put 'special-lambda 'doc-string-elt 2)
  38. (put 'define 'doc-string-elt 2)
  39. (put 'define-syntax 'doc-string-elt 2)
  40. (define-derived-mode slime-mode prog-mode "(slime)"
  41. "Major mode for editing slime code."
  42. :group 'lisp
  43. (defvar project-vc-external-roots-function)
  44. (set-syntax-table lisp-mode-syntax-table)
  45. (setq-local lisp-mode-symbol-regexp "\\(?:\\sw\\|\\s_\\|\\\\.\\|?\\)+")
  46. (setq-local paragraph-ignore-fill-prefix t)
  47. (setq-local fill-paragraph-function 'lisp-fill-paragraph)
  48. (setq-local adaptive-fill-function #'lisp-adaptive-fill)
  49. ;; Adaptive fill mode gets in the way of auto-fill,
  50. ;; and should make no difference for explicit fill
  51. ;; because lisp-fill-paragraph should do the job.
  52. ;; I believe that newcomment's auto-fill code properly deals with it -stef
  53. ;;(set (make-local-variable 'adaptive-fill-mode) nil)
  54. (setq-local indent-line-function 'lisp-indent-line)
  55. (setq-local indent-region-function 'lisp-indent-region)
  56. (setq-local comment-indent-function #'lisp-comment-indent)
  57. ;; (setq-local outline-regexp ";;;\\(;* [^ \t\n]\\|###autoload\\)\\|(")
  58. (setq-local outline-level 'lisp-outline-level)
  59. (setq-local add-log-current-defun-function #'lisp-current-defun-name)
  60. (setq-local comment-start ";")
  61. (setq-local comment-start-skip ";+ *")
  62. (setq-local comment-add 1) ;default to `;;' in comment-region
  63. (setq-local comment-column 40)
  64. (setq-local comment-use-syntax t)
  65. (setq-local imenu-generic-expression lisp-imenu-generic-expression)
  66. (setq-local multibyte-syntax-as-symbol t)
  67. (defconst yess
  68. (append
  69. `((,(concat "\\(define\\)\\s-*(\\(\\_<[^ )]*\\)")
  70. (1 font-lock-keyword-face)
  71. (2 font-lock-function-name-face)
  72. ))
  73. `((,(concat "(\\s-*\\_<"
  74. (regexp-opt
  75. slime-built-ins) "\\_>")
  76. (0 font-lock-keyword-face)))
  77. `((,(concat "[`‘]\\(\\(?:\\sw\\|\\s_\\|\\\\.\\)"
  78. lisp-mode-symbol-regexp "\\)['’]")
  79. (1 font-lock-constant-face prepend))
  80. ;; Constant values.
  81. (,(concat "\\_<:" lisp-mode-symbol-regexp "\\_>")
  82. (0 font-lock-builtin-face)))
  83. ))
  84. (setq font-lock-defaults
  85. `((yess)
  86. nil nil nil nil
  87. (font-lock-mark-block-function . mark-defun)
  88. (font-lock-extra-managed-props help-echo)
  89. (font-lock-syntactic-face-function
  90. . lisp-font-lock-syntactic-face-function)))
  91. ;; (setq font-lock-defaults '((;; ads
  92. ;; ;; lisp-el-font-lock-keywords-1
  93. ;; ;; lisp-el-font-lock-keywords-2
  94. ;; )
  95. ;; nil nil nil nil
  96. ;; (font-lock-mark-block-function . mark-defun)
  97. ;; (font-lock-extra-managed-props help-echo)
  98. ;; (font-lock-syntactic-face-function
  99. ;; . lisp-font-lock-syntactic-face-function)))
  100. (setq-local prettify-symbols-alist lisp-prettify-symbols-alist)
  101. (setq-local electric-pair-skip-whitespace 'chomp)
  102. (setq-local electric-pair-open-newline-between-pairs nil)
  103. (add-hook 'after-load-functions #'elisp--font-lock-flush-elisp-buffers)
  104. (unless noninteractive
  105. (require 'elec-pair)
  106. (defvar electric-pair-text-pairs)
  107. (setq-local electric-pair-text-pairs
  108. (append '((?\` . ?\') (?‘ . ?’)) electric-pair-text-pairs))
  109. (setq-local electric-quote-string t))
  110. (setq imenu-case-fold-search nil)
  111. (add-function :before-until (local 'eldoc-documentation-function)
  112. #'elisp-eldoc-documentation-function)
  113. (add-hook 'xref-backend-functions #'elisp--xref-backend nil t)
  114. (setq-local project-vc-external-roots-function #'elisp-load-path-roots)
  115. (add-hook 'completion-at-point-functions #'elisp-completion-at-point nil 'local)
  116. (add-hook 'flymake-diagnostic-functions #'elisp-flymake-checkdoc nil t)
  117. (add-hook 'flymake-diagnostic-functions #'elisp-flymake-byte-compile nil t))
  118. (defun company-simple-backend (command &optional arg &rest ignored)
  119. (interactive (list 'interactive))
  120. (cl-case command
  121. (interactive (company-begin-backend 'company-simple-backend))
  122. (prefix (when (looking-back "foo\\>")
  123. (match-string 0)))
  124. (candidates (when (equal arg "foo")
  125. (list "foobar" "foobaz" "foobarbaz")))
  126. (meta (format "This value is named %s" arg))))
  127. (defun company-sample-backend (command &optional arg &rest ignored)
  128. (interactive (list 'interactive))
  129. (cl-case command
  130. (interactive (company-begin-backend 'company-sample-backend))
  131. (prefix (and (eq major-mode 'slime-mode)
  132. (company-grab-symbol)))
  133. (candidates
  134. (remove-if-not
  135. (lambda (c) (string-prefix-p arg c))
  136. slime-built-ins))
  137. (meta (sample-meta arg))))
  138. (add-hook 'slime-mode-hook
  139. (lambda ()
  140. ;; (set (make-local-variable 'eldoc-documentation-function) 'my-slime-eldoc-function)
  141. (set (make-local-variable 'company-backends) '(company-sample-backend))))
  142. (provide 'slime-mode)