diff --git a/emacs/.emacs.d/.lsp-session-v1 b/emacs/.emacs.d/.lsp-session-v1 index 208e862..064b583 100644 --- a/emacs/.emacs.d/.lsp-session-v1 +++ b/emacs/.emacs.d/.lsp-session-v1 @@ -1 +1 @@ -#s(lsp-session ("/var/home/fscotto/Projects/toyforth") nil #s(hash-table test equal) #s(hash-table test equal) #s(hash-table test equal)) \ No newline at end of file +#s(lsp-session ("/var/home/fscotto/.dotfiles/emacs/.emacs.d/scripts" "/var/home/fscotto/Projects/toyforth") nil #s(hash-table test equal) #s(hash-table test equal) #s(hash-table test equal)) \ No newline at end of file diff --git a/emacs/.emacs.d/init.el b/emacs/.emacs.d/init.el index 8d427ac..1d8d248 100644 --- a/emacs/.emacs.d/init.el +++ b/emacs/.emacs.d/init.el @@ -107,6 +107,7 @@ (prefer-coding-system 'utf-8-unix) (setq custom-file (null-device)) +<<<<<<< HEAD ;;;;;;;;;;;;;;;;;;;; ;; USER FUNCTIONS ;; ;;;;;;;;;;;;;;;;;;;; @@ -156,6 +157,61 @@ (require 'magit) (call-interactively #'magit-dispatch)) +(defun fscotto/disable-c-formatting () + (setq-local lsp-enable-on-type-formatting nil)) + +||||||| parent of 4b1509a (Improved init performance and added configuration for LSP and DAP) +======= +;;;;;;;;;;;;;;;;;;;; +;; USER FUNCTIONS ;; +;;;;;;;;;;;;;;;;;;;; + +;;functions to support syncing .elfeed between machines +;;makes sure elfeed reads index from disk before launching +(defun fscotto/elfeed-load-db-and-open () + "Wrapper to load the elfeed db from disk before opening URL https://pragmaticemacs.wordpress.com/2016/08/17/read-your-rss-feeds-in-emacs-with-elfeed/ + Created: 2016-08-17 + Updated: 2025-06-13" + (interactive) + (elfeed) + (elfeed-db-load) + ;; (elfeed-search-update--force) + (elfeed-update) + (elfeed-db-save)) + +(defun fscotto/project-root () + "Return projectile project root or fallback to default-directory." + (if (featurep 'projectile) + (or (projectile-project-root) default-directory) + default-directory)) + +(defun fscotto/project-dashboard () + "Open a project dashboard: root + Magit + LSP." + (interactive) + (let ((root (fscotto/project-root))) + (dired root) + (magit-status root) + (lsp))) + +(defun fscotto/project-vterm () + "Open vterm in project root." + (interactive) + (let ((default-directory (fscotto/project-root))) + (vterm))) + +(defun fscotto/project-magit-status () + "Open magit-status in project root." + (interactive) + (let ((default-directory (fscotto/project-root))) + (magit-status))) + +(defun fscotto/magit-dispatch () + "Load Magit if necessary and open magit-dispatch." + (interactive) + (require 'magit) + (call-interactively #'magit-dispatch)) + +>>>>>>> 4b1509a (Improved init performance and added configuration for LSP and DAP) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; PACKAGES ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -189,6 +245,7 @@ ;; Help to remember or discover keybindings (use-package which-key :ensure t +<<<<<<< HEAD :defer 1 :config (which-key-mode) @@ -352,6 +409,174 @@ "+lsp" "LSP" "+debug" "Debug" "+project" "Project")) +||||||| parent of 4b1509a (Improved init performance and added configuration for LSP and DAP) + :commands (which-key-mode) + :init (which-key-mode)) +======= + :defer 1 + :config + (which-key-mode) + (setq which-key-idle-delay 0.45 + which-key-idle-secondary-delay 0.05 + which-key-max-display-columns 3 + which-key-max-description-length 45)) + +;; ============================================================================ +;; Doom-style which-key hierarchy for fscotto +;; ============================================================================ + +(with-eval-after-load 'which-key + + ;; -------------------------------------------------------------------------- + ;; Top-level prefixes + ;; -------------------------------------------------------------------------- + (which-key-add-key-based-replacements + "C-c !" "Analyze" + "C-c o" "Open" + "C-c v" "Version control" + "C-c l" "LSP" + "C-c t" "TODO / Annotations" + "C-c b" "Buffers" + "C-c p" "Project" + "C-c d" "Debug" + "C-c g" "Git" + "C-c e" "Email / Elfeed") + + ;; -------------------------------------------------------------------------- + ;; Open (C-c o …) + ;; -------------------------------------------------------------------------- + (which-key-add-key-based-replacements + "C-c o f" "RSS (Elfeed)" + "C-c o m" "mu4e (Email Client)" + "C-c o T" "Terminal (vterm)") + + ;; -------------------------------------------------------------------------- + ;; Version control + ;; -------------------------------------------------------------------------- + (which-key-add-key-based-replacements + "C-c v" "Version control" + "C-c v g" "Magit status (legacy)") + + (which-key-add-key-based-replacements + "C-c g" "Git" + + ;; Core + "C-c g g" "Status" + "C-c g s" "Status" + ;; "C-c g b" "Branch" + ;; "C-c g c" "Commit" + "C-c g p" "Push / Pull" + "C-c g f" "Fetch" + "C-c g l" "Log" + "C-c g S" "Stash" + + ;; Files + "C-c g d" "Diff" + "C-c g D" "Diff (cached)" + "C-c g B" "Blame" + + ;; Rebase / Reset + "C-c g r" "Rebase" + "C-c g R" "Reset" + + ;; Remote + "C-c g y" "Show refs" + "C-c g o" "Browse remote") + + ;; -------------------------------------------------------------------------- + ;; Buffers + ;; -------------------------------------------------------------------------- + (which-key-add-key-based-replacements + "C-x C-b" "ibuffer") + + ;; -------------------------------------------------------------------------- + ;; TODO / hl-todo + ;; -------------------------------------------------------------------------- + (which-key-add-key-based-replacements + "C-t" "hl-todo" + "C-t p" "Previous TODO" + "C-t n" "Next TODO" + "C-t o" "Occur (list)" + "C-t i" "Insert TODO") + + ;; -------------------------------------------------------------------------- + ;; LSP (C-c l …) + ;; -------------------------------------------------------------------------- + (which-key-add-key-based-replacements + "C-c l" "LSP" + "C-c l a" "Code actions" + "C-c l r" "Rename symbol" + "C-c l f" "Format buffer" + "C-c l d" "Go to definition" + "C-c l D" "Go to type definition" + "C-c l i" "Go to implementation" + "C-c l h" "Hover documentation" + "C-c l s" "Workspace symbols" + "C-c l R" "Restart server") + + ;; -------------------------------------------------------------------------- + ;; Elfeed modes + ;; -------------------------------------------------------------------------- + (which-key-add-key-based-replacements + "w" "Yank" + "R" "Update feeds" + "q" "Quit") + + ;; -------------------------------------------------------------------------- + ;; Debug / DAP + ;; -------------------------------------------------------------------------- + (which-key-add-key-based-replacements + "C-c d" "Debug" + "C-c d d" "Start debug session" + "C-c d b" "Toggle breakpoint" + "C-c d c" "Continue" + "C-c d n" "Next" + "C-c d i" "Step in" + "C-c d o" "Step out") + + ;; -------------------------------------------------------------------------- + ;; Project (future) + ;; -------------------------------------------------------------------------- + (which-key-add-key-based-replacements + "C-c p" "Project" + + ;; Core + "C-c p p" "Switch project" + "C-c p f" "Find file" + "C-c p d" "Find directory" + "C-c p b" "Switch buffer" + "C-c p k" "Kill project buffers" + "C-c p r" "Recent files" + + ;; Search + "C-c p s" "Search" + "C-c p s g" "Grep (ripgrep)" + "C-c p s r" "Replace in project" + + ;; Actions + "C-c p c" "Compile" + "C-c p t" "Test" + "C-c p v" "Open term in project" + "C-c p e" "Edit project config" + "C-c p g" "Project Git status" + "C-c p D" "Project Dashboard" + "C-c p x" "Open Terminal" + "C-c p 4" "Other Window" + "C-c p 5" "Other Frame" + "C-c p x 4" "Other Window" + + ;; Cache + "C-c p i" "Invalidate cache") + + ;; -------------------------------------------------------------------------- + ;; Cleanup annoying +prefix + ;; -------------------------------------------------------------------------- + (which-key-add-key-based-replacements + "+prefix" "Prefix" + "+lsp" "LSP" + "+debug" "Debug" + "+project" "Project")) +>>>>>>> 4b1509a (Improved init performance and added configuration for LSP and DAP) ;; Configuration for mu4e, an interface for mu email index, running inside Emacs (use-package mu4e @@ -537,6 +762,7 @@ (lambda () (ibuffer-projectile-set-filter-groups))) +<<<<<<< HEAD ;; ============================================================================ ;; Projectile - Project management ;; ============================================================================ @@ -572,6 +798,45 @@ (define-key projectile-command-map (kbd "g") #'fscotto/project-magit-status)) (global-set-key (kbd "C-c p D") #'fscotto/project-dashboard) +||||||| parent of 4b1509a (Improved init performance and added configuration for LSP and DAP) +;; TODO adding lsp-mode, dap-mode, autocomplete and project handling for C, Go, Bash and Python +======= +;; ============================================================================ +;; Projectile - Project management (Doom-style) +;; ============================================================================ + +(use-package projectile + :ensure t + :defer 1 + :init + ;; Root detection + (setq projectile-project-search-path '("~/Projects" "~/Work")) + (setq projectile-completion-system 'ivy) + :config + ;; Performance + (setq projectile-enable-caching t) + (setq projectile-indexing-method 'hybrid) + (setq projectile-sort-order 'recently-active) + ;; Projectile as single source of truth + (setq projectile-switch-project-action #'projectile-dired) + ;; Use ripgrep if available + (when (executable-find "rg") + (setq projectile-generic-command "rg --files --hidden --glob '!.git'")) + ;; Enable globally + (projectile-mode 1)) + +;; Projectile keybindings (Doom-style) +(with-eval-after-load 'projectile + (define-key projectile-mode-map (kbd "C-c p") 'projectile-command-map)) + +(with-eval-after-load 'projectile + (define-key projectile-command-map (kbd "v") #'fscotto/project-vterm)) + +(with-eval-after-load 'projectile + (define-key projectile-command-map (kbd "g") #'fscotto/project-magit-status)) + +(global-set-key (kbd "C-c p D") #'fscotto/project-dashboard) +>>>>>>> 4b1509a (Improved init performance and added configuration for LSP and DAP) ;; Add autocomplete feature to Emacs (use-package company @@ -582,16 +847,46 @@ (company-idle-delay 0.1) :hook (prog-mode . company-mode)) +(with-eval-after-load 'company + (add-hook 'bash-ts-mode-hook 'company-mode)) + ;; Static analysis for code base (use-package flycheck :ensure t +<<<<<<< HEAD + :hook (prog-mode . flycheck-mode)) + +(with-eval-after-load 'flycheck + (add-hook 'bash-ts-mode-hook 'flycheck-mode)) + +(use-package treesit + :ensure nil +||||||| parent of 4b1509a (Improved init performance and added configuration for LSP and DAP) +======= :hook (prog-mode . flycheck-mode)) (use-package treesit :ensure nil +>>>>>>> 4b1509a (Improved init performance and added configuration for LSP and DAP) :config +<<<<<<< HEAD (setq treesit-font-lock-level 4) (setq treesit-auto-install 'prompt) + (setq major-mode-remap-alist + '((c-mode . c-ts-mode) + (c++-mode . c++-ts-mode) + (python-mode . python-ts-mode) + (sh-mode . bash-ts-mode))) + (setq treesit-language-source-alist + '((c "https://github.com/tree-sitter/tree-sitter-c") + (cpp "https://github.com/tree-sitter/tree-sitter-cpp") + (python "https://github.com/tree-sitter/tree-sitter-python") + (bash "https://github.com/tree-sitter/tree-sitter-bash") + (go "https://github.com/tree-sitter/tree-sitter-go")))) +||||||| parent of 4b1509a (Improved init performance and added configuration for LSP and DAP) + (add-hook 'after-init-hook #'global-flycheck-mode)) +======= + (setq treesit-font-lock-level 4) (setq major-mode-remap-alist '((c-mode . c-ts-mode) (c++-mode . c++-ts-mode) @@ -603,13 +898,20 @@ (python "https://github.com/tree-sitter/tree-sitter-python") (bash "https://github.com/tree-sitter/tree-sitter-bash") (go "https://github.com/tree-sitter/tree-sitter-go")))) +>>>>>>> 4b1509a (Improved init performance and added configuration for LSP and DAP) (use-package lsp-mode :ensure t +<<<<<<< HEAD :commands (lsp lsp-deferred) +||||||| parent of 4b1509a (Improved init performance and added configuration for LSP and DAP) +======= + :commands lsp +>>>>>>> 4b1509a (Improved init performance and added configuration for LSP and DAP) :init ;; set prefix for lsp-command-keymap (few alternatives - "C-l", "C-c l") (setq lsp-keymap-prefix "C-c l") +<<<<<<< HEAD :hook ((c-mode c-ts-mode @@ -619,7 +921,7 @@ python-ts-mode go-mode go-ts-mode - bash-mode + sh-mode bash-ts-mode) . lsp-deferred) :config ;; Performance @@ -649,8 +951,33 @@ "--ranking-model=heuristics" "--malloc-trim" "--limit-results=500" - "--limit-references=2000")) - ) + "--limit-references=2000"))) +||||||| parent of 4b1509a (Improved init performance and added configuration for LSP and DAP) + :hook ((c-mode . lsp)) + :commands lsp) +======= + :hook + ((c-mode + c-ts-mode + c++-mode + c++-ts-mode + python-mode + python-ts-mode + go-mode + go-ts-mode + bash-mode + bash-ts-mode) . lsp) + :config + ;; Performance + (setq lsp-enable-symbol-highlighting t + lsp-enable-snippet t + lsp-log-io nil + lsp-completion-provider :capf + ;; Disable for huge projects + ;; lsp-enable-file-watchers nil + lsp-headerline-breadcrumb-enable nil + lsp-idle-delay 0.5)) +>>>>>>> 4b1509a (Improved init performance and added configuration for LSP and DAP) (use-package lsp-ui :ensure t @@ -668,6 +995,9 @@ consult-lsp-diagnostics)) (with-eval-after-load 'lsp-mode + ;; Attach bash-language-server when open a shell scripts + (add-hook 'sh-mode-hook #'lsp) + ;; Symbols (global-set-key (kbd "C-c l s") #'consult-lsp-symbols) @@ -703,11 +1033,57 @@ (dap-ui-mode 1) (dap-tooltip-mode 1) +<<<<<<< HEAD ;; Auto show breakpoints + REPL (setq dap-ui-buffer-configurations '((dap-ui-repl . ((side . right) (slot . 1) (window-width . 0.33))) (dap-ui-locals . ((side . right) (slot . 2) (window-width . 0.33))) (dap-ui-breakpoints . ((side . left) (slot . 1) (window-width . 0.20)))))) +||||||| parent of 4b1509a (Improved init performance and added configuration for LSP and DAP) +;;functions to support syncing .elfeed between machines +;;makes sure elfeed reads index from disk before launching +(defun fscotto/elfeed-load-db-and-open () + "Wrapper to load the elfeed db from disk before opening URL https://pragmaticemacs.wordpress.com/2016/08/17/read-your-rss-feeds-in-emacs-with-elfeed/ + Created: 2016-08-17 + Updated: 2025-06-13" + (interactive) + (elfeed) + (elfeed-db-load) + ;; (elfeed-search-update--force) + (elfeed-update) + (elfeed-db-save)) +======= + ;; Auto show breakpoints + REPL + (setq dap-ui-buffer-configurations + '((dap-ui-repl . ((side . right) (slot . 1) (window-width . 0.33))) + (dap-ui-locals . ((side . right) (slot . 2) (window-width . 0.33))) + (dap-ui-breakpoints . ((side . left) (slot . 1) (window-width . 0.20)))))) + +;;;;;;;;;;;;;;;;;;;;;; +;; Enable debuggers ;; +;;;;;;;;;;;;;;;;;;;;;; + +;; For C/C++ +(require 'dap-gdb-lldb) +(setq dap-gdb-lldb-debug-program '("gdb")) + +;; For Go +(require 'dap-go) + +;; For Python +(require 'dap-python) +(setq dap-python-debugger 'debugpy) + +(with-eval-after-load 'dap-mode + (global-set-key (kbd "C-c d d") #'dap-debug) + (global-set-key (kbd "C-c d b") #'dap-breakpoint-toggle) + (global-set-key (kbd "C-c d c") #'dap-continue) + (global-set-key (kbd "C-c d n") #'dap-next) + (global-set-key (kbd "C-c d i") #'dap-step-in) + (global-set-key (kbd "C-c d o") #'dap-step-out) + (global-set-key (kbd "C-c d r") #'dap-restart-frame) + (global-set-key (kbd "C-c d q") #'dap-disconnect)) +>>>>>>> 4b1509a (Improved init performance and added configuration for LSP and DAP) ;; For C/C++ (require 'dap-gdb-lldb) @@ -730,4 +1106,20 @@ (global-set-key (kbd "C-c d r") #'dap-restart-frame) (global-set-key (kbd "C-c d q") #'dap-disconnect)) +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;;;;;;;;;;;;;; Formatters ;;;;;;;;;;;;;;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +;; GOTCHA review this region +(use-package reformatter + :ensure t + :config + (reformatter-define shfmt-format + :program "shfmt" + :args '("-i" "2" "-ci"))) + +(add-hook 'bash-ts-mode-hook #'shfmt-format-on-save-mode) +(add-hook 'c-ts-mode-hook #'fscotto/disable-c-formatting) +(add-hook 'c-mode-hook #'fscotto/disable-c-formatting) + (message "...user configuration loaded")