[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/lua-mode fb12d2b 003/468: lua-send-region: create temporar
From: |
Philip Kaludercic |
Subject: |
[nongnu] elpa/lua-mode fb12d2b 003/468: lua-send-region: create temporary file to send lua code as one chunk |
Date: |
Thu, 5 Aug 2021 04:57:57 -0400 (EDT) |
branch: elpa/lua-mode
commit fb12d2b645bc1f444d8ae1e9b0fddd3136c45ca6
Author: juergen <juergen>
Commit: juergen <juergen>
lua-send-region: create temporary file to send lua code as one chunk
lua-send-region: wait for lua prompt
new custom variable: lua-prompt-regexp (used for comint-prompt-regex)
---
lua-mode.el | 57 +++++++++++++++++++++++++++++++++++++++++++++------------
1 file changed, 45 insertions(+), 12 deletions(-)
diff --git a/lua-mode.el b/lua-mode.el
index 67d1526..50cc3a9 100755
--- a/lua-mode.el
+++ b/lua-mode.el
@@ -11,7 +11,7 @@
;; Paul Du Bois <pld-lua@gelatinous.com> and
;; Aaron Smith <aaron-lua@gelatinous.com>.
-(defconst lua-version "$Revision: 1.2 $"
+(defconst lua-version "$Revision: 1.3 $"
"Lua Mode version number.")
;; Keywords: languages, processes, tools
@@ -117,6 +117,12 @@ Should be a list of strings."
:type 'string
:group 'lua)
+(defcustom lua-prompt-regexp "^>+[\t ]+"
+ "Regexp which matches the Lua program's prompt."
+ :group 'lua
+ :type 'regexp
+ )
+
(defvar lua-mode-hook nil
"Hooks called when Lua mode fires up.")
@@ -214,6 +220,7 @@ The following keys are bound:
(kill-all-local-variables)
(setq major-mode 'lua-mode)
(setq mode-name "Lua")
+ (setq comint-prompt-regexp lua-prompt-regexp)
(set (make-local-variable 'lua-process) nil) ; The active Lua subprocess
corresponding to current buffer
(set (make-local-variable 'lua-process-buffer) nil) ; Buffer used
for communication with Lua subprocess for current buffer.
(make-local-variable 'lua-default-command-switches)
@@ -896,9 +903,11 @@ This function just searches for a `end' at the beginning
of a line."
(setq switches lua-default-command-switches))
(setq lua-process-buffer (apply 'make-comint name program startfile
switches))
(setq lua-process (get-buffer-process lua-process-buffer))
- (save-excursion
- (set-buffer lua-process-buffer))
- )
+ ;; wait for prompt
+ (save-excursion
+ (set-buffer lua-process-buffer)
+ (while (not (lua-prompt-line))
+ (accept-process-output (get-buffer-process (current-buffer))))))
;;}}}
;;{{{ lua-kill-process
@@ -950,16 +959,40 @@ If `lua-process' is nil or dead, start a new process
first."
(defun lua-send-region (start end)
"Send region to lua subprocess."
(interactive "r")
- (or (and lua-process
- (comint-check-proc lua-process-buffer))
- (lua-start-process lua-default-application lua-default-application))
- (comint-simple-send lua-process
- (buffer-substring start end))
- (if lua-always-show
- (display-buffer lua-process-buffer)))
-
+ ;; make temporary lua file
+ (let ((tempfile (make-temp-file "lua-"))
+ (current-prompt nil))
+ (save-excursion
+ (write-region start end tempfile)
+ (or (and lua-process
+ (comint-check-proc lua-process-buffer))
+ (lua-start-process lua-default-application lua-default-application))
+ ;; kill lua process without query
+ (if (fboundp 'process-kill-without-query)
+ (process-kill-without-query lua-process))
+ ;; send dofile(tempfile)
+ (save-excursion
+ (set-buffer lua-process-buffer)
+ (let ((current-prompt (comint-next-prompt 1)))
+ (comint-simple-send (get-buffer-process (current-buffer)) (format
"dofile(\"%s\")" tempfile))
+ ;; wait for prompt
+ (while (or (= (comint-next-prompt 1) current-prompt)
+ (not (lua-prompt-line)))
+ (accept-process-output (get-buffer-process (current-buffer))))))
+ ;; remove temp. lua file
+ (delete-file tempfile)
+ (if lua-always-show
+ (display-buffer lua-process-buffer)))))
;;}}}
+;;{{{ lua-prompt-line
+
+(defun lua-prompt-line ()
+ (save-excursion
+ (forward-line 0)
+ (looking-at comint-prompt-regexp)))
+
;;{{{ lua-send-lua-region
+;;}}}
(defun lua-send-lua-region ()
"Send preset lua region to lua subprocess."
- [nongnu] branch elpa/lua-mode created (now 7ee3feb), Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 001fff1 001/468: Initial revision, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 99230fc 002/468: code cleanup: removed duplicate code from lua-send-buffer, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode fb12d2b 003/468: lua-send-region: create temporary file to send lua code as one chunk,
Philip Kaludercic <=
- [nongnu] elpa/lua-mode 05a9513 004/468: fixed copyright notice, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode f9cbb91 007/468: make lua-process-buffer and lua-process global, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode c13235f 008/468: fixed indention, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode d91bf2b 011/468: new buffer-local variable: lua-electric-flag, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 6a7929a 013/468: lua-postprocess-output-buffer: match first error, not last, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 78f7b78 014/468: emacs-compatibility: replace-in-string not available on GNU emacs, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode ea5c4a1 015/468: Documentation: Added installation notes, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 9d20d58 019/468: fold mode cleanup, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 78fc3ba 005/468: lua-postprocess-output-buffer: jump to lua errors in source files, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 8802c43 006/468: fixed lua-postprocess-output-buffer: start search from last prompt, Philip Kaludercic, 2021/08/05