From 851a493dd6cf946fa8bc85acfdebdcc60c8ffa01 Mon Sep 17 00:00:00 2001 From: Joseph Ferano Date: Fri, 21 Apr 2023 21:30:28 +0700 Subject: [PATCH] Send pg function to sql interactive with C-M-x --- .config/emacs/init.org | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/.config/emacs/init.org b/.config/emacs/init.org index 7b56716..c6bf7a7 100644 --- a/.config/emacs/init.org +++ b/.config/emacs/init.org @@ -930,8 +930,7 @@ Ace Window will show a hint if there are more than 2 windows, but I don't really #+begin_src emacs-lisp :tangle no -;; TODO Prot help improving workflow. There's a bug where sometimes this doesn't work anymore -;; Is there a way to detect if the current window is a side window? +;; TODO Prot help improving workflow (global-set-key (kbd "C-`") #'window-toggle-side-windows) (defvar joe/side-window-buffers '("^\\*Flycheck errors\\*$" @@ -1022,7 +1021,18 @@ Ace Window will show a hint if there are more than 2 windows, but I don't really joe/popper-side-toggle 'below))) -;; TODO Consider adding checks for vertical splits and only popup on right if so +;; TODO Prot We need to revisit this function and change the rules; I +;; just saw that Popper uses side-window for it's internal popup at +;; the bottom function. I prefer the way Popper does it for anything +;; that is going to display horizontally at the bottom. However for +;; side splits I much prefer the functionality we have here where if +;; there's a window on the right, then overtake it and then when I +;; close it, keep whatever window was there open. The issue with +;; side-windows is that they keep the two window splits in tact and +;; that's not what I want. Sort of like how Magit does it, that's what +;; I want to copy. But like I have it here, it should respect my +;; "popper side" variable so I can toggle whether it appears at the +;; bottom or above. (defun joe/popper-display-func (buffer &optional _alist) (cond ((when-let ((popup-buffer @@ -1061,8 +1071,6 @@ Ace Window will show a hint if there are more than 2 windows, but I don't really (body-function . ,#'select-window)))))) (setq popper-display-function #'joe/popper-display-func) -;; (setq popper-display-function nil) -;; (setq popper-display-function #'popper-select-popup-at-bottom) (popper-mode t) #+end_src @@ -1890,10 +1898,28 @@ startup. Reason we have to call this is so the vterm fucntion can call `vterm--i (set-mark end))) (evil-visual-line) (evil-visual-line)) + +(defun sql-send-pg-function () + "Send the current PGSQL function to sql interactive." + (interactive) + (let ((beg (save-excursion + (re-search-backward "^create or replace function [^(]+" nil t) + (line-beginning-position))) + (end (save-excursion + (re-search-forward "\\(language\\)" nil t) + (line-end-position)))) + (save-excursion + (when (and beg end) + (goto-char beg) + (set-mark end)) + (sql-send-region beg end) + (deactivate-mark)))) + ;; This is required so that .dir-locals that read env files for credentials works (require 'dotenv) (defun joe/sql-mode-hook () (define-key sql-mode-map (kbd "C-M-h") #'joe/mark-sql-defun) + (define-key sql-mode-map (kbd "C-M-x") #'sql-send-pg-function) (define-key sql-mode-map (kbd "") #'sql-connect)) (add-hook 'sql-mode-hook #'joe/sql-mode-hook)