-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpq-compile.el
65 lines (53 loc) · 2.26 KB
/
pq-compile.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
;;; pq-compile.el --- Compile the `pq-core` module -*- lexical-binding: t; -*-
;; Copyright (C) 2022 Free Software Foundation, Inc.
;; 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:
;;
;;; Code:
(defvar pq--compile-directory
(file-name-directory
(or
(if (fboundp 'macroexp-file-name) (macroexp-file-name)) ;Emacs≥28
load-file-name
buffer-file-name
(locate-library "pq"))))
(defun pq--compile-module ()
"Compile the `pq-core' module."
(with-temp-buffer
(setq default-directory pq--compile-directory)
(let* ((exitcode (call-process "make" nil t)))
(if (zerop exitcode)
(message "Compilation of `pq-core' succeeded")
(let ((out (buffer-string)))
(if noninteractive
(message "Compilation of `pq-core' failed:\n%s" out)
(with-current-buffer (get-buffer-create "*pq-compile*")
(setq default-directory pq--compile-directory)
(let ((inhibit-read-only t))
(erase-buffer)
(insert out))
(compilation-mode)
(pop-to-buffer (current-buffer))
(error "Compilation of `pq-core' failed"))))))))
(defun pq--compile-maybe ()
(cond
(noninteractive ;; Batch use: try to compile but delay errors when possible.
(ignore-errors (pq--compile-module))
(require 'pq-core nil t))
;; FIXME: Should we first try it silently (i.e. without prompting the user)?
((not (y-or-n-p "PQ needs to compile the `pq-core' module. Do it now?"))
(message "Continuing without `pq-core'; some operations may fail"))
(t
(pq--compile-module)
(require 'pq-core))))
(provide 'pq-compile)
;;; pq-compile.el ends here