-
Notifications
You must be signed in to change notification settings - Fork 31
/
psc-ide-backported.el
64 lines (56 loc) · 2.47 KB
/
psc-ide-backported.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
;;; psc-ide-backported.el --- Backported code from purescript-mode -*- lexical-binding: t -*-
;;; Commentary:
;; Code ported from purescript-mode
;;; Code:
(require 'cl-lib)
(defun psc-ide-ident-at-point ()
"Return the identifier under point, or nil if none found.
May return a qualified name."
(let ((reg (psc-ide-ident-pos-at-point)))
(when reg
(buffer-substring-no-properties (car reg) (cdr reg)))))
(defun psc-ide-ident-pos-at-point ()
"Return the span of the identifier under point, or nil if none found.
May return a qualified name."
(save-excursion
;; Skip whitespace if we're on it. That way, if we're at "map ", we'll
;; see the word "map".
(if (and (not (eobp))
(eq ? (char-syntax (char-after))))
(skip-chars-backward " \t"))
(let ((case-fold-search nil))
(cl-multiple-value-bind (start end)
(if (looking-at "\\.")
(list (progn (skip-syntax-backward "w_") (point))
(progn (skip-syntax-forward "w_") (point)))
(if (looking-at "\\s_")
(list (progn (skip-syntax-backward "_") (point))
(progn (skip-syntax-forward "_") (point)))
(list
(progn (skip-syntax-backward "w'")
(skip-syntax-forward "'") (point))
(progn (skip-syntax-forward "w'") (point)))))
;; If we're looking at a module ID that qualifies further IDs, add
;; those IDs.
(goto-char start)
(while (and (looking-at "[[:upper:]]") (eq (char-after end) ?.)
;; It's a module ID that qualifies further IDs.
(goto-char (1+ end))
(save-excursion
(when (not (zerop (skip-syntax-forward
(if (looking-at "\\s_") "_" "w'"))))
(setq end (point))))))
;; If we're looking at an ID that's itself qualified by previous
;; module IDs, add those too.
(goto-char start)
(if (eq (char-after) ?.) (forward-char 1)) ;Special case for "."
(while (and (eq (char-before) ?.)
(progn (forward-char -1)
(not (zerop (skip-syntax-backward "w'"))))
(skip-syntax-forward "'")
(looking-at "[[:upper:]]"))
(setq start (point)))
;; This is it.
(cons start end)))))
(provide 'psc-ide-backported)
;;; psc-ide-backported.el ends here