[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/sweeprolog c5b1504ca8 033/166: ADDED: sweep-top-level comm
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/sweeprolog c5b1504ca8 033/166: ADDED: sweep-top-level command and appropriate mode |
Date: |
Fri, 30 Sep 2022 04:59:23 -0400 (EDT) |
branch: elpa/sweeprolog
commit c5b1504ca8528743a8528aa2c824d8536f0a7c29
Author: Eshel Yaron <me@eshelyaron.com>
Commit: Eshel Yaron <me@eshelyaron.com>
ADDED: sweep-top-level command and appropriate mode
---
README.org | 15 ++++++++++++++
sweep.el | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
sweep.pl | 10 +++++++++
3 files changed, 90 insertions(+), 4 deletions(-)
diff --git a/README.org b/README.org
index 021160bb9e..e6450c0d8e 100644
--- a/README.org
+++ b/README.org
@@ -194,6 +194,21 @@ permutations of the list =(1 2 3 4 5)=:
num)
#+end_src
+
+* The Prolog top-level
+
+#+FINDEX: sweep-top-level
+=sweep= provides a classic Prolog top-level interface for interacting
+with the embedded Prolog runtime. To start the top-level, use =M-x
+sweep-top-level=. This open a dedicated buffer called
+=*sweep-top-level*= which hosts a live Prolog top-level. If the
+top-level buffer already exists, =sweep-top-level= will reuse it. To
+create another one or more top-level buffers, run the command =C-x x u=
+(or =M-x rename-uniquely=) in the buffer called =*sweep-top-level*= and
+then run =M-x sweep-top-level= again. This will change the name of the
+original top-level buffer to something like =*sweep-top-level*<2>= and
+allow the new top-level to claim the buffer name =*sweep-top-level*=.
+
* Finding Prolog code
:PROPERTIES:
:CUSTOM_ID: finding-prolog-code
diff --git a/sweep.el b/sweep.el
index 0ba1589161..ba4e34240f 100644
--- a/sweep.el
+++ b/sweep.el
@@ -26,6 +26,8 @@
;;; Code:
+(require 'comint)
+
(defgroup sweep nil
"SWI-Prolog Embedded in Emacs."
:group 'prolog)
@@ -65,6 +67,9 @@
:type '(list string)
:group 'sweep)
+
+(defvar sweep-prolog-server-port 12345)
+
;;;###autoload
(defun sweep-module-compile ()
"Compile sweep-module."
@@ -90,11 +95,23 @@
(require 'sweep-module))
(error "Sweep will not work until `sweep-module' is compiled!"))))
+(defun sweep-start-prolog-server ()
+ (sweep-open-query "user"
+ "sweep"
+ "sweep_start_prolog_server"
+ sweep-prolog-server-port)
+ (let ((sol (sweep-next-solution)))
+ (sweep-close-query)
+ sol))
+
(defun sweep-init ()
+ (setq sweep-prolog-server-port (+ (random 10000)
+ sweep-prolog-server-port))
(apply #'sweep-initialize
(cons (expand-file-name "bin/swipl" (file-name-directory
load-file-name))
- (cons "-q" sweep-init-args))))
+ (cons "-q" sweep-init-args)))
+ (sweep-start-prolog-server))
(defun sweep-predicates-collection ()
(sweep-open-query "user" "sweep" "sweep_predicates_collection" nil)
@@ -208,14 +225,58 @@ module name, F is a functor name and N is its arity."
(message "Package install successful.")
(user-error "Pacakge installation failed"))))
-;;;; Testing:
+;; (defun sweep-file-handler (operation &rest args)
+;; (cond ((eq operation 'expand-file-name) (apply sweep-expand-file-name
args) )
+;; ;; ((eq operation 'file-name-all-completions))
+;; ;; ((eq operation 'file-name-completion))
+;; (t (let ((inhibit-file-name-handlers
+;; (cons 'my-file-handler
+;; (and (eq inhibit-file-name-operation operation)
+;; inhibit-file-name-handlers)))
+;; (inhibit-file-name-operation operation))
+;; (apply operation args)))))
+
+;; (defun sweep-expand-file-name (name &optional dir)
+;; (sweep-open-query "user" "sweep" "sweep_expand_file_name" (cons name dir))
+;; (let ((sol (sweep-next-solution)))
+;; (sweep-close-query)
+;; (when (sweep-true-p sol)
+;; (cdr sol))))
+
+;;;###autoload
+(defun sweep-top-level ()
+ "Start an interactive Prolog top-level."
+ (interactive)
+ (let ((buf (get-buffer-create "*sweep-top-level*")))
+ (with-current-buffer buf
+ (unless (eq major-mode 'sweep-top-level-mode)
+ (sweep-top-level-mode)))
+ (make-comint-in-buffer "sweep-top-level"
+ buf
+ (cons "localhost"
+ sweep-prolog-server-port))
+ (select-window (display-buffer buf))))
+
+
+;;;###autoload
+(define-derived-mode sweep-top-level-mode comint-mode "sweep Top-level"
+ "Major mode for interacting with an inferior Prolog interpreter."
+ :group 'sweep-top-level
+ (setq-local comint-prompt-regexp (rx (seq line-start "?- "))
+ comint-input-ignoredups t
+ comint-prompt-read-only t
+ comint-delimiter-argument-list '(?,)
+ comment-start "%"))
-;; (add-to-list 'load-path (file-name-directory (buffer-file-name)))
-;; (require 'sweep)
(sweep--ensure-module)
(when sweep-init-on-load (sweep-init))
+;;;; Testing:
+
+;; (add-to-list 'load-path (file-name-directory (buffer-file-name)))
+;; (require 'sweep)
+
(provide 'sweep)
;;; sweep.el ends here
diff --git a/sweep.pl b/sweep.pl
index 6f9ef2a01b..c423dd5c9d 100644
--- a/sweep.pl
+++ b/sweep.pl
@@ -5,6 +5,7 @@
sweep_predicates_collection/2,
sweep_modules_collection/2,
sweep_packs_collection/2,
+ sweep_start_prolog_server/2,
sweep_pack_install/2,
sweep_module_path/2
]).
@@ -20,6 +21,7 @@
:- use_module(library(pldoc/man_index)).
:- use_module(library(lynx/html_text)).
:- use_module(library(prolog_pack)).
+:- use_module(library(prolog_server)).
:- dynamic sweep_current_color/3,
sweep_open/2,
@@ -230,3 +232,11 @@ sweep_pack_info(pack(Name0, _, Desc0, Version0, URLS0),
[Name, Desc, Version, UR
sweep_pack_install(PackName, []) :-
atom_string(Pack, PackName), pack_install(Pack, [silent(true),
upgrade(true), interactive(false)]).
+
+
+% sweep_expand_file_name([SpecString|_Dir], Path) :-
+% term_string(Spec, String),
+% absolute_file_name(library(lists), Path, [access(exist),
extensions(['pl', '']), solutions(all)]).
+
+sweep_start_prolog_server(Port, []) :-
+ prolog_server(Port, []).
- [nongnu] elpa/sweeprolog 353ef846fb 035/166: ENHANCED: Pass keystrokes to the top-level directly when appropriate, (continued)
- [nongnu] elpa/sweeprolog 353ef846fb 035/166: ENHANCED: Pass keystrokes to the top-level directly when appropriate, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 72cc4d516b 014/166: PORT: detect linux vs macOS shared object extension in Makefile, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog e029eb3e3c 016/166: update .build.yml, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 0aa0a46631 017/166: PORT: don't use clang's -fdiagnostics-absolute-paths, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog d4a501e9af 020/166: PORT: use rpath linker option, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog b75179cc6e 022/166: Revert rpath tweaks, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 2f5dd9f13c 024/166: FIXED: Use more robust Prolog to C string conversion, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 5f0f223318 023/166: Use LD_PRELOAD for testing, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog ea04f467b9 027/166: ADDED: sweep-pack-install for interactively installing packs, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 25bda86c48 032/166: Use load-file-path instead of custom hack, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog c5b1504ca8 033/166: ADDED: sweep-top-level command and appropriate mode,
ELPA Syncer <=
- [nongnu] elpa/sweeprolog a06906287f 036/166: ADDED: sweep_funcall/2, 3 for calling Elisp functions from Prolog, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 5b23e9819b 038/166: DOC: Add Prolog initialization section to the manual, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 4e4d8508cd 039/166: ENHANCED: Allow using swipl compiled with GMP, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 4b4b28f15a 007/166: Add module descriptions to sweep-find-module annotation function, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 0078ef8ff0 060/166: ENHANCED: syntax errors coloring, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog e38825d0e2 066/166: ENHANCED: use a distinct face for structured comments, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 84e6182685 077/166: FIXED: detect "|:" prompt in the top-level, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 6e5c822fc8 116/166: ADDED: sweep-colourise-buffer-on-idle user option, on by default, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog a7ce69558e 111/166: Makefile: Use "--batch" instead of "-batch" for consistency, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 5b54d23b8b 086/166: ENHANCED: apply an appropriate face to global predicate calls, ELPA Syncer, 2022/09/30