[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/swift-mode 286c4b8 077/496: Merge pull request #21 from ap
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/swift-mode 286c4b8 077/496: Merge pull request #21 from ap4y/feature_repl |
Date: |
Sun, 29 Aug 2021 11:33:11 -0400 (EDT) |
branch: elpa/swift-mode
commit 286c4b844d5c92fe31519276f61f7ee242f8ceb6
Merge: 98b627a d136303
Author: Chris Barrett <chris.d.barrett@me.com>
Commit: Chris Barrett <chris.d.barrett@me.com>
Merge pull request #21 from ap4y/feature_repl
Feature REPL
---
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
- [nongnu] elpa/swift-mode 8641ebc 048/496: Mention old-school installation method, (continued)
- [nongnu] elpa/swift-mode 8641ebc 048/496: Mention old-school installation method, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 8e72839 004/496: Add basic syntax table, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 5274877 010/496: Add single-line comments to syntax table, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode d110515 011/496: Font lock tweaks, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 272473b 005/496: Remove currently unused mode map, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode cbb19f2 003/496: Add basic font-locking, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 7df8b6d 037/496: Remove dash.el dependency., ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 09b50fa 042/496: [Fix #12] Merge mode code in a single file, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode c882c70 053/496: Replace `if` exprs with `when` exprs, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode d136303 076/496: Adding support for Swift REPL via comint-mode, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 286c4b8 077/496: Merge pull request #21 from ap4y/feature_repl,
ELPA Syncer <=
- [nongnu] elpa/swift-mode e0fba71 083/496: repl -> REPL, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 48cbf55 088/496: Extend a bit installation instructions for package.el, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 7e77211 087/496: Remove redundant autoload, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode a092adc 091/496: Return default paragraph definitions., ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode c9c1271 089/496: Make flycheck work with multiple sources, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 4ac4ea3 098/496: Add font-lock for declaration expression with destructuring, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 6abb788 121/496: Add keywords header, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 07780b4 118/496: Merge pull request #30 from ap4y/syntactic_fontification, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 18ea989 134/496: Merge pull request #42 from ap4y/customizable_multiline_dot_statement, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode d42c53c 147/496: Use semantic smie function instead of regex for multi-line dot, ELPA Syncer, 2021/08/29