forked from takeokunn/company-dockerfile
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompany-dockerfile.el
More file actions
94 lines (77 loc) · 2.55 KB
/
company-dockerfile.el
File metadata and controls
94 lines (77 loc) · 2.55 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
;;; company-dockerfile.el --- Company mode backend for dockefile -*- lexical-binding: t -*-
;; Author: takeokunn
;; Maintainer: takeokunn
;; Jen-Chieh Shen <jcs090218@gmail.com>
;; Version: 0.1
;; Package-Requires: ((emacs "24.4") (company "0.8.12") (dockerfile-mode "1.0"))
;; Homepage: https://github.com/elp-revive/company-dockerfile
;; Keywords: convenience
;; This file is not part of GNU Emacs
;; 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 program 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.
;; For a full copy of the GNU General Public License
;; see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; To use this package with company-mode run;
;; (add-hook 'dockerfile-mode-hook
;; (lambda ()
;; (add-to-list 'company-backends #'company-dockerfile))
;; To use this package, you must be in dockerfile major mode.
;;; Code:
(require 'cl-lib)
(require 'company)
(require 'dockerfile-mode)
(defconst company-dockerfile-instruction-keywords
'("FROM"
"AS"
"RUN"
"CMD"
"LABEL"
"MAINTAINER"
"EXPOSE"
"ENV"
"ADD"
"COPY"
"ENTRYPOINT"
"VOLUME"
"USER"
"WORKDIR"
"ARG"
"ONBUILD"
"STOPSIGNAL"
"HEALTHCHECK"
"SHELL")
"Keywords of the dockerfile.")
(defconst company-dockerfile-option-keywords
'("--platform="
"--chown="
"--interval="
"--timeout="
"--start-period="
"--retries=")
"Keywords of the dockerfile options")
(defvar company-dockerfile-keywords
(cl-concatenate 'list company-dockerfile-instruction-keywords company-dockerfile-option-keywords))
(defun company-dockerfile--candidates (prefix)
(let (res)
(dolist (item company-dockerfile-keywords)
(when (string-prefix-p prefix item)
(push item res)))
res))
;;;###autoload
(defun company-dockerfile (command &optional arg &rest ignored)
"Dockerfile backend for company mode."
(interactive (list 'interactive))
(cl-case command
(interactive (company-begin-backend 'company-dockerfile))
(prefix (when (eq major-mode 'dockerfile-mode)
(company-grab-symbol)))
(candidates (company-dockerfile--candidates arg))))
(provide 'company-dockerfile)
;;; company-dockerfile.el ends here