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

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

[nongnu] elpa/lua-mode 4a203b9 172/468: add lua-send-defun (a lua-send-p


From: Philip Kaludercic
Subject: [nongnu] elpa/lua-mode 4a203b9 172/468: add lua-send-defun (a lua-send-proc replacement)
Date: Thu, 5 Aug 2021 04:58:30 -0400 (EDT)

branch: elpa/lua-mode
commit 4a203b9e35b057d07adb4454f70fc7cc5d9f1904
Author: Leonardo Etcheverry <leo@kalio.net>
Commit: Leonardo Etcheverry <leo@kalio.net>

    add lua-send-defun (a lua-send-proc replacement)
    
    This patch creates a new `lua-send-defun` function which refactors the
    existing `lua-send-proc` to use `lua-send-region` instead of its current
    implementation (which basically reimplments `lua-send-region` inline.)
    
    It also fixes the issue where `lua-send-proc` would send the _previous_
    function when point is at the beggining of the `function` keyword.
---
 lua-mode.el | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/lua-mode.el b/lua-mode.el
index 4f79e82..ecfa78b 100644
--- a/lua-mode.el
+++ b/lua-mode.el
@@ -1222,6 +1222,28 @@ If `lua-process' is nil or dead, start a new process 
first."
   (interactive)
   (lua-send-region (line-beginning-position) (line-end-position)))
 
+(defun lua-send-defun (pos)
+  "Send the function definition around point to lua subprocess."
+  (interactive "d")
+  (save-excursion
+    (let ((start (if (save-match-data (looking-at "^function[ \t]"))
+                     ;; point already at the start of "function".
+                     ;; We need to handle this case explicitly since
+                     ;; lua-beginning-of-proc will move to the
+                     ;; beginning of the _previous_ function.
+                     (point)
+                   ;; point is not at the beginning of function, move
+                   ;; there and bind start to that position
+                   (lua-beginning-of-proc)
+                   (point)))
+          (end (progn (lua-end-of-proc) (point))))
+
+      ;; make sure point is in a function defintion before sending to
+      ;; the subprocess
+      (if (and (>= pos start) (< pos end))
+          (lua-send-region start end)
+        (error "Not on a function definition")))))
+
 (defun lua-send-region (start end)
   "Send region to lua subprocess."
   (interactive "r")



reply via email to

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