diff options
| author | Marcos Magueta <maguetamarcos@gmail.com> | 2025-10-25 16:41:40 -0300 |
|---|---|---|
| committer | Marcos Magueta <maguetamarcos@gmail.com> | 2025-10-25 16:41:40 -0300 |
| commit | 1cfc60020997353e5f14d632a29a4dcd4db25329 (patch) | |
| tree | f7cc9ae412e77d2ccab0b3eb0ed041f0a3382866 | |
| parent | 756c24533db8590e6ecb1bbe1f1ba36f7f38d4cf (diff) | |
| download | MageMacs-1cfc60020997353e5f14d632a29a4dcd4db25329.tar.gz MageMacs-1cfc60020997353e5f14d632a29a4dcd4db25329.zip | |
improve sql support with lsp and better secret management
Diffstat (limited to '')
| -rw-r--r-- | .gitignore | 2 | ||||
| -rw-r--r-- | behaviour.el | 1 | ||||
| -rw-r--r-- | configuration.el | 164 | ||||
| -rwxr-xr-x | init.el | 26 | ||||
| -rw-r--r-- | magemacs-sql.el | 68 | ||||
| -rw-r--r-- | theme.el | 15 |
6 files changed, 197 insertions, 79 deletions
@@ -10,4 +10,4 @@ straight/ eshell/ .lsp-session* .dap* -postgres-secrets.el
\ No newline at end of file +secrets.el diff --git a/behaviour.el b/behaviour.el index 24a5616..608eaad 100644 --- a/behaviour.el +++ b/behaviour.el @@ -12,6 +12,7 @@ (define-key emacs-lisp-mode-map (kbd "C-c C-c") 'emacs-lisp/eval-entire-expression) (global-set-key (kbd "s-e") 'eshell) (global-set-key (kbd "s-t") 'transpose-frame) +(pixel-scroll-precision-mode +1) (use-package comint :after fsharp-mode diff --git a/configuration.el b/configuration.el index 3db987b..82480b4 100644 --- a/configuration.el +++ b/configuration.el @@ -30,7 +30,7 @@ lsp-ui-sideline-diagnostic-max-lines 7 lsp-ui-sideline-diagnostic-max-line-length 40 lsp-lens-enable nil) - (defun magueta/lsp-ui-doc-toggle () + (defun magemacs/lsp-ui-doc-toggle () "For some reason it is required to do at least once a call to lsp-ui-doc-show in order for this to work. Probably the problem resides on the frame created requiring some preparation before actually being used, so `frame-live-p` doesn't return nil." (interactive) (let ((frame (lsp-ui-doc--get-frame))) @@ -39,22 +39,13 @@ (t (lsp-ui-doc-show))) (message "Hover with the mouse or call `lsp-ui-doc-show` over some obect first. For why, read doc string.")))) :bind - (("s-?" . 'magueta/lsp-ui-doc-toggle))) + (("s-?" . 'magemacs/lsp-ui-doc-toggle))) (use-package nix-mode :straight t - :init - (unless (eq system-type 'darwin) - (defun nix-repl-with-variable () - (interactive) - (let ((variables (read-string "Nix repl variable to load: "))) - (defcustom nix-repl-executable-args `("repl" ,variables) - "Arguments to provide to nix-repl." - :type '(repeat string)) - (nix-repl)))) :hook (nix-mode . lsp-deferred) - ;; (nix-repl-mode . company-mode) + (nix-repl-mode . corfu-mode) :config (add-to-list 'lsp-language-id-configuration '(nix-mode . "nix")) (lsp-register-client @@ -106,8 +97,8 @@ (corfu-mode) (unless window-system (corfu-terminal-mode)))) (sql-mode . (lambda () - (corfu-mode -1) - (unless window-system (corfu-terminal-mode -1)))) + (corfu-mode) + (unless window-system (corfu-terminal-mode)))) (corfu-mode . corfu-popupinfo-mode) (eshell-mode . corfu-mode))) @@ -145,9 +136,14 @@ :straight t :init (helm-mode t) - (set-face-attribute 'helm-selection nil - :background (color-lighten-name (face-attribute 'default :foreground) 50) - :foreground (color-darken-name (face-attribute 'default :background) 100)) + (if (seq-find (lambda (x) (or (eq 'marquardt x) + (eq 'feng-shui x))) custom-enabled-themes) + (set-face-attribute 'helm-selection nil + :background (color-lighten-name (face-attribute 'default :foreground) 50) + :foreground (color-darken-name (face-attribute 'default :background) 40)) + (set-face-attribute 'helm-selection nil + :background (color-lighten-name (face-attribute 'default :foreground) 50) + :foreground (color-darken-name (face-attribute 'default :background) 100))) :bind ("M-x" . helm-M-x) ("M-i" . helm-imenu) @@ -242,12 +238,74 @@ (lfe-mode . display-line-numbers-mode) (lfe-mode . corfu-mode) (lfe-mode . eglot-ensure) - (lfe-mode . yas-minor-mode)) + (lfe-mode . yas-minor-mode) + :init + (defvar lfe-mode-syntax-table + (let ((table (copy-syntax-table lisp-mode-syntax-table))) + ;; Like scheme we allow [ ... ] as alternate parentheses. + (modify-syntax-entry ?\[ "(] " table) + (modify-syntax-entry ?\] ")[ " table) + ;; ":" character should be used as punctuation to separate symbols + (modify-syntax-entry ?: "." table) + table) + "Syntax table in use in Lisp Flavoured Erlang mode buffers.") + (defun find-rebar-config-root () + "Find the nearest parent directory containing 'rebar.config'. +Starts from `default-directory`. Returns the path or nil if not found." + (let ((dir (file-name-as-directory default-directory))) + (catch 'found +(while dir + (if (file-exists-p (expand-file-name "rebar.config" dir)) + (throw 'found dir) + (let ((parent (file-name-directory (directory-file-name dir)))) + (if (or (null parent) (equal parent dir)) + (setq dir nil) ;; reached root +(setq dir parent))))) +nil))) + (defvar inferior-lfe-program + ;; (concat "rebar3 --config " (find-rebar-config-root) "rebar.config lfe repl") + ;; (setenv "REBAR_CONFIG" (concat (find-rebar-config-root) + ;; "rebar.config")) + ;; "rebar3 lfe repl") + ;; "rebar3 --config /home/mmagueta/Projects/Nekoma/mahjong/server/rebar.config lfe repl" + "rebar3") + (defvar inferior-lfe-program-options '("lfe" "repl")) + (defun inferior-lfe () + "Run an inferior LFE process, input and output via a buffer `*inferior-lfe*'. +Start the shell `inferior-lfe-program' `inferior-lfe-program-options' -env TERM vt100. +If a rebar project is found you are prompted (see `inferior-lfe-check-if-rebar-project') +and can choose to run lfe using rebar3." + (interactive) + (let ((prog inferior-lfe-program) + (opts inferior-lfe-program-options) + (rebar-project-root (inferior-lfe--is-rebar-project)) + (mix-project-root (inferior-lfe--is-mix-project))) + (cond + ((and inferior-lfe-check-if-rebar-project + rebar-project-root + (inferior-lfe--start-rebar-lfe)) +(setq prog "sh" + opts (list "-i" "-c" (concat "TERM=\"vt100\";" + (format "cd %s" rebar-project-root) + "; rebar3 lfe repl")))) + ((and inferior-lfe-check-if-mix-project + mix-project-root + (inferior-lfe--start-mix-lfe)) +(setq prog "sh" + opts (list "-i" "-c" (concat "TERM=\"vt100\";" + (format "cd %s" mix-project-root) + "; mix lfe repl"))))) + (unless (comint-check-proc "*inferior-lfe*") +(set-buffer (apply (function make-comint) + "inferior-lfe" prog nil opts)) +(inferior-lfe-mode)) + (setq inferior-lfe-buffer "*inferior-lfe*") + (pop-to-buffer "*inferior-lfe*")))) (with-eval-after-load 'eglot (add-to-list 'eglot-server-programs - '(lfe-mode . ("/User/mmagueta/Binary/lfe-ls/_build/prod/bin/lfe-ls" + `(lfe-mode . (,(concat (getenv "HOME") "/Binary/lfe-ls/_build/prod/bin/lfe-ls") "--transport" "tcp" "--port" :autoport)))) (use-package org-drill @@ -314,33 +372,6 @@ (when (file-exists-p secrets) (load-file secrets))) -;; (with-eval-after-load 'sql-mode -;; (progn -;; (add-to-list 'sql-connection-alist -;; '(supabase-local (sql-product 'postgres) -;; (sql-port 54322) -;; (sql-user "postgres") -;; (sql-server "localhost") -;; (sql-database "postgres"))) -;; (add-to-list 'sql-connection-alist -;; '(dev (sql-product 'postgres) -;; (sql-port 5433) -;; (sql-user "admin") -;; (sql-server "localhost") -;; (sql-database "supabase"))) -;; (add-to-list 'sql-connection-alist -;; '(supabase-prod (sql-product 'postgres) -;; (sql-port 6543) -;; (sql-user "postgres.lzrwqzryybmmzdjyrxtf") -;; (sql-server "aws-0-us-east-1.pooler.supabase.com") -;; (sql-database "postgres"))) -;; (setq lsp-sqls-workspace-config-path nil) -;; ;; (setq lsp-sqls-connections -;; ;; '(((driver . "postgresql") (dataSourceName . "host=127.0.0.1 port=54322 user=postgres password=postgres dbname=postgres sslmode=disable")))) -;; ;; (setq lsp-sqls-connections -;; ;; '(((driver . "postgresql") (dataSourceName . "host=127.0.0.1 port=5433 user=admin password=admin dbname=supabase sslmode=disable")))) -;; )) - (use-package sqlformat :straight t :ensure t @@ -378,8 +409,8 @@ :straight t :hook (emacs-lisp-mode . eros-mode)) -(use-package pgmacs - :straight (:host github :repo "MMagueta/pgmacs" :branch "add-script-support" :files ("dist" "*.el"))) +;; (use-package pgmacs + ;; :straight (:host github :repo "MMagueta/pgmacs" :branch "add-script-support" :files ("dist" "*.el"))) (use-package envrc :straight t @@ -391,5 +422,42 @@ (use-package projectile-direnv :straight t) +(use-package org-super-agenda + :straight t + :after org + :custom + (org-agenda-custom-commands + '(("c" "Super Agenda" + ((agenda "" ((org-super-agenda-groups + '((:name "Today" + :time-grid t + :date today + :todo "TODAY") + (:name "Due soon" + :deadline future) + (:name "Overdue" + :deadline past) + (:name "Important" + :priority "A"))))))))) + (org-agenda-files `(,(concat (getenv "HOME") "/.emacs.d/agenda.org"))) + :config + (org-super-agenda-mode)) + +(use-package typescript-mode + :straight t) + +(defun c-mode-compile-bind () + "Bind C-c C-c to `compile' in C mode." + (local-set-key (kbd "C-c C-c") #'compile)) + +(add-hook 'c-mode-hook #'c-mode-compile-bind) +(add-hook 'c-mode-hook #'lsp-deferred) + +(lsp-register-client + (make-lsp-client :new-connection (lsp-stdio-connection '("denon" "lsp")) + :activation-fn (lsp-activate-on "typescript") + :priority -1 + :server-id 'ts-ls)) + (provide 'configuration) ;;; configuration.el ends here @@ -21,27 +21,7 @@ (load-file "~/.emacs.d/theme.el") (load-file "~/.emacs.d/behaviour.el") (load-file "~/.emacs.d/configuration.el") +(load-file "~/.emacs.d/magemacs-sql.el") -(custom-set-variables - ;; custom-set-variables was added by Custom. - ;; If you edit it by hand, you could mess it up, so be careful. - ;; Your init file should contain only one such instance. - ;; If there is more than one, they won't work right. - '(custom-safe-themes - '("76ddb2e196c6ba8f380c23d169cf2c8f561fd2013ad54b987c516d3cabc00216" default))) -(custom-set-faces - ;; custom-set-faces was added by Custom. - ;; If you edit it by hand, you could mess it up, so be careful. - ;; Your init file should contain only one such instance. - ;; If there is more than one, they won't work right. - '(default ((t (:family "Hack" :foundry "nil" :slant normal :weight regular :height 145 :width normal)))) - '(fill-column-indicator ((t (:foreground "#CCCCCC" :weight normal)))) - '(multi-magit-repo-heading ((t (:inherit magit-section-heading :box nil)))) - '(rainbow-delimiters-depth-1-face ((t (:foreground "systemTealColor")))) - '(rainbow-delimiters-depth-2-face ((t (:foreground "Brown")))) - '(rainbow-delimiters-depth-3-face ((t (:foreground "Blue")))) - '(rainbow-delimiters-depth-4-face ((t (:foreground "Orange")))) - '(rainbow-delimiters-depth-5-face ((t (:foreground "Purple")))) - '(rainbow-delimiters-depth-6-face ((t (:foreground "dark green")))) - '(rainbow-delimiters-depth-9-face ((t (:foreground "indian red")))) - '(speedbar-selected-face ((t (:foreground "#119911" :underline t))))) +(put 'upcase-region 'disabled nil) +(put 'downcase-region 'disabled nil) diff --git a/magemacs-sql.el b/magemacs-sql.el new file mode 100644 index 0000000..e6f2a9c --- /dev/null +++ b/magemacs-sql.el @@ -0,0 +1,68 @@ +;;; magemacs-sql.el --- MageMacs SQL integration -*- lexical-binding: t; -*- + +(defun magemacs/lsp-sqls-from-connection-alist () + "Configure `lsp-sqls-connections` from `sql-connection-alist`." + (require 'lsp-sqls) + (setq lsp-sqls-connections + (mapcar + (lambda (conn) + (let* ((props (cdr conn)) + (driver "postgresql") + (server (cadr (assoc 'sql-server props))) + (port (cadr (assoc 'sql-port props))) + (user (cadr (assoc 'sql-user props))) + (db (cadr (assoc 'sql-database props)))) + `((driver . ,driver) + (dataSourceName . ,(format "host=%s port=%s user=%s dbname=%s sslmode=disable" + server port user db))))) + sql-connection-alist)) + (message "Configured lsp-sqls-connections for %d databases" + (length lsp-sqls-connections))) + +(defun magemacs/lsp-sqls-use-connection () + "Configure `lsp-sqls` to use only the `psi` connection." + (interactive) + (require 'lsp-sqls) + (let* ((connection-name (read-string "Connection name: ")) + (conn (assoc (intern connection-name) sql-connection-alist))) + (if conn + (setq-local lsp-sqls-connections + (list + (let* ((props (cdr conn)) + (driver "postgresql") + (server (cadr (assoc 'sql-server props))) + (port (cadr (assoc 'sql-port props))) + (user (cadr (assoc 'sql-user props))) + (db (cadr (assoc 'sql-database props)))) + `((driver . ,driver) + (dataSourceName . ,(format "host=%s port=%s user=%s dbname=%s sslmode=require" + server port user db)))))) + (user-error "Could not load connection '%s'" connection-name))) + (message "lsp-sqls configured to use the specified connection")) + +(defun magemacs/use-sql-connections (var) + "Replace `sql-connection-alist` with the value of VAR. +VAR should be a symbol referring to a variable that holds +an alist of SQL connection definitions." + (interactive + (list (intern + (completing-read + "Use SQL connections from variable: " + (let (vars) + (mapatoms + (lambda (sym) + (when (and (boundp sym) + (string-prefix-p "secret|" (symbol-name sym))) + (push (symbol-name sym) vars)))) + vars) + nil t)))) + (if (and (boundp var) + (listp (symbol-value var))) + (progn + (setq sql-connection-alist (symbol-value var)) + (message "sql-connection-alist replaced with value from %s" var)) + (user-error "Variable %s is not bound or not a list" var))) + +(provide 'magemacs-sql) +;;; magemacs-sql.el ends here + @@ -1,14 +1,13 @@ (require 'use-package) (use-package color-theme-modern + :after helm :straight t ;; :config (load-theme 'snowish :no-confirm)) ;; :config (load-theme 'deep-blue :no-confirm)) - :config (load-theme 'marquardt :no-confirm) - :init (if (seq-find (lambda (x) (eq 'marquardt x)) custom-enabled-themes) - (set-face-attribute 'helm-selection nil - :background (color-lighten-name (face-attribute 'default :foreground) 50) - :foreground (color-darken-name (face-attribute 'default :background) 40)))) + ;; :config (load-theme 'marquardt :no-confirm)) + ;; :config (load-theme 'resolve :no-confirm)) + :config (load-theme 'feng-shui :no-confirm)) ;; (use-package catppuccin-theme ;; :straight t @@ -49,7 +48,9 @@ ;; (setq-default cursor-type 'box) (setq-default cursor-type 'bar) -(fringe-mode '(7 . 0)) +;; (x . y) means the left and right fringes +;; put left on 7 at least for debug +(fringe-mode '(0 . 0)) (scroll-bar-mode -1) (unless (eq system-type 'darwin) (menu-bar-mode -1)) @@ -67,7 +68,7 @@ '(rainbow-delimiters-depth-4-face ((t (:foreground "dark green")))) '(rainbow-delimiters-depth-9-face ((t (:foreground "systemTealColor")))) (cond - ((eq system-type 'darwin) '(default ((t (:family "Menlo" :foundry "nil" :slant normal :weight regular :height 180 :width normal))))) + ((eq system-type 'darwin) '(default ((t (:family "Menlo" :foundry "nil" :slant normal :weight regular :height 165 :width normal))))) (t '(default ((t (:family "MesloLGS NF" :foundry "nil" :slant normal :weight regular :height 130 :width normal))))))) (provide 'theme) |
