Skip to content

Completions package #718

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 12, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ ELFILES = \
haskell-compat.el \
haskell-compile.el \
haskell-complete-module.el \
haskell-completions.el \
haskell-customize.el \
haskell-debug.el \
haskell-decl-scan.el \
Expand Down
46 changes: 46 additions & 0 deletions haskell-completions.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
;;; haskell-completions.el --- Haskell Completion package

;; Copyright © 2015 Athur Fayzrakhmanov. All rights reserved.

;; This file is part of haskell-mode package.
;; You can contact with authors using GitHub issue tracker:
;; https://github.com/haskell/haskell-mode/issues

;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.

;; This file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.

;;; Commentary:

;; This package provides completions related functionality for
;; Haskell Mode such grab completion prefix at point, and etc..

;;; Code:

(defun haskell-completions-can-grab-prefix ()
"Check if the case is appropriate for grabbing completion prefix.
Returns t if point is either at whitespace character, or at
punctuation, or at line end and preceeding character is not a
whitespace or new line, otherwise returns nil.

Returns nil in presense of active region."
(when (not (region-active-p))
(when (looking-at (rx (| space line-end punct)))
(when (not (bobp))
(save-excursion
(backward-char)
(not (looking-at (rx (| space line-end)))))))))

(provide 'haskell-completions)
;;; haskell-completions.el ends here
74 changes: 74 additions & 0 deletions tests/haskell-completions-tests.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
;;; haskell-completions-tests.el --- Tests for Haskell Completion package

;; Copyright © 2015 Athur Fayzrakhmanov. All rights reserved.

;; This file is part of haskell-mode package.
;; You can contact with authors using GitHub issue tracker:
;; https://github.com/haskell/haskell-mode/issues

;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.

;; This file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.

;;; Commentary:

;; This package provides regression tests for haskell-completions package.

;;; Code:

(require 'ert)
(require 'haskell-mode)
(require 'haskell-completions)


(ert-deftest haskell-completions-can-grab-prefix-test ()
"Tests the function `haskell-completions-can-grab-prefix'."
(with-temp-buffer
(haskell-mode)
(should (eql nil (haskell-completions-can-grab-prefix)))
(insert " ")
(should (eql nil (haskell-completions-can-grab-prefix)))
(insert "a")
(should (eql t (haskell-completions-can-grab-prefix)))
(save-excursion
(insert " ")
(should (eql nil (haskell-completions-can-grab-prefix)))
(insert "bc-")
(should (eql t (haskell-completions-can-grab-prefix)))
(insert "\n")
(should (eql nil (haskell-completions-can-grab-prefix)))
(insert "def:#!")
(should (eql t (haskell-completions-can-grab-prefix))))
(should (eql t (haskell-completions-can-grab-prefix)))
;; punctuation tests
(save-excursion (insert ")"))
(should (eql t (haskell-completions-can-grab-prefix)))
(save-excursion (insert ","))
(should (eql t (haskell-completions-can-grab-prefix)))
(save-excursion (insert "'"))
(should (eql t (haskell-completions-can-grab-prefix)))
;; should return nil in the middle of word
(save-excursion (insert "bcd"))
(should (eql nil (haskell-completions-can-grab-prefix)))
;; region case
(let ((p (point)))
(goto-char (point-min))
(push-mark)
(goto-char p)
(activate-mark)
(should (eql nil (haskell-completions-can-grab-prefix))))))


(provide 'haskell-completions-tests)
;;; haskell-completions-tests.el ends here