From d5ef998239b6489ffdc450d9f543fcd1f446d844 Mon Sep 17 00:00:00 2001 From: Ryan Yin Date: Fri, 5 Jan 2024 18:37:51 +0800 Subject: [PATCH] feat: emacs - replace smartparens with parinfer feat: emacs - add emacs-rime --- Justfile | 23 +++-- .../desktop/editors/Structured-Editing.md | 4 +- home/base/desktop/editors/emacs/default.nix | 92 ++++++++++--------- .../base/desktop/editors/emacs/doom/config.el | 77 +++++++++------- home/base/desktop/editors/emacs/doom/init.el | 6 +- .../desktop/editors/emacs/doom/packages.el | 12 +-- hosts/fern/home.nix | 1 - hosts/idols/ai/home.nix | 1 - 8 files changed, 120 insertions(+), 96 deletions(-) diff --git a/Justfile b/Justfile index c3053ecc..93407be0 100644 --- a/Justfile +++ b/Justfile @@ -162,12 +162,9 @@ test-nvim: test-nvim-clean: rm -rf $"($env.HOME)/.config/astronvim/lua/user" -test-emacs: - rm -rf $"($env.HOME)/.config/doom" - rsync -avz --copy-links --chmod=D2755,F744 home/base/desktop/editors/emacs/doom/ $"($env.HOME)/.config/doom" - -test-emacs-clean: - rm -rf $"($env.HOME)/.config/doom/" +# ================================================= +# Emacs related commands +# ================================================= emacs-plist-path := "~/Library/LaunchAgents/org.nix-community.home.emacs.plist" @@ -181,5 +178,19 @@ reload-emacs-cmd := if os() == "macos" { + "systemctl --user status emacs.service" } +test-emacs: + rm -rf $"($env.HOME)/.config/doom" + rsync -avz --copy-links --chmod=D2755,F744 home/base/desktop/editors/emacs/doom/ $"($env.HOME)/.config/doom" + doom sync + doom purge + doom clean + doom sync + {{reload-emacs-cmd}} + tail -f $"($env.HOME)//Library/Logs/emacs-daemon.stderr.log" + reload-emacs: {{reload-emacs-cmd}} + +test-emacs-clean: + rm -rf $"($env.HOME)/.config/doom/" + diff --git a/home/base/desktop/editors/Structured-Editing.md b/home/base/desktop/editors/Structured-Editing.md index 0556e122..82be5238 100644 --- a/home/base/desktop/editors/Structured-Editing.md +++ b/home/base/desktop/editors/Structured-Editing.md @@ -3,7 +3,7 @@ ## S-expression data(Lisp) - paredit/[lispy](https://github.com/doomemacs/doomemacs/tree/master/modules/editor/lispy): too complex. -- [evil-smartparens](https://github.com/expez/evil-smartparens): simple and useful. +- [evil-cleverparens](https://github.com/emacs-evil/evil-cleverparens): simple and useful. - [parinfer(par-in-fer)](https://shaunlebron.github.io/parinfer/): morden, simple, elegant and useful, but works not well with some other completion plugins... - to make parinfer works, you should disable sexp & smartparens in any lisp mode. @@ -14,6 +14,8 @@ Some plugins: - Neovim - [parinfer-rust](https://github.com/eraserhd/parinfer-rust) - +- Helix + - [parinfer #4090 - Helix](https://github.com/helix-editor/helix/discussions/4090) ## Other Languages diff --git a/home/base/desktop/editors/emacs/default.nix b/home/base/desktop/editors/emacs/default.nix index 9dd5f3c5..47c1cd06 100644 --- a/home/base/desktop/editors/emacs/default.nix +++ b/home/base/desktop/editors/emacs/default.nix @@ -21,23 +21,18 @@ with lib; let shellAliases = { e = "emacsclient --create-frame --tty"; }; + librime-dir = "${config.xdg.dataHome}/librime/"; + parinfer-rust-lib-dir = "${config.xdg.dataHome}/parinfer-rust/"; in { options.modules.editors.emacs = { enable = mkEnableOption "Emacs Editor"; - doom = { - enable = mkEnableOption "Doom Emacs"; - }; }; config = mkIf cfg.enable (mkMerge [ { - home.packages = with pkgs; - let - epkgs = emacsPackages; - in - [ + home.packages = with pkgs; [ emacs-all-the-icons-fonts - # epkgs.parinfer-rust-mode + # epkgs.rime ## Doom dependencies @@ -74,46 +69,55 @@ in { force = true; }; - home.activation = mkIf cfg.doom.enable { - installDoomEmacs = lib.hm.dag.entryAfter ["writeBoundary"] '' - ${pkgs.rsync}/bin/rsync -avz --chmod=D2755,F744 ${doomemacs}/ ${config.xdg.configHome}/emacs/ - ''; - }; + home.activation.installDoomEmacs = lib.hm.dag.entryAfter ["writeBoundary"] '' + ${pkgs.rsync}/bin/rsync -avz --chmod=D2755,F744 ${doomemacs}/ ${config.xdg.configHome}/emacs/ + + # librime for emacs-rime + ${pkgs.rsync}/bin/rsync -avz --chmod=D2755,F744 ${pkgs.librime}/ ${librime-dir} + + # libparinfer_rust for emacs' parinfer-rust-mode + mkdir -p ${parinfer-rust-lib-dir} + cp ${pkgs.vimPlugins.parinfer-rust}/lib/libparinfer_rust.* ${parinfer-rust-lib-dir}/parinfer-rust.so + ''; } (mkIf pkgs.stdenv.isLinux ( - # Do not use emacs-nox here, which makes the mouse wheel work abnormally in terminal mode. - let emacsPkg = pkgs.emacs29; in - { - home.packages = [emacsPkg]; - services.emacs = { - enable = true; - package = emacsPkg; - startWithUserSession = true; - }; - })) + # Do not use emacs-nox here, which makes the mouse wheel work abnormally in terminal mode. + let + emacsPkg = pkgs.emacs29; + in { + home.packages = [emacsPkg]; + services.emacs = { + enable = true; + package = emacsPkg; + startWithUserSession = true; + }; + } + )) (mkIf pkgs.stdenv.isDarwin ( - # Do not use emacs-nox here, which makes the mouse wheel work abnormally in terminal mode. - let emacsPkg = pkgs.emacs29; in - { - home.packages = [emacsPkg]; - launchd.enable = true; - launchd.agents.emacs = { - enable = true; - config = { - ProgramArguments = [ - "${pkgs.bash}/bin/bash" - "-l" - "-c" - "${emacsPkg}/bin/emacs --fg-daemon" - ]; - StandardErrorPath = "${config.home.homeDirectory}/Library/Logs/emacs-daemon.stderr.log"; - StandardOutPath = "${config.home.homeDirectory}/Library/Logs/emacs-daemon.stdout.log"; - RunAtLoad = true; - KeepAlive = true; + # Do not use emacs-nox here, which makes the mouse wheel work abnormally in terminal mode. + let + emacsPkg = pkgs.emacs29; + in { + home.packages = [emacsPkg]; + launchd.enable = true; + launchd.agents.emacs = { + enable = true; + config = { + ProgramArguments = [ + "${pkgs.bash}/bin/bash" + "-l" + "-c" + "${emacsPkg}/bin/emacs --fg-daemon" + ]; + StandardErrorPath = "${config.home.homeDirectory}/Library/Logs/emacs-daemon.stderr.log"; + StandardOutPath = "${config.home.homeDirectory}/Library/Logs/emacs-daemon.stdout.log"; + RunAtLoad = true; + KeepAlive = true; + }; }; - }; - })) + } + )) ]); } diff --git a/home/base/desktop/editors/emacs/doom/config.el b/home/base/desktop/editors/emacs/doom/config.el index 9a2c0857..b6151cb3 100644 --- a/home/base/desktop/editors/emacs/doom/config.el +++ b/home/base/desktop/editors/emacs/doom/config.el @@ -74,28 +74,7 @@ ;; You can also try 'gd' (or 'C-c c d') to jump to their definition and see how ;; they are implemented. -;; accept completion from copilot and fallback to company -(use-package! copilot - :hook - (prog-mode . copilot-mode) - :bind - (:map copilot-completion-map - ("" . 'copilot-accept-completion) - ("TAB" . 'copilot-accept-completion) - ("C-TAB" . 'copilot-accept-completion-by-word) - ("C-" . 'copilot-accept-completion-by-word)) - :config - (copilot-mode +1)) -(use-package super-save - :ensure t - :config - (super-save-mode +1)) -(after! super-save - (setq super-save-auto-save-when-idle t) - (setq super-save-all-buffers t) - (setq super-save-delete-trailing-whitespace t)) -(use-package wakatime-mode - :ensure t) +(use-package! wakatime-mode :ensure t) ;; fully enable tree-sitter highlighting (after! tree-sitter (setq +tree-sitter-hl-enabled-modes t)) @@ -106,7 +85,7 @@ (global-font-lock-mode 0)) ;; use alejandra to format nix files -(use-package lsp-nix +(use-package! lsp-nix :ensure lsp-mode :after (lsp-mode) @@ -114,14 +93,50 @@ :custom (lsp-nix-nil-formatter ["alejandra"])) -(use-package nushell-mode +(use-package! nushell-mode :config (setq nushell-enable-auto-indent 1)) -;; https://github.com/doomemacs/doomemacs/issues/4374 -(use-package! smartparens - :init (add-hook 'smartparens-enabled-hook #'evil-smartparens-mode) - :hook ((clojure-mode . smartparens-strict-mode) - (scheme-mode . smartparens-strict-mode) - (lisp-mode . smartparens-strict-mode) - (emacs-lisp-mode . smartparens-strict-mode))) +;; emacs-rime +(use-package! rime + :custom + (default-input-method "rime") + (rime-librime-root "~/.local/share/librime")) + +;; use parinfer for lisp editing +(use-package! parinfer-rust-mode + :hook ((emacs-lisp-mode + clojure-mode + scheme-mode + lisp-mode + racket-mode + fennel-mode + hy-mode) . parinfer-rust-mode) + :init + ;; parinfer-rust library do not provide a apple silicon binary. + ;; fix: https://github.com/doomemacs/doomemacs/issues/6163 + (setq parinfer-rust-auto-download 0) + ;; we need to download it manually and put it in this path + (setq parinfer-rust-library "~/.local/share/parinfer-rust/parinfer-rust.so") + :config + (map! :map parinfer-rust-mode-map + :localleader + "p" #'parinfer-rust-switch-mode + "P" #'parinfer-rust-toggle-disable)) + +;; disable smatparens-mode here to void conflict with parinfer +;; https://discourse.doomemacs.org/t/disable-smartparens-or-parenthesis-completion/134 +(add-hook 'clojure-mode-hook #'turn-off-smartparens-mode) +(add-hook 'scheme-mode-hook #'turn-off-smartparens-mode) +(add-hook 'lisp-mode-hook #'turn-off-smartparens-mode) +(add-hook 'racket-mode-hook #'turn-off-smartparens-mode) +(add-hook 'fennel-mode-hook #'turn-off-smartparens-mode) +(add-hook 'hy-mode-hook #'turn-off-smartparens-mode) + + + + + + + + diff --git a/home/base/desktop/editors/emacs/doom/init.el b/home/base/desktop/editors/emacs/doom/init.el index 9a0f14fa..b609fb45 100644 --- a/home/base/desktop/editors/emacs/doom/init.el +++ b/home/base/desktop/editors/emacs/doom/init.el @@ -17,7 +17,7 @@ (doom! :input ;;bidi ; (tfel ot) thgir etirw uoy gnipleh - chinese ; TODO: use (chinese +rime) + chinese ;;japanese ;;layout ; auie,ctsrnm is the superior home row @@ -61,8 +61,8 @@ (format +onsave) ; automated prettiness ;; multiple-cursors ; editing in many places at once - objed ; text object editing for the innocent - ;; parinfer ; turn lisp into python, sort of + ;; objed ; text object editing for the innocent + parinfer ; turn lisp into python, sort of, conflict with copilot/objed/smartparens ;;rotate-text ; cycle region at point between text candidates snippets ; my elves. They type so I don't have to word-wrap ; soft wrapping with language-aware indent diff --git a/home/base/desktop/editors/emacs/doom/packages.el b/home/base/desktop/editors/emacs/doom/packages.el index dfc9a779..d64eb057 100644 --- a/home/base/desktop/editors/emacs/doom/packages.el +++ b/home/base/desktop/editors/emacs/doom/packages.el @@ -4,21 +4,15 @@ ;; To install a package with Doom you must declare them here and run 'doom sync' ;; on the command line, then restart Emacs for the changes to take effect -- or ;; use 'M-x doom/reload'. -(package! copilot - :recipe - (:host github :repo "copilot-emacs/copilot.el" :files - ("*.el" "dist"))) -(package! super-save - :recipe - (:host github :repo "bbatsov/super-save" :files - ("*.el" "dist"))) (package! wakatime-mode :recipe (:host github :repo "wakatime/wakatime-mode" :files ("*.el" "dist"))) + (package! nushell-mode :recipe (:host github :repo "mrkkrp/nushell-mode")) -(package! evil-smartparens) + +(package! rime) ;; To install SOME-PACKAGE from MELPA, ELPA or emacsmirror: ;; (package! some-package) diff --git a/hosts/fern/home.nix b/hosts/fern/home.nix index 8a2d6ff1..b05d9d11 100644 --- a/hosts/fern/home.nix +++ b/hosts/fern/home.nix @@ -14,6 +14,5 @@ modules.editors.emacs = { enable = true; - doom.enable = true; }; } diff --git a/hosts/idols/ai/home.nix b/hosts/idols/ai/home.nix index 6a79e66a..4865f904 100644 --- a/hosts/idols/ai/home.nix +++ b/hosts/idols/ai/home.nix @@ -15,7 +15,6 @@ }; modules.editors.emacs = { enable = true; - doom.enable = true; }; programs.ssh = {