From: Eshel Yaron Date: Mon, 29 Aug 2022 17:33:19 +0000 (+0300) Subject: ENHANCED: Pass keystrokes to the top-level directly when appropriate X-Git-Tag: v0.2.0~68 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=353ef846fb4df9ea49f486f7ba06d392df5d8791;p=dict.git ENHANCED: Pass keystrokes to the top-level directly when appropriate --- diff --git a/sweep.el b/sweep.el index ba4e342..2fd6954 100644 --- a/sweep.el +++ b/sweep.el @@ -257,6 +257,17 @@ module name, F is a functor name and N is its arity." sweep-prolog-server-port)) (select-window (display-buffer buf)))) +(defun sweep-top-level--post-self-insert-function () + (when-let ((pend (cdr comint-last-prompt))) + (let* ((pstart (car comint-last-prompt)) + (prompt (buffer-substring-no-properties pstart pend))) + (when (and (= (point) (1+ pend)) + (not (string-empty-p prompt)) + (not (string= "?- " (substring prompt + (- pend pstart 3) + (- pend pstart)))) + (not (string= "| " prompt))) + (comint-send-input))))) ;;;###autoload (define-derived-mode sweep-top-level-mode comint-mode "sweep Top-level" @@ -266,7 +277,8 @@ module name, F is a functor name and N is its arity." comint-input-ignoredups t comint-prompt-read-only t comint-delimiter-argument-list '(?,) - comment-start "%")) + comment-start "%") + (add-hook 'post-self-insert-hook #'sweep-top-level--post-self-insert-function nil t)) (sweep--ensure-module)