emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/swift-mode d136303 076/496: Adding support for Swift REPL


From: ELPA Syncer
Subject: [nongnu] elpa/swift-mode d136303 076/496: Adding support for Swift REPL via comint-mode
Date: Sun, 29 Aug 2021 11:33:11 -0400 (EDT)

branch: elpa/swift-mode
commit d136303b737179d5abcbd38fb840bfc03a63f71e
Author: ap4y <lod@pisem.net>
Commit: ap4y <lod@pisem.net>

    Adding support for Swift REPL via comint-mode
---
 swift-mode.el | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 66 insertions(+)

diff --git a/swift-mode.el b/swift-mode.el
index a226a9b..eff7214 100644
--- a/swift-mode.el
+++ b/swift-mode.el
@@ -28,6 +28,7 @@
 ;;; Code:
 
 (require 'rx)
+(require 'comint)
 
 (eval-and-compile
   ;; Added in Emacs 24.3
@@ -318,6 +319,71 @@ Returns the column number as an integer."
 
 ;;; Mode definition
 
+;;; REPL
+(defcustom swift-mode-executable
+  "xcrun swift"
+  "Path to the Swift CLI.")
+
+(defgroup swift-repl nil
+  "Run a Swift REPL process in a buffer."
+  :group 'swift-repl)
+
+(defcustom swift-repl-mode-hook nil
+  "*Hook for customizing swift-repl mode."
+  :type 'hook
+  :group 'swift-repl)
+
+(defun swift-mode-run-repl (cmd &optional dont-switch-p)
+  "Run a REPL process, input and output via buffer `*swift-repl*'.
+If there is a process already running in `*swift-repl*', switch to that buffer.
+With argument CMD allows you to edit the command line (default is value
+of `swift-mode-executable').
+With DONT-SWITCH-P cursor will stay in current buffer.
+Runs the hook `swift-repl-mode-hook' \(after the `comint-mode-hook'
+is run).
+\(Type \\[describe-mode] in the process buffer for a list of commands.)"
+
+  (interactive (list (if current-prefix-arg
+                         (read-string "Run swift-repl: " swift-mode-executable)
+                       swift-mode-executable)))
+  (if (not (comint-check-proc "*swift-repl*"))
+      (save-excursion (let ((cmdlist (split-string cmd)))
+                        (set-buffer (apply 'make-comint "swift-repl" (car 
cmdlist)
+                                           nil (cdr cmdlist)))
+                        (swift-repl-mode))))
+  (setq swift-mode-executable cmd)
+  (setq swift-mode-repl-buffer "*swift-repl*")
+  (if (not dont-switch-p)
+      (pop-to-buffer "*swift-repl*")))
+
+(defvar swift-mode-repl-buffer)
+
+(defun swift-mode-send-region (start end)
+  "Send the current region to the inferior Javascript process.
+START and END define region within current buffer"
+  (interactive "r")
+  (swift-mode-run-repl swift-mode-executable t)
+  (comint-send-region swift-mode-repl-buffer start end)
+  (comint-send-string swift-mode-repl-buffer "\n"))
+
+(defun swift-mode-send-buffer ()
+  "Send the buffer to the Swift REPL process."
+  (interactive)
+  (swift-mode-send-region (point-min) (point-max)))
+
+(define-derived-mode swift-repl-mode comint-mode "Swift REPL"
+  "Major mode for interacting with Swift REPL.
+
+A REPL can be fired up with M-x swift-mode-run-repl.
+
+Customization: Entry to this mode runs the hooks on comint-mode-hook and
+swift-repl-mode-hook (in that order).
+
+You can send text to the REPL process from other buffers containing source.
+    swift-mode-send-region sends the current region to the REPL process,
+    swift-mode-send-buffer sends the current buffer to the REPL process.
+")
+
 ;; HACK: This syntax table is lifted directly from `rust-mode'. There may be
 ;; corner cases in the Swift syntax that are not accounted for.
 (defvar swift-mode-syntax-table



reply via email to

[Prev in Thread] Current Thread [Next in Thread]