From 868e94ef20694e583c9fad77d896ad371dc33bf6 Mon Sep 17 00:00:00 2001 From: SqrtMinusOne Date: Mon, 13 Feb 2023 18:30:33 +0300 Subject: [PATCH] feat(emacs): run lsp-ltex only when necessary --- .emacs.d/init.el | 17 ++++++++++++++++- Emacs.org | 25 +++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/.emacs.d/init.el b/.emacs.d/init.el index 4e5f1a8..10d57ca 100644 --- a/.emacs.d/init.el +++ b/.emacs.d/init.el @@ -1234,7 +1234,7 @@ influence of C1 on the result." (haskell-literate-mode . lsp) (java-mode . lsp) ;; (csharp-mode . lsp) - (text-mode . lsp)) + ) :commands lsp :init (setq lsp-keymap-prefix nil) @@ -2181,6 +2181,21 @@ Returns ( . ) or nil." '("en-US" "ru-RU" "de-DE"))) (lsp-workspace-restart (lsp--read-workspace))) +(defun my/ltex-need-p () + (let ((file-name (buffer-file-name))) + (cond + ((null file-name) nil) + ((string-match-p (rx "/home/pavel/" (+ alnum) ".org" eos) file-name) nil) + ((string-match-p (rx (literal org-directory) "/" (or "roam" "inbox-notes" "literature-notes" "journal")) file-name) t) + ((string-match-p (rx (literal org-directory)) file-name) nil) + (t t)))) + +(defun my/text-mode-lsp-maybe () + (when (my/ltex-need-p) + (lsp))) + +(add-hook 'text-mode-hook #'my/text-mode-lsp-maybe) + (use-package langtool :straight t :commands (langtool-check) diff --git a/Emacs.org b/Emacs.org index 3023871..3e70c43 100644 --- a/Emacs.org +++ b/Emacs.org @@ -1945,7 +1945,7 @@ References: (haskell-literate-mode . lsp) (java-mode . lsp) ;; (csharp-mode . lsp) - (text-mode . lsp)) + ) :commands lsp :init (setq lsp-keymap-prefix nil) @@ -2964,6 +2964,27 @@ A function to switch the current language. '("en-US" "ru-RU" "de-DE"))) (lsp-workspace-restart (lsp--read-workspace))) #+end_src + +Check whether it's necessary to run LTeX: +#+begin_src emacs-lisp +(defun my/ltex-need-p () + (let ((file-name (buffer-file-name))) + (cond + ((null file-name) nil) + ((string-match-p (rx "/home/pavel/" (+ alnum) ".org" eos) file-name) nil) + ((string-match-p (rx (literal org-directory) "/" (or "roam" "inbox-notes" "literature-notes" "journal")) file-name) t) + ((string-match-p (rx (literal org-directory)) file-name) nil) + (t t)))) +#+end_src + +To use it in =text-mode-hook= +#+begin_src emacs-lisp +(defun my/text-mode-lsp-maybe () + (when (my/ltex-need-p) + (lsp))) + +(add-hook 'text-mode-hook #'my/text-mode-lsp-maybe) +#+end_src *** LanguageTool LanguageTool is a great offline spell checker. For some reason, the download link is nowhere to be found on the home page, so it is listed in the references as well. @@ -3601,7 +3622,7 @@ Setting up =org-crypt= to encrypt parts of file. (with-eval-after-load-norem 'org (require 'org-crypt) (org-crypt-use-before-save-magic) - (setq org-tags-exclude-from-inheritance (quote ("crypt"))) + (setq org-tags-exclude-from-inheritance '("crypt")) (setq org-crypt-key "C1EC867E478472439CC82410DE004F32AFA00205")) #+end_src