-
Notifications
You must be signed in to change notification settings - Fork 2
/
run-command-recipes-make.el
83 lines (67 loc) · 2.91 KB
/
run-command-recipes-make.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
;;; run-command-recipes-make.el --- Recipe of `run-command' for GNU Make -*- lexical-binding: t; -*-
;; Author: semenInRussia <[email protected]>
;; Version: 0.1.0
;; Keywords: extensions run-command
;; Homepage: https://github.com/semenInRussia/emacs-run-command-recipes
;; URL: https://github.com/semenInRussia/emacs-run-command-recipes/blob/main/docs/make.md
;; 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 <https://www.gnu.org/licenses/>.
;;; Commentary:
;; To use this recipe put the following to your Emacs configuration:
;;
;; (run-command-recipes-use-one 'make)
;;
;;; Code:
(require 'dash)
(require 'f)
(require 'run-command-recipes-project)
(defcustom run-command-recipes-make-executable "make"
"Path to the GNU Make executable."
:group 'run-command-recipes
:type 'string)
(defcustom run-command-recipes-makefile-names '("Makefile" "Make")
"The list of names in which can be defined commands for GNU Make."
:group 'run-command-recipes
:type '(repeat string))
(defun run-command-recipes-make ()
"Recipe of `run-command' for GNU Make."
(and
(run-command-recipes-make-project-p)
(executable-find run-command-recipes-make-executable)
(->>
(run-command-recipes-make--project-makefile)
(run-command-recipes-make--commands)
(--map
(list
:command-name (concat "make-" it)
:command-line (concat "make " it)
:display (concat "Make: `" it "'"))))))
(defun run-command-recipes-make--commands (makefile)
"Return the list of commands names that was defined in MAKEFILE."
(let ((s (f-read makefile))
(commands nil)
(pos 0))
(while (string-match "^\\([^ \n]+\\):" s pos)
(push (match-string 1 s) commands)
(setq pos (match-end 0)))
commands))
(defun run-command-recipes-make--project-makefile (&optional root)
"Return path to the Makefile of the project at ROOT.
ROOT defaults to value of `run-command-recipes-project-root'"
(or root (setq root (run-command-recipes-project-root)))
(f-join root "Makefile"))
(defun run-command-recipes-make-project-p (&optional root)
"Return non-nil if the project at ROOT has Makefile.
ROOT defaults to value of `run-command-recipes-project-root'"
(or root (setq root (run-command-recipes-project-root)))
(run-command-recipes-project-root-has-one-of run-command-recipes-makefile-names))
(provide 'run-command-recipes-make)
;;; run-command-recipes-make.el ends here