diff --git a/eval-in-repl-geiser.el b/eval-in-repl-geiser.el index 3812333..4e21a66 100644 --- a/eval-in-repl-geiser.el +++ b/eval-in-repl-geiser.el @@ -6,6 +6,7 @@ ;; Keywords: tools, convenience ;; URL: https://github.com/kaz-yos/eval-in-repl ;; Version: 0.9.4 +;; Package-Requires: ((emacs "24") (geiser "0.26")) ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by @@ -35,6 +36,14 @@ (require 'eval-in-repl) (require 'geiser-mode) +;;; +;;; CUSTOMIZATION VARIABLES +;;; eir-geiser-regexp +(defcustom eir-geiser-repl-regexp + "\\*Geiser \\(?:Guile\\|Mit\\|Racket\\) REPL\\*.*$" + "The regular expression used to search the geiser buffer." + :group 'eval-in-repl + :type 'string) ;;; ;;; GEISER RELATED @@ -42,9 +51,9 @@ (defalias 'eir-send-to-geiser (apply-partially 'eir-send-to-repl ;; fun-change-to-repl - #'switch-to-geiser + #'geiser-repl-switch ;; fun-execute - #'geiser-repl--maybe-send) + #'geiser-repl-maybe-send) "Send expression to * Racket/Guile REPL * and have it evaluated.") @@ -55,9 +64,9 @@ (interactive) (eir-eval-in-repl-lisp ;; repl-buffer-regexp - "\\* Racket REPL.*\\*$\\|\\* Guile REPL.*\\*$\\|\\* Mit REPL.*\\*$" + eir-geiser-repl-regexp ;; fun-repl-start - #'run-geiser + #'geiser ;; fun-repl-send #'eir-send-to-geiser ;; defun-string diff --git a/eval-in-repl-pkg.el b/eval-in-repl-pkg.el deleted file mode 100644 index 0b9f8f6..0000000 --- a/eval-in-repl-pkg.el +++ /dev/null @@ -1,32 +0,0 @@ -;;; Package definition file for eval-in-repl -;; -;; This has been created because it is a multi-file package. -;; Only dash.el and paredit.el are required for all installation. -;; Other dependencies are use-specific, so configure referring to: -;; https://github.com/kaz-yos/eval-in-repl/ -;; -;; (define-package NAME-STRING VERSION-STRING &optional DOCSTRING -;; REQUIREMENTS &rest EXTRA-PROPERTIES) -;; -;; Define a new package. -;; NAME-STRING is the name of the package, as a string. -;; VERSION-STRING is the version of the package, as a string. -;; DOCSTRING is a short description of the package, a string. -;; REQUIREMENTS is a list of dependencies on other packages. -;; Each requirement is of the form (OTHER-PACKAGE OTHER-VERSION), -;; where OTHER-VERSION is a string. -;; -(define-package - ;; NAME-STRING - "eval-in-repl" - ;; VERSION-STRING - "%VERSION%" - ;; DOCSTRING (Shown as Summary in package.el) - "Consistent ESS-like eval interface for various REPLs" - ;; REQUIREMENTS - '((dash "0.0.0") (paredit "0.0.0") (ace-window "0.0.0")) - ;; Shown as Homepage in package.el - :url "https://github.com/kaz-yos/eval-in-repl/" - ;; Shown as Keywords in package.el - ;; :keywords ("utilities" "repl") - ) diff --git a/eval-in-repl-shell.el b/eval-in-repl-shell.el index 725a9fa..ab490da 100644 --- a/eval-in-repl-shell.el +++ b/eval-in-repl-shell.el @@ -39,14 +39,55 @@ ;;; SHELL RELATED ;; ;;; eir-send-to-shell + +(cl-defgeneric eir-shell-execute () + nil) + +(cl-defmethod eir-shell-execute (&context (major-mode shell-mode)) + (comint-send-input)) + +(cl-defmethod eir-shell-execute (&context (major-mode term-mode)) + (term-send-input)) + +(cl-defmethod eir-shell-execute (&context (major-mode vterm-mode)) + (vterm-send-return)) + (defalias 'eir-send-to-shell (apply-partially 'eir-send-to-repl ;; fun-change-to-repl #'(lambda () (switch-to-buffer-other-window eir-shell-buffer-name)) ;; fun-execute - #'comint-send-input) + #'eir-shell-execute) "Send expression to 'eir-shell-buffer-name and have it evaluated.") +(cl-defmethod eir-insert (string &context (major-mode term-mode)) + "Overwrites the default implementation of eir-insert that just calls (insert string)" + (term-send-string (current-buffer) string)) + +(cl-defmethod eir-insert (string &context (major-mode vterm-mode)) + "term-send-string seems to work with vterm. Is there another command that should be used instead?" + (term-send-string (current-buffer) string)) + +(defun eir--remove-surrounding-stars (string) + (replace-regexp-in-string "^[*]\\(.+\\)[*]$" "\\1" string)) + +(cl-defgeneric eir-create-shell (shell-name) + (error "Could not create shell")) + +(cl-defmethod eir-create-shell (shell-name &context (eir-shell-type (eql shell))) + (shell shell-name)) + +(cl-defmethod eir-create-shell (shell-name &context (eir-shell-type (eql term))) + ;; make-term wraps the passed name with asterisks ie ** + (make-term (eir--remove-surrounding-stars shell-name) eir-shell-term-program)) + +(cl-defmethod eir-create-shell (shell-name &context (eir-shell-type (eql vterm))) + ;; vterm messes with the window configuration + (save-window-excursion + ;; Start vterm, and force buffer name to stay shell-name (in case + ;; when vterm-buffer-name-string is customized) + (with-current-buffer (vterm shell-name) + (setq-local vterm-buffer-name-string nil)))) ;;; eir-eval-in-shell ;;;###autoload @@ -57,7 +98,7 @@ (let* (;; Save current point (initial-point (point))) (eir-repl-start (regexp-quote eir-shell-buffer-name) - (lambda () (interactive) (shell eir-shell-buffer-name)) + (lambda () (interactive) (eir-create-shell eir-shell-buffer-name)) t) ;; Check if selection is present diff --git a/eval-in-repl.el b/eval-in-repl.el index 67e2b57..e2d46f1 100644 --- a/eval-in-repl.el +++ b/eval-in-repl.el @@ -5,7 +5,8 @@ ;; Author: Kazuki YOSHIDA ;; Keywords: tools, convenience ;; URL: https://github.com/kaz-yos/eval-in-repl -;; Version: 0.9.6 +;; Version: 0.9.7 +;; Package-Requires: (dash paredit ace-window) ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by @@ -120,6 +121,16 @@ Give a quoted symbol 'left, 'right, 'above, or 'below." :group 'eval-in-repl :type '(string)) +(defcustom eir-shell-type 'shell + "The shell mode to be used for newly spawned shells (ie shell or term)" + :group 'eval-in-repl + :type '(symbol) + :options '(shell term vterm)) + +(defcustom eir-shell-term-program "/bin/bash" + "The default term program to be used when eir-shell-type is 'term" + :group 'eval-in-repl + :type '(string)) ;;; ;;; COMMON ELEMENTS @@ -205,6 +216,12 @@ Also split the current window when staring a REPL." ;; Select the script window. (select-window window-script)))) +(cl-defgeneric eir-insert (string) + "Default implementation of eir-insert is just to insert a string into the apropriate buffer. +Other REPLs however might need other implementations (see for example eval-in-repl-shell.el +for term-mode). +Define your own with cl-defmethod" + (insert string)) ;;; eir-send-to-repl (defun eir-send-to-repl (fun-change-to-repl fun-execute region-string) @@ -219,7 +236,7 @@ and execute by FUN-EXECUTE." ;; Move to end of buffer (goto-char (point-max)) ;; Insert the string - (insert region-string) + (eir-insert region-string) ;; Execute (funcall fun-execute) ;; Come back to the script