Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 94 additions & 8 deletions layers/+lang/sql/funcs.el
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,6 @@
;; along with this program. If not, see <http://www.gnu.org/licenses/>.


(defun spacemacs/sql-populate-products-list (&rest args)
"Update Spacemacs list of sql products"
(setq
spacemacs-sql-highlightable sql-product-alist
spacemacs-sql-startable (cl-remove-if-not
(lambda (product) (sql-get-product-feature (car product) :sqli-program))
sql-product-alist)))

(defun spacemacs//sql-setup-company ()
"Conditionally setup company based on backend."
(pcase sql-backend
Expand All @@ -45,3 +37,97 @@
"Conditionally setup sql backend."
(when (eq sql-backend 'lsp)
(lsp-deferred)))

(defun spacemacs//sql-product-completion-table ()
"Return an alist of (PRODUCT-PRETTY-NAME . PRODUCT-SYMBOL)."
(mapcar
(lambda (product)
(cons (plist-get (cdr product) :name)
(car product)))
sql-product-alist))

(defun spacemacs//sql-read-product (pred)
"Read an SQL product, with completion limited by predicate PRED."
(let* ((alist (spacemacs//sql-product-completion-table))
(input (completing-read
"SQL Product: "
alist pred 'require-match
nil 'sql-product-history)))
(cdr (assoc input alist))))

(defun spacemacs/sql-highlight (product)
"Set SQL dialect-specific highlighting."
(interactive (list (spacemacs//sql-read-product nil)))
(sql-set-product product))

(defun spacemacs/sql-start (product)
"Set SQL dialect-specific highlighting and start inferior SQLi process."
(interactive
(list (spacemacs//sql-read-product
(lambda (product) (sql-get-product-feature (cdr product) :sqli-program)))))
(sql-set-product product)
(sql-product-interactive))

(defun spacemacs/sql-send-string-and-focus ()
"Send a string to SQLi and switch to SQLi in `insert state'."
(interactive)
(let ((sql-pop-to-buffer-after-send-region t))
(call-interactively 'sql-send-string)
(evil-insert-state)))

(defun spacemacs/sql-send-buffer-and-focus ()
"Send the buffer to SQLi and switch to SQLi in `insert state'."
(interactive)
(let ((sql-pop-to-buffer-after-send-region t))
(sql-send-buffer)
(evil-insert-state)))

(defun spacemacs/sql-send-paragraph-and-focus ()
"Send the paragraph to SQLi and switch to SQLi in `insert state'."
(interactive)
(let ((sql-pop-to-buffer-after-send-region t))
(sql-send-paragraph)
(evil-insert-state)))

(defun spacemacs/sql-send-region-and-focus (start end)
"Send region to SQLi and switch to SQLi in `insert state'."
(interactive "r")
(let ((sql-pop-to-buffer-after-send-region t))
(sql-send-region start end)
(evil-insert-state)))

(defun spacemacs/sql-send-line-and-next-and-focus ()
"Send the current line to SQLi and switch to SQLi in `insert state'."
(interactive)
(let ((sql-pop-to-buffer-after-send-region t))
(sql-send-line-and-next)))

(defun spacemacs/sql-send-string ()
"Send a string to SQLi and stays in the same region."
(interactive)
(let ((sql-pop-to-buffer-after-send-region nil))
(call-interactively 'sql-send-string)))

(defun spacemacs/sql-send-buffer ()
"Send the buffer to SQLi and stays in the same region."
(interactive)
(let ((sql-pop-to-buffer-after-send-region nil))
(sql-send-buffer)))

(defun spacemacs/sql-send-paragraph ()
"Send the paragraph to SQLi and stays in the same region."
(interactive)
(let ((sql-pop-to-buffer-after-send-region nil))
(sql-send-paragraph)))

(defun spacemacs/sql-send-region (start end)
"Send region to SQLi and stays in the same region."
(interactive "r")
(let ((sql-pop-to-buffer-after-send-region nil))
(sql-send-region start end)))

(defun spacemacs/sql-send-line-and-next ()
"Send the current line to SQLi and stays in the same region."
(interactive)
(let ((sql-pop-to-buffer-after-send-region nil))
(sql-send-line-and-next)))
91 changes: 0 additions & 91 deletions layers/+lang/sql/packages.el
Original file line number Diff line number Diff line change
Expand Up @@ -43,97 +43,6 @@
;; should not set this to anything else than nil
;; the focus of SQLi is handled by spacemacs conventions
sql-pop-to-buffer-after-send-region nil)
(advice-add 'sql-add-product :after #'spacemacs/sql-populate-products-list)
(advice-add 'sql-del-product :after #'spacemacs/sql-populate-products-list)
(spacemacs/sql-populate-products-list)
(defun spacemacs//sql-source (products)
"return a source for helm selection"
`((name . "SQL Products")
(candidates . ,(mapcar (lambda (product)
(cons (sql-get-product-feature (car product) :name)
(car product)))
products))
(action . (lambda (candidate) (helm-marked-candidates)))))

(defun spacemacs/sql-highlight ()
"set SQL dialect-specific highlighting"
(interactive)
(let ((product (car (helm
:sources (list (spacemacs//sql-source spacemacs-sql-highlightable))))))
(sql-set-product product)))

(defun spacemacs/sql-start ()
"set SQL dialect-specific highlighting and start inferior SQLi process"
(interactive)
(let ((product (car (helm
:sources (list (spacemacs//sql-source spacemacs-sql-startable))))))
(sql-set-product product)
(sql-product-interactive product)))

(defun spacemacs/sql-send-string-and-focus ()
"Send a string to SQLi and switch to SQLi in `insert state'."
(interactive)
(let ((sql-pop-to-buffer-after-send-region t))
(call-interactively 'sql-send-string)
(evil-insert-state)))

(defun spacemacs/sql-send-buffer-and-focus ()
"Send the buffer to SQLi and switch to SQLi in `insert state'."
(interactive)
(let ((sql-pop-to-buffer-after-send-region t))
(sql-send-buffer)
(evil-insert-state)))

(defun spacemacs/sql-send-paragraph-and-focus ()
"Send the paragraph to SQLi and switch to SQLi in `insert state'."
(interactive)
(let ((sql-pop-to-buffer-after-send-region t))
(sql-send-paragraph)
(evil-insert-state)))

(defun spacemacs/sql-send-region-and-focus (start end)
"Send region to SQLi and switch to SQLi in `insert state'."
(interactive "r")
(let ((sql-pop-to-buffer-after-send-region t))
(sql-send-region start end)
(evil-insert-state)))

(defun spacemacs/sql-send-line-and-next-and-focus ()
"Send the current line to SQLi and switch to SQLi in `insert state'."
(interactive)
(let ((sql-pop-to-buffer-after-send-region t))
(sql-send-line-and-next)))

(defun spacemacs/sql-send-string ()
"Send a string to SQLi and stays in the same region."
(interactive)
(let ((sql-pop-to-buffer-after-send-region nil))
(call-interactively 'sql-send-string)))

(defun spacemacs/sql-send-buffer ()
"Send the buffer to SQLi and stays in the same region."
(interactive)
(let ((sql-pop-to-buffer-after-send-region nil))
(sql-send-buffer)))

(defun spacemacs/sql-send-paragraph ()
"Send the paragraph to SQLi and stays in the same region."
(interactive)
(let ((sql-pop-to-buffer-after-send-region nil))
(sql-send-paragraph)))

(defun spacemacs/sql-send-region (start end)
"Send region to SQLi and stays in the same region."
(interactive "r")
(let ((sql-pop-to-buffer-after-send-region nil))
(sql-send-region start end)))

(defun spacemacs/sql-send-line-and-next ()
"Send the current line to SQLi and stays in the same region."
(interactive)
(let ((sql-pop-to-buffer-after-send-region nil))
(sql-send-line-and-next)))

(spacemacs/declare-prefix-for-mode 'sql-mode "mb" "buffer")
(spacemacs/declare-prefix-for-mode 'sql-mode "mg" "goto")
(spacemacs/declare-prefix-for-mode 'sql-mode "mh" "dialects")
Expand Down