branch: elpa/lua-mode
commit 24cc45edf0cb54c0de5724161ffbf40b1a133892
Author: immerrr <[email protected]>
Commit: immerrr <[email protected]>
Skip shebang line when sending to inferior buffer (issue #61)
---
lua-mode.el | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/lua-mode.el b/lua-mode.el
index 240cb8b..5942109 100644
--- a/lua-mode.el
+++ b/lua-mode.el
@@ -1637,8 +1637,25 @@ If `lua-process' is nil or dead, start a new process
first."
(lua-send-region start end)
(error "Not on a function definition")))))
+(defun lua-maybe-skip-shebang-line (start)
+ "Skip shebang (#!/path/to/interpreter/) line at beginning of buffer.
+
+Return a position that is after Lua-recognized shebang line (1st
+character in file must be ?#) if START is at its beginning.
+Otherwise, return START."
+ (save-restriction
+ (widen)
+ (if (and (eq start (point-min))
+ (eq (char-after start) ?#))
+ (save-excursion
+ (goto-char start)
+ (forward-line)
+ (point))
+ start)))
+
(defun lua-send-region (start end)
(interactive "r")
+ (setq start (lua-maybe-skip-shebang-line start))
(let* ((lineno (line-number-at-pos start))
(lua-tempfile (lua-make-temp-file "lua-"))
(lua-file (or (buffer-file-name) (buffer-name)))