-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathquickfix-erlang.el
110 lines (82 loc) · 3.57 KB
/
quickfix-erlang.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
;;; quickfix-erlang.el --- erlang fixes for quickfix-mode
;; Copyright (C) 2012-2013 Ulises Cervino Beresi
;; Author: Ulises Cervino Beresi <[email protected]>
;; Created: 21 Dec 2012
;; Keywords: languages
;; This file is not part of GNU Emacs.
;; URL: https://github.com/ulises/quickfix-mode
;; Version: 0.0.1
;; Package-Requires: '((quickfix-mode 0.0.1))
;;; Code
;; License: GNU General Public License version 3, or (at your option) any later version
(require 'quickfix-mode)
(defvar quickfix-erlang-generic-fn-re
"function \\(\\w+\\)/\\([0-9]+\\)"
"Regexp to extract the function and arity from a flymake error/warning.")
(defvar quickfix-erlang-undefined-fn-re
"^function \\(\\w+\\)/\\([0-9]+\\) undefined$"
"Regexp to test whether the flymake error is about an undefined function.")
(defvar quickfix-erlang-unused-fn-re
"^Warning: function \\(\\w+\\)/\\([0-9]+\\) is unused$"
"Regexp to test whether the flymake error is about an unused function.")
(defvar quickfix-erlang-fn-skeleton
"%s(%s) ->"
"Skeleton for defining an erlang function.")
(defun quickfix-erlang-get-undefined-function-name-and-arity (issue-at-point)
(when (not (null issue-at-point))
(let ((issue-text (flymake-ler-text issue-at-point)))
(string-match quickfix-erlang-generic-fn-re issue-text)
(list (match-string 1 issue-text) (string-to-int (match-string 2 issue-text))))))
(defun quickfix-erlang-generic-arguments (n)
(interactive)
(quickfix-erlang-generic-arguments- n ()))
(defun quickfix-erlang-generic-arguments- (n acc)
(interactive)
(print n)
(if (<= n 0) (mapconcat 'identity acc ",")
(quickfix-erlang-generic-arguments- (- n 1) (cons (format "_Arg%d" n) acc))))
(defun quickfix-erlang-undefined-fn-fix (issue-at-point)
(interactive)
(let* ((name-and-arity (quickfix-erlang-get-undefined-function-name-and-arity issue-at-point))
(fn-name (car name-and-arity))
(fn-arity (car (cdr name-and-arity)))
(gen-args (quickfix-erlang-generic-arguments fn-arity)))
;; go to the end of the buffer and start a new para
(end-of-buffer)
(insert-string "\n")
;; insert the function's skeleton
(insert-string
(format quickfix-erlang-fn-skeleton fn-name gen-args))
;; place point at beginning of argument list
(beginning-of-line)
(search-forward "(")))
(defun quickfix-erlang-unused-fn-fix (issue-at-point)
(save-excursion
(interactive)
(let* ((name-and-arity (quickfix-erlang-get-undefined-function-name-and-arity issue-at-point))
(fn-name (car name-and-arity))
(fn-arity (car (cdr name-and-arity))))
(beginning-of-buffer)
(search-forward-regexp "^\\-export[^].)]")
(end-of-line)
(backward-char 3)
(insert-string (format ", %s/%d" fn-name fn-arity)))))
(defvar quickfix-erlang-undefined-fn-predicate
(quickfix-when-text-matches
quickfix-erlang-undefined-fn-re
"define function"))
(defvar quickfix-erlang-unused-fn-predicate
(quickfix-when-text-matches quickfix-erlang-unused-fn-re
"export function"))
;; registering handlers
(defvar quickfix-erlang-undefined-fn-handler
(quickfix-make-handler quickfix-erlang-undefined-fn-predicate
'quickfix-erlang-undefined-fn-fix))
(defvar quickfix-erlang-unused-fn-handler
(quickfix-make-handler quickfix-erlang-unused-fn-predicate
'quickfix-erlang-unused-fn-fix))
(quickfix-add-handler
quickfix-erlang-undefined-fn-handler 'erlang-mode)
(quickfix-add-handler
quickfix-erlang-unused-fn-handler 'erlang-mode)
;;; quickfix-erlang.el ends here