From 11987e1f3b75fcc498d862710fe0a33e0f4dd900 Mon Sep 17 00:00:00 2001 From: materus Date: Tue, 29 Oct 2024 13:15:12 +0100 Subject: [PATCH] configurations: update emacs config --- .../profile/home/editor/emacs/default.nix | 55 ++++++++++++----- .../profile/home/editor/emacs/init.nix | 4 +- extraFiles/config/emacs/init.el | 10 +++- extraFiles/config/emacs/lsp.el | 59 +++++++++++++++++++ 4 files changed, 112 insertions(+), 16 deletions(-) create mode 100644 extraFiles/config/emacs/lsp.el diff --git a/configurations/profile/home/editor/emacs/default.nix b/configurations/profile/home/editor/emacs/default.nix index 901f25c..0f4a8c7 100644 --- a/configurations/profile/home/editor/emacs/default.nix +++ b/configurations/profile/home/editor/emacs/default.nix @@ -21,6 +21,13 @@ let projectile company clipetty + which-key + iedit + + #Evil-Mode + evil + treemacs-evil + ######### treemacs treemacs-nerd-icons @@ -47,16 +54,20 @@ let lsp-treemacs dap-mode d-mode + lua-mode multiple-cursors org org-rainbow-tags org-roam org-roam-ui org-review + csharp-mode markdown-mode json-mode nix-mode + no-littering + right-click-context moe-theme doom-themes @@ -67,18 +78,34 @@ let ${inits.initText} ''; - emacsPkgs = with pkgs; [ python3 lua multimarkdown git ]; + emacsEnv = pkgs.buildEnv { + name = "emacs-env"; + paths = with pkgs; [ + python3 + lua + multimarkdown + git + emacs-lsp-booster + llvmPackages.clang-tools + llvmPackages.clang + llvmPackages.lldb + (hiPrio gcc) + gdb + nixd + jdt-language-server + omnisharp-roslyn + ]; + }; cfg = config.materus.profile.editor.emacs; setNixInit = '' - (setenv "PATH" (concat (getenv "PATH") ":${lib.makeBinPath emacsPkgs}")) - ${builtins.concatStringsSep "\n" (builtins.map - (x: ''(setq exec-path (append exec-path '("'' + x + ''/bin")))'') - emacsPkgs)} + (setenv "PATH" (concat (getenv "PATH") ":${emacsEnv}/bin")) + (setq exec-path (append exec-path '("${emacsEnv}/bin"))) (call-process-shell-command "${pkgs.xorg.xmodmap}/bin/xmodmap -e \"keycode 148 = Hyper_L\" -e \"remove Mod4 = Hyper_L\" -e \"add Mod3 = Hyper_L\" &" nil 0) ''; -in { +in +{ options.materus.profile.editor.emacs.enable = materusArg.pkgs.lib.mkBoolOpt false "Enable emacs with materus cfg"; @@ -96,14 +123,14 @@ in { xdg.configFile."emacs/early-init.el".text = '' ${inits.earlyInitText} ''; - xdg.configFile."emacs/init.el".text ='' - (require 'recentf) - (require 'no-littering) - (add-to-list 'recentf-exclude - (recentf-expand-file-name no-littering-var-directory)) - (add-to-list 'recentf-exclude - (recentf-expand-file-name no-littering-etc-directory)) - ''; + xdg.configFile."emacs/init.el".text = '' + (require 'recentf) + (require 'no-littering) + (add-to-list 'recentf-exclude + (recentf-expand-file-name no-littering-var-directory)) + (add-to-list 'recentf-exclude + (recentf-expand-file-name no-littering-etc-directory)) + ''; programs.emacs = { enable = true; diff --git a/configurations/profile/home/editor/emacs/init.nix b/configurations/profile/home/editor/emacs/init.nix index 57393e2..d6e73b4 100644 --- a/configurations/profile/home/editor/emacs/init.nix +++ b/configurations/profile/home/editor/emacs/init.nix @@ -5,8 +5,10 @@ ${builtins.readFile (path + "early-init.el")} ''; initText = '' - (require 'doom-themes nil 'noerror) ${builtins.readFile (path + "init.el")} + ${builtins.readFile (path + "lsp.el")} + + ''; } diff --git a/extraFiles/config/emacs/init.el b/extraFiles/config/emacs/init.el index f18cd20..6c0af82 100644 --- a/extraFiles/config/emacs/init.el +++ b/extraFiles/config/emacs/init.el @@ -72,13 +72,15 @@ (setq-default cursor-type '(bar . 1)) (pixel-scroll-precision-mode 1) +(context-menu-mode 1) (setq mouse-wheel-follow-mouse 't) (setq scroll-step 1) (setq mouse-drag-and-drop-region t) (telephone-line-mode 1) (setq-default pixel-scroll-precision-large-scroll-height 10.0) (minions-mode 1) -(elcord-mode) +(unless (daemonp) + (elcord-mode 1)) ;Hide startup screen if started with file (defun startup-screen-advice (orig-fun &rest args) @@ -112,9 +114,15 @@ (cua-mode 1) (global-set-key (kbd "C-y") 'undo-redo) +(global-set-key (kbd "C-") 'indent-rigidly-right-to-tab-stop) +(global-set-key (kbd "") 'indent-rigidly-left-to-tab-stop) + (define-key key-translation-map (kbd "") 'event-apply-hyper-modifier ) (define-key key-translation-map (kbd "") 'event-apply-hyper-modifier ) +(define-key key-translation-map (kbd "∇") 'event-apply-hyper-modifier ) ;(global-set-key (kbd "C-∇") (kbd "C-H")) ;(global-set-key (kbd "H-∇") (lambda () (interactive) (insert-char #x2207))) + + diff --git a/extraFiles/config/emacs/lsp.el b/extraFiles/config/emacs/lsp.el new file mode 100644 index 0000000..c394f19 --- /dev/null +++ b/extraFiles/config/emacs/lsp.el @@ -0,0 +1,59 @@ +(defun lsp-booster--advice-json-parse (old-fn &rest args) + "Try to parse bytecode instead of json." + (or + (when (equal (following-char) ?#) + (let ((bytecode (read (current-buffer)))) + (when (byte-code-function-p bytecode) + (funcall bytecode)))) + (apply old-fn args))) +(advice-add (if (progn (require 'json) + (fboundp 'json-parse-buffer)) + 'json-parse-buffer + 'json-read) + :around + #'lsp-booster--advice-json-parse) + +(defun lsp-booster--advice-final-command (old-fn cmd &optional test?) + "Prepend emacs-lsp-booster command to lsp CMD." + (let ((orig-result (funcall old-fn cmd test?))) + (if (and (not test?) ;; for check lsp-server-present? + (not (file-remote-p default-directory)) ;; see lsp-resolve-final-command, it would add extra shell wrapper + lsp-use-plists + (not (functionp 'json-rpc-connection)) ;; native json-rpc + (executable-find "emacs-lsp-booster")) + (progn + (when-let ((command-from-exec-path (executable-find (car orig-result)))) ;; resolve command from exec-path (in case not found in $PATH) + (setcar orig-result command-from-exec-path)) + (message "Using emacs-lsp-booster for %s!" orig-result) + (cons "emacs-lsp-booster" orig-result)) + orig-result))) +(advice-add 'lsp-resolve-final-command :around #'lsp-booster--advice-final-command) + + +(require 'lsp-mode) +(require 'lsp-ui) +(require 'dap-lldb) +(require 'dap-gdb-lldb) + +(with-eval-after-load 'lsp-mode + (lsp-register-client + (make-lsp-client :new-connection (lsp-stdio-connection "nixd") + :major-modes '(nix-mode) + :priority 0 + :server-id 'nixd))) + + +;; Hooks +(add-hook 'c-mode-hook 'lsp-deferred) +(add-hook 'c-mode-hook 'display-line-numbers-mode) + +(add-hook 'c++-mode-hook 'lsp-deferred) +(add-hook 'c++-mode-hook 'display-line-numbers-mode) + + + +(add-hook 'nix-mode-hook 'lsp-deferred) +(add-hook 'nix-mode-hook 'display-line-numbers-mode) + +(add-hook 'java-mode-hook 'lsp-deferred) +(add-hook 'nix-mode-hook 'display-line-numbers-mode) \ No newline at end of file