Skip to content

Commit 8b504d9

Browse files
committed
Merge pull request #718 from geraldus/completions-package
Completions package (step 0: no functions yet)
2 parents a678b42 + aa3c7ab commit 8b504d9

File tree

3 files changed

+121
-0
lines changed

3 files changed

+121
-0
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ ELFILES = \
4747
haskell-compat.el \
4848
haskell-compile.el \
4949
haskell-complete-module.el \
50+
haskell-completions.el \
5051
haskell-customize.el \
5152
haskell-debug.el \
5253
haskell-decl-scan.el \

haskell-completions.el

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
;;; haskell-completions.el --- Haskell Completion package
2+
3+
;; Copyright © 2015 Athur Fayzrakhmanov. All rights reserved.
4+
5+
;; This file is part of haskell-mode package.
6+
;; You can contact with authors using GitHub issue tracker:
7+
;; https://github.com/haskell/haskell-mode/issues
8+
9+
;; This file is free software; you can redistribute it and/or modify
10+
;; it under the terms of the GNU General Public License as published by
11+
;; the Free Software Foundation; either version 3, or (at your option)
12+
;; any later version.
13+
14+
;; This file is distributed in the hope that it will be useful,
15+
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
;; GNU General Public License for more details.
18+
19+
;; You should have received a copy of the GNU General Public License
20+
;; along with GNU Emacs; see the file COPYING. If not, write to
21+
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22+
;; Boston, MA 02110-1301, USA.
23+
24+
;;; Commentary:
25+
26+
;; This package provides completions related functionality for
27+
;; Haskell Mode such grab completion prefix at point, and etc..
28+
29+
;;; Code:
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+
45+
(provide 'haskell-completions)
46+
;;; haskell-completions.el ends here

tests/haskell-completions-tests.el

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
;;; haskell-completions-tests.el --- Tests for Haskell Completion package
2+
3+
;; Copyright © 2015 Athur Fayzrakhmanov. All rights reserved.
4+
5+
;; This file is part of haskell-mode package.
6+
;; You can contact with authors using GitHub issue tracker:
7+
;; https://github.com/haskell/haskell-mode/issues
8+
9+
;; This file is free software; you can redistribute it and/or modify
10+
;; it under the terms of the GNU General Public License as published by
11+
;; the Free Software Foundation; either version 3, or (at your option)
12+
;; any later version.
13+
14+
;; This file is distributed in the hope that it will be useful,
15+
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
;; GNU General Public License for more details.
18+
19+
;; You should have received a copy of the GNU General Public License
20+
;; along with GNU Emacs; see the file COPYING. If not, write to
21+
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22+
;; Boston, MA 02110-1301, USA.
23+
24+
;;; Commentary:
25+
26+
;; This package provides regression tests for haskell-completions package.
27+
28+
;;; Code:
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+
73+
(provide 'haskell-completions-tests)
74+
;;; haskell-completions-tests.el ends here

0 commit comments

Comments
 (0)