From: Eshel Yaron Date: Thu, 29 Sep 2022 05:58:05 +0000 (+0300) Subject: ADDED: new command sweeprolog-restart for resetting sweep X-Git-Tag: v0.4.1~1 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=83bbd580315573f54a90b2a13b8b35e6c630ea9a;p=sweep.git ADDED: new command sweeprolog-restart for resetting sweep * (sweeprolog-init): new &rest args * (sweeprolog-restart): new command * sweeprolog-prefix-map: bind it --- diff --git a/sweep.pl b/sweep.pl index afaa971..c8a29f0 100644 --- a/sweep.pl +++ b/sweep.pl @@ -776,12 +776,6 @@ sweep_top_level_server_loop_(accept(Buffer), ServerSocket) :- set_stream(InStream, close_on_abort(false)), set_stream(OutStream, close_on_abort(false)), thread_create(sweep_top_level_client(InStream, OutStream, Peer), T, [detached(true)]), - at_halt(( is_thread(T), - thread_property(T, status(running)) - -> thread_signal(T, thread_exit(0)), - thread_join(T, _) - ; true - )), thread_property(T, id(Id)), asserta(sweep_top_level_thread_buffer(Id, Buffer)), sweep_top_level_server_loop(ServerSocket). diff --git a/sweeprolog.el b/sweeprolog.el index 523e536..b02c32d 100644 --- a/sweeprolog.el +++ b/sweeprolog.el @@ -6,7 +6,7 @@ ;; Maintainer: Eshel Yaron ;; Keywords: prolog languages extensions ;; URL: https://git.sr.ht/~eshel/sweep -;; Package-Version: 0.4.0 +;; Package-Version: 0.4.1 ;; Package-Requires: ((emacs "28")) ;; This file is NOT part of GNU Emacs. @@ -119,9 +119,9 @@ inserted to the input history in `sweeprolog-top-level-mode' buffers." :group 'sweeprolog) (defcustom sweeprolog-init-args (list "-q" - "--no-signals" - "-g" - "[library(sweep)]") + "--no-signals" + "-g" + "[library(sweep)]") "List of strings used as initialization arguments for Prolog." :package-version '((sweeprolog "0.3.1")) :type '(repeat string) @@ -285,13 +285,42 @@ FLAG and VALUE are specified as strings and read as Prolog terms." (when (sweeprolog-true-p sol) (setq sweeprolog-prolog-server-port (cdr sol))))) -(defun sweeprolog-init () +(defun sweeprolog-init (&rest args) (apply #'sweeprolog-initialize (cons (or sweeprolog-swipl-path (executable-find "swipl")) - sweeprolog-init-args)) + (append sweeprolog-init-args args))) (sweeprolog-setup-message-hook) (sweeprolog-start-prolog-server)) +(defun sweeprolog-restart (&rest args) + "Restart the embedded Prolog runtime. + +ARGS is a list of strings appended to the value of +`sweeprolog-init-args' to produce the Prolog initialization +arguments. + +Interactively, with a prefix arguments, prompt for ARGS. +Otherwise set ARGS to nil." + (interactive + (and + current-prefix-arg + (split-string-shell-command (read-string "swipl arguments: ")))) + (when-let ((top-levels (seq-filter (lambda (buffer) + (eq 'sweeprolog-top-level-mode + (buffer-local-value 'major-mode + buffer))) + (buffer-list)))) + (if (y-or-n-p "Stop running sweep top-level processes?") + (dolist (buffer top-levels) + (let ((process (get-buffer-process buffer))) + (when (process-live-p process) + (delete-process process)))) + (user-error "Cannot restart sweep with running top-level processes"))) + (message "Stoping sweep.") + (sweeprolog-cleanup) + (message "Starting sweep.") + (apply #'sweeprolog-init args)) + (defvar sweeprolog-predicate-completion-collection nil) (defvar-local sweeprolog-buffer-module "user") @@ -1342,13 +1371,14 @@ Interactively, a prefix arg means to prompt for BUFFER." ;;;###autoload (defvar sweeprolog-prefix-map (let ((map (make-sparse-keymap))) + (define-key map "F" #'sweeprolog-set-prolog-flag) + (define-key map "P" #'sweeprolog-pack-install) + (define-key map "R" #'sweeprolog-restart) + (define-key map "e" #'sweeprolog-view-messages) + (define-key map "l" #'sweeprolog-load-buffer) (define-key map "m" #'sweeprolog-find-module) (define-key map "p" #'sweeprolog-find-predicate) (define-key map "t" #'sweeprolog-top-level) - (define-key map "l" #'sweeprolog-load-buffer) - (define-key map "P" #'sweeprolog-pack-install) - (define-key map "F" #'sweeprolog-set-prolog-flag) - (define-key map "e" #'sweeprolog-view-messages) map) "Keymap for `sweeprolog' global commands.")