From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alex Kost Subject: [PATCH 4/5] emacs: Improve REPL procedures. Date: Tue, 21 Oct 2014 22:12:26 +0400 Message-ID: <87oat547hx.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:34927) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XgdvE-00005S-Dt for guix-devel@gnu.org; Tue, 21 Oct 2014 14:12:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xgdv5-0004aK-8m for guix-devel@gnu.org; Tue, 21 Oct 2014 14:12:40 -0400 Received: from mail-la0-x229.google.com ([2a00:1450:4010:c03::229]:44744) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xgdv4-0004XP-Sc for guix-devel@gnu.org; Tue, 21 Oct 2014 14:12:31 -0400 Received: by mail-la0-f41.google.com with SMTP id pn19so1531936lab.14 for ; Tue, 21 Oct 2014 11:12:29 -0700 (PDT) Received: from leviafan (128-74-164-65.broadband.corbina.ru. [128.74.164.65]) by mx.google.com with ESMTPSA id x6sm4827765lbj.40.2014.10.21.11.12.28 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Oct 2014 11:12:28 -0700 (PDT) List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org To: guix-devel@gnu.org --=-=-= Content-Type: text/plain More internal changes. --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0004-emacs-Improve-REPL-procedures.patch >From 6dd7a04f6021892b79b88579297cdf3358e3c2dc Mon Sep 17 00:00:00 2001 From: Alex Kost Date: Mon, 20 Oct 2014 23:23:32 +0400 Subject: [PATCH 4/5] emacs: Improve REPL procedures. * emacs/guix-backend.el (guix-start-process-maybe): Add 'start-msg' and 'end-msg' optional arguments. (guix-start-repl-maybe): Likewise. Do not kill buffer with a dead process. (guix-repl-exit): New procedure. (guix-eval-in-repl): Use 'geiser-repl--send'. --- emacs/guix-backend.el | 46 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/emacs/guix-backend.el b/emacs/guix-backend.el index ddc106f..e6f0944 100644 --- a/emacs/guix-backend.el +++ b/emacs/guix-backend.el @@ -152,24 +152,31 @@ from operations performed in Guix REPL by a user.") (list (concat "--listen=" (number-to-string guix-default-port)))))) -(defun guix-start-process-maybe () - "Start Geiser REPL configured for Guix if needed." - (guix-start-repl-maybe) +(defun guix-start-process-maybe (&optional start-msg end-msg) + "Start Geiser REPL configured for Guix if needed. +START-MSG and END-MSG are strings displayed in the minibuffer in +the beginning and in the end of the starting process. If nil, +display default messages." + (guix-start-repl-maybe nil + (or start-msg "Starting Guix REPL ...") + (or end-msg "Guix REPL has been started.")) (if guix-use-guile-server (guix-start-repl-maybe 'internal) (setq guix-internal-repl-buffer guix-repl-buffer))) -(defun guix-start-repl-maybe (&optional internal) +(defun guix-start-repl-maybe (&optional internal start-msg end-msg) "Start Guix REPL if needed. -If INTERNAL is non-nil, start an internal REPL." +If INTERNAL is non-nil, start an internal REPL. + +START-MSG and END-MSG are strings displayed in the minibuffer in +the beginning and in the end of the process. If nil, do not +display messages." (let* ((repl-var (guix-get-repl-buffer-variable internal)) (repl (symbol-value repl-var))) (unless (and (buffer-live-p repl) (get-buffer-process repl)) - ;; Kill REPL buffer with a dead process - (and (buffer-live-p repl) (kill-buffer repl)) - (or internal - (message "Starting Geiser REPL for Guix ...")) + (and start-msg (message start-msg)) + (setq guix-repl-operation-p nil) (let ((geiser-guile-binary (guix-get-guile-program internal)) (geiser-guile-init-file (or internal guix-helper-file)) (repl (get-buffer-create @@ -184,8 +191,8 @@ If INTERNAL is non-nil, start an internal REPL." "See buffer '%s' for details") guix-default-port (buffer-name repl)))) (set repl-var repl) + (and end-msg (message end-msg)) (unless internal - (message "Guix REPL has been started.") (run-hooks 'guix-after-start-repl-hook)))))) (defun guix-start-repl (buffer &optional address) @@ -251,6 +258,20 @@ This is a replacement for `geiser-repl--output-filter'." (match-beginning 0)) (geiser-autodoc--disinhibit-autodoc)))) +(defun guix-repl-exit (&optional internal no-wait) + "Exit the current Guix REPL. +If INTERNAL is non-nil, exit the internal REPL. +If NO-WAIT is non-nil, do not wait for the REPL process to exit: +send a kill signal to it and return immediately." + (let ((repl (symbol-value (guix-get-repl-buffer-variable internal)))) + (when (get-buffer-process repl) + (with-current-buffer repl + (geiser-con--connection-deactivate geiser-repl--connection t) + (comint-kill-subjob) + (unless no-wait + (while (get-buffer-process repl) + (sleep-for 0.1))))))) + (defun guix-get-repl-buffer (&optional internal) "Return Guix REPL buffer; start REPL if needed. If INTERNAL is non-nil, return an additional internal REPL." @@ -343,10 +364,7 @@ successful executing of the current operation, guix-operation-buffer operation-buffer) (let ((repl (guix-get-repl-buffer))) (with-current-buffer repl - (delete-region (geiser-repl--last-prompt-end) (point-max)) - (goto-char (point-max)) - (insert str) - (geiser-repl--send-input)) + (geiser-repl--send str)) (geiser-repl--switch-to-buffer repl))) (provide 'guix-backend) -- 2.1.2 --=-=-=--