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).
;; Maintainer: Eshel Yaron <me(at)eshelyaron(dot)com>
;; 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.
: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)
(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")
;;;###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.")