I liked the interactivity of Clojure/Lisp, where you can see the result in the REPL. I tried to implement the same behaviour for SQL-mode.
The idea is that when I do C-x C-e on the SQL-statemnt, I see the result in the
*SQL*-mode, which will function as an alternative REPL.
To get this behaviour, I wrote two functions (I use Evil, so I have a normal, visual and insert state).
(defun sql-region-evaluate (start end) "This will send the selected region to the SQL process" (interactive "r") (if (evil-visual-state-p) (sql-send-string (buffer-substring-no-properties start end))))
When I select a region, then I will use this function.
I do not want to use the
sql-send-buffer command, because sometimes I type the next statement after the previous statement. When calling
sql-send-buffer both SQL-statements will be queried, instead the last one.
So that's why I use the
sql-send-region. The key command vap is an Evil keysequence in normal state which will visually selects the block.
(defun sql-evaluate (s) "It will visually select the text block, and send it to the SQL process" (interactive) ;; If I'm in the normal mode (if (evil-normal-state-p) (lambda () (execute-kbd-macro (kbd "vap")) (sql-send-region start end) )))
When I call
sql-region-evaluate, it works fine.
When I call
sql-evaluate, nothing happens, I don't get any error message or something. So I cannot trace it back where it went wrong.
Any suggestions where it could get wrong?