-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsdev-mypy.el
125 lines (98 loc) · 3.88 KB
/
sdev-mypy.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
;;; sdev-mypy.el --- Python Type checking compilation-mode
;; Copyright (C) 2017 Andres Mariscal <[email protected]>
;;
;; Author: Andres Mariscal <[email protected]>
;; URL: https://github.com/SerialDev/mypy-mode
;; Created: 14 November 2017
;; Version: 1.0
;; Package-Requires: ((emacs "24.4"))
;;; Commentary:
;; pip install mypy , Python 3.6 +
;; Maintained by Andres Mariscal -- [email protected]
;;; License:
;; This file is not part of GNU Emacs.
;; However, it is distributed under the same license.
;; GNU Emacs 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.
;; GNU Emacs 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.
;;; Code:
(defun sdev-mypy-shell-command-to-buffer (command buffer-name &optional buffer-mode)
"Run a `command' ,pop and, append its output to buffer `buffer-name' ."
(with-current-buffer (pop-to-buffer buffer-name)
(goto-char (point-max))
(insert (shell-command-to-string command))
(goto-char (point-min))
(funcall buffer-mode)))
(defun sdev-mypy-buffer-mode (&optional buffer-or-name)
"Returns the major mode associated with a buffer.
If buffer-or-name is nil return current buffer's mode."
(buffer-local-value 'major-mode
(if buffer-or-name (get-buffer buffer-or-name) (current-buffer))))
(defun sdev-mypy-type-check()
"type checker for python.--inferstats "
(interactive)
(sdev-mypy-shell-command-to-buffer
(message "python -m mypy \
--ignore-missing-imports \
--disallow-incomplete-defs \
--disallow-any-explicit \
--disallow-any-generics \
--disallow-untyped-decorators \
--show-column-numbers \
--warn-return-any \
--warn-redundant-casts \
--warn-unused-ignores \
--check-untyped-defs \
--disallow-untyped-calls \
--python-version 3.6 \
%s" buffer-file-name)
"*py-typecheck*" 'sdev-mypy-mode))
;; a simple major mode, mypy-mode
(define-derived-mode sdev-mypy-mode compilation-mode "mypy"
"major mode for editing mypy language code."
)
(defun sdev-mypy-install()
(interactive)
(async-shell-command "pip install mypy"))
;{error mode support};
(pushnew '(mypy ("\\(.*py\\):\\([0-9]+\\):\\([0-9]+\\)?" 1 2 3))
compilation-error-regexp-alist-alist)
(make-face 'mypy-file-face)
(make-face 'mypy-line-face)
(make-face 'mypy-quoted-face)
(add-hook 'sdev-mypy-mode-hook (lambda()
(set (make-local-variable font-lock-type-face)
'mypy-file-face)
))
(add-hook 'sdev-mypy-mode-hook (lambda()
(set (make-local-variable font-lock-keyword-face)
'mypy-line-face)
))
(add-hook 'sdev-mypy-mode-hook (lambda()
(set (make-local-variable font-lock-variable-name-face)
'mypy-quoted-face)
))
(set-face-attribute 'mypy-file-face nil :foreground "#add8e6")
(set-face-attribute 'mypy-line-face nil :foreground "#ffffff")
(set-face-attribute 'mypy-quoted-face nil :foreground "#Fafad2")
(add-hook 'mypy-mode-hook (lambda()
(font-lock-add-keywords nil
'(("\\<\\(error\\):" 1 font-lock-warning-face prepend)
("\\<\\(info\\):" 1 font-lock-comment-face append)
("\"\\(\\(?:[^\"\\]+\\|\\\\\\(?:.\\|\\)\\)*\\)\"" 1 font-lock-variable-name-face append)
("\\(.*py*\\):" 1 font-lock-type-face append)
("\\([0-9]+\\):" 1 font-lock-keyword-face append)
))))
(defun sdev-mypy-buffer-dir()
(file-name-directory buffer-file-name))
(provide 'sdev-mypy)
;;; sdev-mypy.el ends here