diff options
| -rw-r--r-- | .elpaignore | 1 | ||||
| -rw-r--r-- | .gitignore | 3 | ||||
| -rw-r--r-- | pq-compile.el | 61 | ||||
| -rw-r--r-- | pq.el | 24 |
4 files changed, 86 insertions, 3 deletions
diff --git a/.elpaignore b/.elpaignore new file mode 100644 index 0000000..98e124b --- /dev/null +++ b/.elpaignore @@ -0,0 +1 @@ +test.el @@ -1,4 +1,7 @@ *.so #*# +*.elc +/pq-autoloads.el +/pq-pkg.el diff --git a/pq-compile.el b/pq-compile.el new file mode 100644 index 0000000..574aa4c --- /dev/null +++ b/pq-compile.el @@ -0,0 +1,61 @@ +;;; pq-compile.el --- Compile the `pq-core` module -*- lexical-binding: t; -*- + +;; Copyright (C) 2022 Free Software Foundation, Inc. + +;; Author: Stefan Monnier <monnier@iro.umontreal.ca> +;; Keywords: + +;; 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))) + (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 () + ;; FIXME: Should we first try it silently (i.e. without prompting the user)? + (if (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") + (pq--compile-module) + (require 'pq-core))) + + +(provide 'pq-compile) +;;; pq-compile.el ends here @@ -1,8 +1,8 @@ -;;; pq.el --- libpq binding +;;; pq.el --- libpq binding -*- lexical-binding: t; -*- ;; Copyright (C) 2020-2022 Free Software Foundation, Inc. -;; Author: Tom Gillespie +;; Author: Tom Gillespie <tgbugs@gmail.com> ;; URL: https://github.com/anse1/emacs-libpq ;; Version: 0.01 ;; Package-Requires: ((emacs "25")) @@ -26,7 +26,25 @@ ;;; Code: -(if t (require 'pq-core)) +(require 'pq-core nil t) ;Don't signal an error if the module is absent. + +;; Try and compile the `pq-core' module when we compile the PQ package. +(eval-when-compile + (unless (or (featurep 'pq-core) + ;; Try and avoid running this code when we're just + ;; loading the uncompiled `pq.el'. + (and (fboundp 'macroexp-compiling-p) ;Emacs≥28 + (not (macroexp-compiling-p)))) + (require 'pq-compile) + (declare-function pq--compile-module "pq-compile" ()) + (ignore-errors (pq--compile-module)))) + +;; Try and compile the `pq-core' module when the PQ package is loaded. +(unless (featurep 'pq-core) + (require 'pq-compile) + (declare-function pq--compile-maybe "pq-compile" ()) + (pq--compile-maybe)) + (provide 'pq) |
