File tree Expand file tree Collapse file tree 2 files changed +57
-0
lines changed Expand file tree Collapse file tree 2 files changed +57
-0
lines changed Original file line number Diff line number Diff line change 28
28
29
29
; ;; Code:
30
30
31
+ (defun haskell-completions-can-grab-prefix ()
32
+ " Check if the case is appropriate for grabbing completion prefix.
33
+ Returns t if point is either at whitespace character, or at
34
+ punctuation, or at line end and preceeding character is not a
35
+ whitespace or new line, otherwise returns nil.
36
+
37
+ Returns nil in presense of active region."
38
+ (when (not (region-active-p ))
39
+ (when (looking-at (rx (| space line-end punct)))
40
+ (when (not (bobp ))
41
+ (save-excursion
42
+ (backward-char )
43
+ (not (looking-at (rx (| space line-end)))))))))
44
+
31
45
(provide 'haskell-completions )
32
46
; ;; haskell-completions.el ends here
Original file line number Diff line number Diff line change 27
27
28
28
; ;; Code:
29
29
30
+ (require 'ert )
31
+ (require 'haskell-mode )
32
+ (require 'haskell-completions )
33
+
34
+
35
+ (ert-deftest haskell-completions-can-grab-prefix-test ()
36
+ " Tests the function `haskell-completions-can-grab-prefix' ."
37
+ (with-temp-buffer
38
+ (haskell-mode )
39
+ (should (eql nil (haskell-completions-can-grab-prefix)))
40
+ (insert " " )
41
+ (should (eql nil (haskell-completions-can-grab-prefix)))
42
+ (insert " a" )
43
+ (should (eql t (haskell-completions-can-grab-prefix)))
44
+ (save-excursion
45
+ (insert " " )
46
+ (should (eql nil (haskell-completions-can-grab-prefix)))
47
+ (insert " bc-" )
48
+ (should (eql t (haskell-completions-can-grab-prefix)))
49
+ (insert " \n " )
50
+ (should (eql nil (haskell-completions-can-grab-prefix)))
51
+ (insert " def:#!" )
52
+ (should (eql t (haskell-completions-can-grab-prefix))))
53
+ (should (eql t (haskell-completions-can-grab-prefix)))
54
+ ; ; punctuation tests
55
+ (save-excursion (insert " )" ))
56
+ (should (eql t (haskell-completions-can-grab-prefix)))
57
+ (save-excursion (insert " ," ))
58
+ (should (eql t (haskell-completions-can-grab-prefix)))
59
+ (save-excursion (insert " '" ))
60
+ (should (eql t (haskell-completions-can-grab-prefix)))
61
+ ; ; should return nil in the middle of word
62
+ (save-excursion (insert " bcd" ))
63
+ (should (eql nil (haskell-completions-can-grab-prefix)))
64
+ ; ; region case
65
+ (let ((p (point )))
66
+ (goto-char (point-min ))
67
+ (push-mark )
68
+ (goto-char p)
69
+ (activate-mark )
70
+ (should (eql nil (haskell-completions-can-grab-prefix))))))
71
+
72
+
30
73
(provide 'haskell-completions-tests )
31
74
; ;; haskell-completions-tests.el ends here
You can’t perform that action at this time.
0 commit comments