-
-
Notifications
You must be signed in to change notification settings - Fork 91
/
racket-complete.el
78 lines (63 loc) · 2.77 KB
/
racket-complete.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
;;; racket-complete.el -*- lexical-binding: t -*-
;; Copyright (c) 2013-2023 by Greg Hendershott.
;; Portions Copyright (C) 1985-1986, 1999-2013 Free Software Foundation, Inc.
;; Author: Greg Hendershott
;; URL: https://github.com/greghendershott/racket-mode
;; SPDX-License-Identifier: GPL-3.0-or-later
(require 'racket-common)
(defun racket--call-with-completion-prefix-positions (proc)
(if forward-sexp-function ;not necessarily sexp lang
(condition-case _
(save-excursion
(let ((beg (progn (forward-sexp -1) (point)))
(end (progn (forward-sexp 1) (point))))
(when (<= (+ beg 2) end) ;prefix at least 2 chars
(funcall proc beg end))))
(error nil)))
(let ((beg (save-excursion (skip-syntax-backward "^-()>") (point))))
(unless (or (eq beg (point-max))
(member (char-syntax (char-after beg)) '(?\" ?\( ?\))))
(condition-case _
(save-excursion
(goto-char beg)
(forward-sexp 1)
(let ((end (point)))
(when (<= (+ beg 2) end) ;prefix at least 2 chars
(funcall proc beg end))))
(error nil)))))
(defun racket--in-require-form-p ()
(unless forward-sexp-function ;not necessarily sexp lang
(save-excursion
(save-match-data
(racket--escape-string-or-comment)
(let ((done nil)
(result nil))
(condition-case _
(while (not done)
(backward-up-list)
(when (looking-at-p (rx ?\( (or "require" "#%require")))
(setq done t)
(setq result t)))
(scan-error nil))
result)))))
;;; Completion tables with "category" metadata
(defconst racket--identifier-category 'racket-identifier
"Value for category metadata of identifier completion tables.")
;; Suggest default; can customize via `completion-category-overrides'.
(add-to-list 'completion-category-defaults
`(,racket--identifier-category (styles basic)))
(defun racket--completion-table (completions &optional category)
"Like `completion-table-dynamic' but we supply category metadata.
CATEGORY defaults to `racket--identifier-category'.
Category metadata needs to be returned by the completion table
function itself, unlike metadata supplied as properties in the
`completion-at-point-functions' list.
Supplying category metadata allows the user to configure a
completion matching style for that category."
(let ((category (or category racket--identifier-category)))
(lambda (prefix predicate action)
(if (eq action 'metadata)
`(metadata (category . ,category))
(complete-with-action action completions prefix predicate)))))
(provide 'racket-complete)
;; racket-complete.el ends here