emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/pq afa350c7e8 1/4: pq-compile.el: added


From: ELPA Syncer
Subject: [elpa] externals/pq afa350c7e8 1/4: pq-compile.el: added
Date: Sun, 19 Jun 2022 20:58:00 -0400 (EDT)

branch: externals/pq
commit afa350c7e88f00da8ee83942e358090ae618e9d0
Author: Tom Gillespie <tgbugs@gmail.com>
Commit: Mario Rodas <marsam@users.noreply.github.com>

    pq-compile.el: added
    
    changes from Stefan Monnier
---
 .gitignore    |  3 +++
 pq-compile.el | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 pq.el         | 24 +++++++++++++++++++++---
 3 files changed, 82 insertions(+), 3 deletions(-)

diff --git a/.gitignore b/.gitignore
index 9f8c20a9e2..2c16467025 100644
--- a/.gitignore
+++ b/.gitignore
@@ -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 0000000000..5899ce7620
--- /dev/null
+++ b/pq-compile.el
@@ -0,0 +1,58 @@
+;;; 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)))
+          (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
diff --git a/pq.el b/pq.el
index b7a943355b..69ef12c5a2 100644
--- a/pq.el
+++ b/pq.el
@@ -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)
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]