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

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

[nongnu] elpa/sweeprolog b92f25f764 030/166: Cleanup sweep.el


From: ELPA Syncer
Subject: [nongnu] elpa/sweeprolog b92f25f764 030/166: Cleanup sweep.el
Date: Fri, 30 Sep 2022 04:59:23 -0400 (EDT)

branch: elpa/sweeprolog
commit b92f25f76493a9473530f7de25e58cb4b8464ac9
Author: Eshel Yaron <me@eshelyaron.com>
Commit: Eshel Yaron <me@eshelyaron.com>

    Cleanup sweep.el
---
 README.org | 15 ++++++----
 sweep.el   | 99 +++++++++++++++++++++++++++++++++++---------------------------
 2 files changed, 65 insertions(+), 49 deletions(-)

diff --git a/README.org b/README.org
index 415f821a81..96d090cf19 100644
--- a/README.org
+++ b/README.org
@@ -14,8 +14,6 @@
 #+texinfo_header:        @set MAINTAINEREMAIL @email{me@eshelyaron.com}
 #+texinfo_header:        @set MAINTAINERCONTACT 
@uref{mailto:me@eshelyaron.com,contact the maintainer}
 
-#+macro: kbd (eval (let ((case-fold-search nil) (regexp (regexp-opt '("SPC" 
"RET" "LFD" "TAB" "BS" "ESC" "DELETE" "SHIFT" "Ctrl" "Meta" "Alt" "Cmd" "Super" 
"UP" "LEFT" "RIGHT" "DOWN") 'words))) (format 
"@@texinfo:@kbd{@@%s@@texinfo:}@@" (replace-regexp-in-string regexp 
"@@texinfo:@key{@@\\&@@texinfo:}@@" $1 t))))
-
 This manual describes the Emacs package =sweep=, which provides an
 embedded SWI-Prolog runtime inside of Emacs.
 
@@ -84,6 +82,11 @@ The different parts of =sweep= are structured as follows:
    it when loaded. Note that this may take a couple of minutes as the
    SWI-Prolog runtime may need to be built as well.
 
+* TODO Prolog initialization and cleanup
+
+#+VINDEX: sweep-init-on-load
+#+VINDEX: sweep-init-args
+
 * Querying Prolog
 :PROPERTIES:
 :CUSTOM_ID: querying-prolog
@@ -194,21 +197,21 @@ permutations of the list =(1 2 3 4 5)=:
 :END:
 
 #+FINDEX: sweep-find-module
-=sweep= provides the command {{{kbd(M-x sweep-find-module)}}} for
+=sweep= provides the command =M-x sweep-find-module= for
 selecting and jumping to the source code of a loaded or auto-loadable
 Prolog module.  =sweep= integrates with Emacs' standard completion API
 to annotate candidate modules in the completion UI with their =PLDoc=
 description when available.
 
 #+FINDEX: sweep-find-predicate
-Along with {{{kbd(M-x sweep-find-module)}}}, =sweep= provides the
-command {{{kbd(M-x sweep-find-predicate)}}} jumping to the definition a
+Along with =M-x sweep-find-module=, =sweep= provides the
+command =M-x sweep-find-predicate= jumping to the definition a
 loaded or auto-loadable Prolog predicate.
 
 * Installing Prolog packages
 
 #+FINDEX: sweep-pack-install
-The command {{{kbd(M-x sweep-pack-install)}}} can be used to install
+The command =M-x sweep-pack-install= can be used to install
 or upgrade a SWI-Prolog =pack=. When selecting a =pack= to install, the
 completion candidates are annotated with description and the version
 of each package.
diff --git a/sweep.el b/sweep.el
index 437d1efe34..4b21eb130f 100644
--- a/sweep.el
+++ b/sweep.el
@@ -1,20 +1,35 @@
-;;; sweep.el --- SWI-Prolog Embedded in Emacs -*- lexical-binding:t -*-
+;;; sweep.el --- Embedded SWI-Prolog -*- lexical-binding:t -*-
 
 ;; Copyright (C) 2022 Eshel Yaron
 
-;; Authors: Eshel Yaron <me(at)eshelyaron(dot)com>
+;; Author: Eshel Yaron <me(at)eshelyaron(dot)com>
 ;; Maintainer: Eshel Yaron <me(at)eshelyaron(dot)com>
-;; Keywords: prolog programming
+;; Keywords: prolog languages extensions
+;; URL: https://git.sr.ht/~protesilaos/denote
+;; Mailing-List: https://lists.sr.ht/~protesilaos/denote
+;; Package-Version: 0.1.0
+;; Package-Requires: ((emacs "27"))
 
 ;; This file is NOT part of GNU Emacs.
 
-;;; Package-Version: 0.1.0
-;;; Package-Requires: ((emacs "28"))
-
 ;;; Commentary:
+;;
+;; sweep is an embedding of SWI-Prolog in Emacs.  It uses the C
+;; interfaces of both SWI-Prolog and Emacs Lisp to create a
+;; dynamically loaded Emacs module that contains the SWI-Prolog
+;; runtime.  As such, =sweep= has parts written in C, in Prolog and in
+;; Emacs Lisp.
+;;
+;; For more information, see the sweep manual at
+;; <https://eshelyaron.com/sweep.html>.  The manual can also be read
+;; locally by evaluating (info "(sweep) Top")
 
 ;;; Code:
 
+(defun sweep-home-directory ()
+  "Return the installation directory of `sweep'."
+  (file-name-directory (locate-library "sweep.el" t)))
+
 (defgroup sweep nil
   "SWI-Prolog Embedded in Emacs."
   :group 'prolog)
@@ -40,8 +55,19 @@
 (defvar sweep-install-buffer-name "*Install sweep*"
   "Name of the buffer used for compiling sweep-module.")
 
-(defun sweep-home-directory ()
-  (file-name-directory (locate-library "sweep.el" t)))
+(defcustom sweep-init-on-load t
+  "If non-nil, initialize Prolog when `sweep' is loaded."
+  :package-version '((sweep "0.1.0"))
+  :type 'boolean
+  :group 'sweep)
+
+(defcustom sweep-init-args (list (expand-file-name
+                                  "sweep.pl"
+                                  (sweep-home-directory)))
+  "List of strings used as initialization arguments for Prolog."
+  :package-version '((sweep "0.1.0"))
+  :type '(list string)
+  :group 'sweep)
 
 ;;;###autoload
 (defun sweep-module-compile ()
@@ -60,44 +86,32 @@
         (message "Compilation of `sweep' module succeeded")
       (error "Compilation of `sweep' module failed!"))))
 
-(unless (require 'sweep-module nil t)
-  (if (y-or-n-p "Sweep needs `sweep-module' to work.  Compile it now? ")
-      (progn
-        (sweep-module-compile)
-        (require 'sweep-module))
-  (error "Sweep will not work until `sweep-module' is compiled!")))
-
-(sweep-initialize (expand-file-name "bin/swipl"
-                                    (sweep-home-directory))
-                  "-q"
-                  (expand-file-name "sweep.pl"
-                                    (sweep-home-directory)))
-
-(declare-function sweep-initialize    "sweep-module")
-(declare-function sweep-initialized-p "sweep-module")
-(declare-function sweep-open-query    "sweep-module")
-(declare-function sweep-cut-query     "sweep-module")
-(declare-function sweep-close-query   "sweep-module")
-(declare-function sweep-next-solution "sweep-module")
-(declare-function sweep-cleanup       "sweep-module")
+(defun sweep--ensure-module ()
+  (unless (require 'sweep-module nil t)
+    (if (y-or-n-p "Sweep needs `sweep-module' to work.  Compile it now? ")
+        (progn
+          (sweep-module-compile)
+          (require 'sweep-module))
+      (error "Sweep will not work until `sweep-module' is compiled!"))))
+
+(defun sweep-init ()
+  (apply #'sweep-initialize
+         (cons (expand-file-name "bin/swipl" (sweep-home-directory))
+               (cons "-q" sweep-init-args))))
 
 (defun sweep-predicates-collection ()
   (sweep-open-query "user" "sweep" "sweep_predicates_collection" nil)
   (let ((sol (sweep-next-solution)))
     (sweep-close-query)
-    (let ((car (car sol)))
-      (when (or (eq car '!)
-                (eq car t))
-        (cdr sol)))))
+    (when (sweep-true-p sol)
+      (cdr sol))))
 
 (defun sweep-predicate-location (mfn)
   (sweep-open-query "user" "sweep" "sweep_predicate_location" mfn)
   (let ((sol (sweep-next-solution)))
     (sweep-close-query)
-    (let ((car (car sol)))
-      (when (or (eq car '!)
-                (eq car t))
-        (cdr sol)))))
+    (when (sweep-true-p sol)
+      (cdr sol))))
 
 (defun sweep-read-predicate ()
   "Read a Prolog predicate (M:F/N) from the minibuffer, with completion."
@@ -128,16 +142,14 @@ module name, F is a functor name and N is its arity."
   (sweep-open-query "user" "sweep" "sweep_modules_collection" nil)
   (let ((sol (sweep-next-solution)))
     (sweep-close-query)
-    (when (or (eq (car sol) '!)
-              (eq (car sol) t))
+    (when (sweep-true-p sol)
       (cdr sol))))
 
 (defun sweep-module-path (mod)
   (sweep-open-query "user" "sweep" "sweep_module_path" mod)
   (let ((sol (sweep-next-solution)))
     (sweep-close-query)
-    (when (or (eq (car sol) '!)
-              (eq (car sol) t))
+    (when (sweep-true-p sol)
       (cdr sol))))
 
 (defun sweep-read-module-name ()
@@ -161,13 +173,11 @@ module name, F is a functor name and N is its arity."
   (interactive (list (sweep-read-module-name)))
   (find-file (sweep-module-path mod)))
 
-
 (defun sweep-packs-collection ()
   (sweep-open-query "user" "sweep" "sweep_packs_collection" "")
   (let ((sol (sweep-next-solution)))
     (sweep-close-query)
-    (when (or (eq (car sol) '!)
-              (eq (car sol) t))
+    (when (sweep-true-p sol)
       (cdr sol))))
 
 (defun sweep-read-pack-name ()
@@ -206,6 +216,9 @@ module name, F is a functor name and N is its arity."
 ;; (add-to-list 'load-path (file-name-directory (buffer-file-name)))
 ;; (require 'sweep)
 
+(sweep--ensure-module)
+(when sweep-init-on-load (sweep-init))
+
 (provide 'sweep)
 
 ;;; sweep.el ends here



reply via email to

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