File: eproject-compile.el

package info (click to toggle)
eproject-el 1.5+git20180312.068218d-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 204 kB
  • sloc: lisp: 1,092; sh: 10; makefile: 2
file content (88 lines) | stat: -rw-r--r-- 2,965 bytes parent folder | download
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
;;; eproject-compile.el --- eproject compilation extensions

;; Copyright (C) 2009  Jonathan Rockway
;;           (C) 2012  Alex Bennée

;; Author: Jonathan Rockway <jon@jrock.us>
;; Keywords: eproject

;; 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:

;; This extension to eproject adds the ability to compile projects
;; using meta-data defined in your project.  For example:
;;
;; (define-project-type rockbox
;;   (generic-git)
;;   (look-for "../rockbox.git/rbutil")
;;   :common-compiles ("make" "make install" "make fullzip"))
;;
;; Now when you you call eproject-compile you will be presented with
;; a prompt with history pre-filled with your favourite compile sequences.


;;; History:
;;
;; 2012-05-16: `eproject-compile' moved from eproject-extras to this
;; file.  Extended by Alex Bennée to populate the history
;; intelligently.

;;; Code:

(require 'eproject)
(require 'compile)

(defun* eproject--build-new-history (&optional (buffer (current-buffer)))
  "Return a list of compile commands suitable for use as a compile history."
  (eproject--do-in-buffer
   (buffer)
   (let ((potential-compiles (eproject-attribute :common-compiles))
	 (new-compile-history (list ())))
     (if potential-compiles
	 (mapcar
	  #'(lambda (c)
              (format "cd %s && %s" (eproject-root) c))
	  potential-compiles)
       (list (format "cd %s && make -k" (eproject-root)))))))

;;;###autoload
(defun eproject-compile ()
  "Run `compile' in the project root.

This uses a computed history based on project attributes, the
existing `compile-history', and `compile-command' which may have
been locally set by a mode.

To provide defaults for a project or project type, set the
`:common-compiles' attribute to a list of strings representing
the command to invoke."
  (interactive)
  (let* ((default-directory (eproject-root))
	 (ehistory (append (eproject--build-new-history) compile-history))
	 (ecompile (read-shell-command
		    "Compile command: " compile-command 'ehistory)))
    (compile ecompile)))

(defun eproject-compile-repeat ()
  "Run 'compile' in the project root, using most recent command
in compile-command."
  (interactive)
  (let* ((default-directory (eproject-root)))
    (compile compile-command)))

(define-key eproject-mode-map (kbd "C-c C-k") #'eproject-compile)

(provide 'eproject-compile)
;;; eproject-compile.el ends here