#+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.
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
: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.
-;;; 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)
(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 ()
(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."
(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 ()
(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 ()
;; (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