-
Notifications
You must be signed in to change notification settings - Fork 5
/
company-matlab.el
92 lines (69 loc) · 2.73 KB
/
company-matlab.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
;;; company-matlab.el --- support for the Matlab programming language
;; Copyright (C) 2016 yuhonglin
;; Author: yuhonglin <yuhonglin1986@gmail.com>
;; Keywords: languages, terminals
;; This program 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.
;; 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.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; The company backend of matlab mode.
;; It is based on matlab-server.el.
;;; Code:
(require 'cl-lib)
(require 'company)
(require 'matlab)
(require 's)
(require 'matlab-server)
(defvar company-matlab-is-completing nil
"Whether it is during the completing backend.")
(defvar company-matlab-complete-output ""
"The output of matlab used by completing")
(defvar company-matlab-complete-candidates ""
"The candidates")
(defun company-matlab-process-received-data (inarg)
(mapcar 'car
(mapcar 'cdr
(s-match-strings-all "'\\([^ \t\n']+\\)'" inarg))))
;; some are copied from matlab-shell-collect-command-output function
(defun company-matlab-get-candidates (arg)
(if (and matlab-server-process
(eq (process-status matlab-server-process) 'run))
(let ((res (company-matlab-process-received-data
(matlab-send-request-sync
(concat "tmp=com.mathworks.jmi.MatlabMCR;tmp.mtFindAllTabCompletions('"
arg "'," (int-to-string (length arg)) ",0)")))))
(if (eq res nil)
;; nil
(company-other-backend)
res))))
(defun company-matlab-grab-symbol ()
(let* ((prefix (buffer-substring (point)
(save-excursion (skip-chars-backward "a-zA-Z0-9._")
(point)))))
(if (or (= (length prefix) 0)
(string= (substring prefix 0 1) ".")
(string= (substring prefix 0 1) "/"))
nil
prefix)))
(defun company-matlab (command &optional arg &rest ignored)
(interactive (list 'interactive))
(cl-case command
(interactive (company-begin-backend 'company-matlab))
(prefix (and (or (eq major-mode 'matlab-mode)
(string= (buffer-name) "*MATLAB*"))
(company-matlab-grab-symbol)))
(no-cache nil)
(duplicates t)
(ignore-case nil)
(candidates
(company-matlab-get-candidates arg))))
(defun company-matlab-company-cancel-hook (arg))
(add-to-list 'company-completion-cancelled-hook 'company-matlab-company-cancel-hook)
(provide 'company-matlab)