Skip to content

Commit afa350c

Browse files
tgbugsmarsam
authored andcommitted
pq-compile.el: added
changes from Stefan Monnier
1 parent cb47fcf commit afa350c

File tree

3 files changed

+82
-3
lines changed

3 files changed

+82
-3
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
*.so
22
#*#
33

4+
*.elc
5+
/pq-autoloads.el
6+
/pq-pkg.el
47

pq-compile.el

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
;;; pq-compile.el --- Compile the `pq-core` module -*- lexical-binding: t; -*-
2+
3+
;; Copyright (C) 2022 Free Software Foundation, Inc.
4+
5+
;; This program is free software; you can redistribute it and/or modify
6+
;; it under the terms of the GNU General Public License as published by
7+
;; the Free Software Foundation, either version 3 of the License, or
8+
;; (at your option) any later version.
9+
10+
;; This program is distributed in the hope that it will be useful,
11+
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
;; GNU General Public License for more details.
14+
15+
;; You should have received a copy of the GNU General Public License
16+
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
18+
;;; Commentary:
19+
20+
;;
21+
22+
;;; Code:
23+
24+
(defvar pq--compile-directory
25+
(file-name-directory
26+
(or
27+
(if (fboundp 'macroexp-file-name) (macroexp-file-name)) ;Emacs≥28
28+
load-file-name
29+
buffer-file-name
30+
(locate-library "pq"))))
31+
32+
(defun pq--compile-module ()
33+
"Compile the `pq-core' module."
34+
(with-temp-buffer
35+
(setq default-directory pq--compile-directory)
36+
(let* ((exitcode (call-process "make" nil t)))
37+
(if (zerop exitcode)
38+
(message "Compilation of `pq-core' succeeded")
39+
(let ((out (buffer-string)))
40+
(with-current-buffer (get-buffer-create "*pq-compile*")
41+
(setq default-directory pq--compile-directory)
42+
(let ((inhibit-read-only t))
43+
(erase-buffer)
44+
(insert out))
45+
(compilation-mode)
46+
(pop-to-buffer (current-buffer))
47+
(error "Compilation of `pq-core' failed")))))))
48+
49+
(defun pq--compile-maybe ()
50+
;; FIXME: Should we first try it silently (i.e. without prompting the user)?
51+
(if (not (y-or-n-p "PQ needs to compile the `pq-core' module. Do it now?"))
52+
(message "Continuing without `pq-core'; some operations may fail")
53+
(pq--compile-module)
54+
(require 'pq-core)))
55+
56+
57+
(provide 'pq-compile)
58+
;;; pq-compile.el ends here

pq.el

+21-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
;;; pq.el --- libpq binding
1+
;;; pq.el --- libpq binding -*- lexical-binding: t; -*-
22

33
;; Copyright (C) 2020-2022 Free Software Foundation, Inc.
44

5-
;; Author: Tom Gillespie
5+
;; Author: Tom Gillespie <[email protected]>
66
;; URL: https://github.com/anse1/emacs-libpq
77
;; Version: 0.01
88
;; Package-Requires: ((emacs "25"))
@@ -26,7 +26,25 @@
2626

2727
;;; Code:
2828

29-
(if t (require 'pq-core))
29+
(require 'pq-core nil t) ; Don't signal an error if the module is absent.
30+
31+
;; Try and compile the `pq-core' module when we compile the PQ package.
32+
(eval-when-compile
33+
(unless (or (featurep 'pq-core)
34+
;; Try and avoid running this code when we're just
35+
;; loading the uncompiled `pq.el'.
36+
(and (fboundp 'macroexp-compiling-p) ;Emacs≥28
37+
(not (macroexp-compiling-p))))
38+
(require 'pq-compile)
39+
(declare-function pq--compile-module "pq-compile" ())
40+
(ignore-errors (pq--compile-module))))
41+
42+
;; Try and compile the `pq-core' module when the PQ package is loaded.
43+
(unless (featurep 'pq-core)
44+
(require 'pq-compile)
45+
(declare-function pq--compile-maybe "pq-compile" ())
46+
(pq--compile-maybe))
47+
3048

3149
(provide 'pq)
3250

0 commit comments

Comments
 (0)