-
Notifications
You must be signed in to change notification settings - Fork 4
/
company-ncl-mode.el
74 lines (59 loc) · 2.78 KB
/
company-ncl-mode.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
;;; company-ncl-mode.el --- company-mode completion backend for ncl-mode -*- lexical-binding: t -*-
;; Copyright (C) 2012-2018 Yagnesh Raghava Yakkala <http://yagnesh.org>
;; Author: Yagnesh Raghava Yakkala. http://yagnesh.org
;; Created: Thursday, September 22 2016
;; This file is part of ncl-mode.
;; ncl-mode 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 of the License, or
;; (at your option) any later version.
;; ncl-mode 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. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;;; Code:
(require 'company)
(require 'cl-lib)
(require 'ncl-mode-keywords)
(defcustom company-ncl-enable-fuzzy nil nil)
(setq ncl-all-keywords (delete-dups (append ncl-key-builtin ncl-key-contrib
ncl-key-diag ncl-key-gsn
ncl-key-keywords ncl-key-operators
ncl-key-pop ncl-key-resources
ncl-key-shea ncl-key-skewt
ncl-key-user ncl-key-windrose
ncl-key-wrfarw)))
(defun company-ncl-fuzzy-match (prefix candidate)
(if company-ncl-enable-fuzzy
(cl-subsetp (string-to-list prefix)
(string-to-list candidate))
(string-prefix-p prefix candidate)))
;;;###autoload
(defun company-ncl-mode (command &optional arg &rest ignored)
"`company-mode' completion backend for `ncl-mode'."
(interactive (list 'interactive))
(cl-case command
(interactive (company-begin-backend 'company-ncl-mode))
(prefix (and (member major-mode '(ncl-mode inf-ncl-mode))
(company-grab-symbol)))
(candidates (cl-remove-if-not
(lambda (c) (company-ncl-fuzzy-match arg c))
ncl-all-keywords))
(sorted t)))
;;;###autoload
(add-hook 'ncl-mode-hook
(lambda ()
(setq-local company-backends
'((company-ncl-mode company-dabbrev company-etags
company-gtags company-files)))))
;;;###autoload
(add-hook 'inf-ncl-mode-hook
(lambda ()
(setq-local company-backends
'((company-ncl-mode company-dabbrev company-etags
company-gtags company-files)))))
(provide 'company-ncl-mode)
;;; company-ncl-mode.el ends here