diff options
| author | Miquel Sabaté Solà <msabate@suse.com> | 2020-02-13 12:39:09 +0100 |
|---|---|---|
| committer | Miquel Sabaté Solà <msabate@suse.com> | 2020-02-13 12:39:09 +0100 |
| commit | b0b518badc81bac885e54939cc727be7c0dfeb47 (patch) | |
| tree | ae969681672286d9e32811e5e2d5a1b70df4a0b0 /.emacs.d | |
| parent | 01d7cc30f570e94d37f07326541f5a0d9b8473ba (diff) | |
| download | dotfiles-b0b518badc81bac885e54939cc727be7c0dfeb47.tar.gz dotfiles-b0b518badc81bac885e54939cc727be7c0dfeb47.zip | |
emacs: reworked the whole mess that was spell checking
I've added support for hunspell and languagetool. Moreover, I've redistributed
sections so things were located more logically.
Signed-off-by: Miquel Sabaté Solà <msabate@suse.com>
Diffstat (limited to '.emacs.d')
| -rw-r--r-- | .emacs.d/custom.el | 4 | ||||
| -rw-r--r-- | .emacs.d/init.org | 275 |
2 files changed, 171 insertions, 108 deletions
diff --git a/.emacs.d/custom.el b/.emacs.d/custom.el index f83bfc5..dae54af 100644 --- a/.emacs.d/custom.el +++ b/.emacs.d/custom.el @@ -7,7 +7,7 @@ ["#1c1c1c" "#d78787" "#b9dc92" "#ffffaf" "#87afd7" "#875f87" "#dfafdf" "#d0d0d0"]) '(custom-safe-themes (quote - ("44c996124982462f61fa04eeccb9e3661fbe995489eacd3b0f289e37aed29c98" "613d432fab88d34f9a4451bdbe714a31749de6c5a4d9d0bf0929399ad50f1ac6" "03f4de3e9d5df2d34dc4085ea2fe4906edf6377bf02eef7eb3430b97155c1398" "c2ea64b5a0d8042da7ff3979fc03e5cc13fc1e4bc839c5ab464f69c2dada0804" "1c79d160e207fcd2193beaf95bf25d55e15f3237f6943cc04f516e7ef600bdd7" "6a32c414a3d1a493d534a28e7814a4d6055bc607bbf45d57196cd6ee9215461b" "da9b51d7ba5c03589a7cb74f0da136cf4c9b2fdc6c58e48d78f077c8ccca39a9" "6a068d53e7b2bf41ac4a3874ea296b78c3f90cd1fd44d1769812c4c578313539" "8ebd5ccdc11c1e53647c9efc153dbcf0b00a61a519825d2698ce065913cecd35" "7e69e41a60afea0bea1e5f7a89416466db331ec45cbafe47ebec694411c997b8" "3762f105d8ea307cec0ee7cc36dcbce1ab0009ca1ae448fd07e8e8e65647431f" "75080b8936556e23444bd76fcfc042e484a50a403ccb7f36fd190c21f7bf8941" "e2669e7d32201debd97395277167b6a1d93606b9445ebce01b9f878eb980e200" "92eb47cefb2f03abaaaa52c60a0b89845361577c2201d3399d19b944828505f4" "62c1fac02f61eaad07bf39fd461f5c78ee3424ba87a1f5fe91b1bea25475f327" "62f08bc59e1ac24e6df5b5b01fea2da24f2fec201b285ccda9991b7052a3a46a" "ce1c38b72f45eed22f3dfaf7f3f0df4b0b6ed975cc5d2012fb1aad13e8055840" "e8b0224a3bd5da096120bf19c976a29cfe67af41bfe73171348bfe99ee0da62d" "ad1c0d9498ad9344082d47e3a1bb6b75f0d004e0ae8361613b0c9963b23fbb4d" "8e6f5b61626315a98a6b38acfe966800777bf6a1841aa2b812b471772cc17114" "5869e98ef7446c9e2283e5788c0f6e2790676bdb52e9e1e112bb74e2415733c4" "5a3f33eefbcf2a3098bafd22d7ad44358e66c3e844797e7bf9ef552a08dfeb6f" default))) + ("2637747c64ee19317fb896fdef24eda37f9e9c472294c965f78bcae61a338714" "44c996124982462f61fa04eeccb9e3661fbe995489eacd3b0f289e37aed29c98" "613d432fab88d34f9a4451bdbe714a31749de6c5a4d9d0bf0929399ad50f1ac6" "03f4de3e9d5df2d34dc4085ea2fe4906edf6377bf02eef7eb3430b97155c1398" "c2ea64b5a0d8042da7ff3979fc03e5cc13fc1e4bc839c5ab464f69c2dada0804" "1c79d160e207fcd2193beaf95bf25d55e15f3237f6943cc04f516e7ef600bdd7" "6a32c414a3d1a493d534a28e7814a4d6055bc607bbf45d57196cd6ee9215461b" "da9b51d7ba5c03589a7cb74f0da136cf4c9b2fdc6c58e48d78f077c8ccca39a9" "6a068d53e7b2bf41ac4a3874ea296b78c3f90cd1fd44d1769812c4c578313539" "8ebd5ccdc11c1e53647c9efc153dbcf0b00a61a519825d2698ce065913cecd35" "7e69e41a60afea0bea1e5f7a89416466db331ec45cbafe47ebec694411c997b8" "3762f105d8ea307cec0ee7cc36dcbce1ab0009ca1ae448fd07e8e8e65647431f" "75080b8936556e23444bd76fcfc042e484a50a403ccb7f36fd190c21f7bf8941" "e2669e7d32201debd97395277167b6a1d93606b9445ebce01b9f878eb980e200" "92eb47cefb2f03abaaaa52c60a0b89845361577c2201d3399d19b944828505f4" "62c1fac02f61eaad07bf39fd461f5c78ee3424ba87a1f5fe91b1bea25475f327" "62f08bc59e1ac24e6df5b5b01fea2da24f2fec201b285ccda9991b7052a3a46a" "ce1c38b72f45eed22f3dfaf7f3f0df4b0b6ed975cc5d2012fb1aad13e8055840" "e8b0224a3bd5da096120bf19c976a29cfe67af41bfe73171348bfe99ee0da62d" "ad1c0d9498ad9344082d47e3a1bb6b75f0d004e0ae8361613b0c9963b23fbb4d" "8e6f5b61626315a98a6b38acfe966800777bf6a1841aa2b812b471772cc17114" "5869e98ef7446c9e2283e5788c0f6e2790676bdb52e9e1e112bb74e2415733c4" "5a3f33eefbcf2a3098bafd22d7ad44358e66c3e844797e7bf9ef552a08dfeb6f" default))) '(delete-selection-mode nil) '(electric-indent-mode t) '(magit-commit-arguments (quote ("--all" "--verbose" "--signoff"))) @@ -15,7 +15,7 @@ '(markdown-command "/usr/bin/markdown-calibre") '(package-selected-packages (quote - (clang-format+ keycast gif-screencast py-autopep8 elpy inf-ruby move-text git-timemachine debbugs async-await request emojify auctex diminish bats-mode bool-flip salt-mode flycheck-rust rust-playground rust-mode vue-mode coffee-mode json-reformat erc-hl-nicks emoji-cheat-sheet-plus helm-circe htmlize cmake-mode websocket markdown-mode go-mode magit evil-leader evil helm projectile org-eldoc evil-commentary yasnippet yaml-mode which-key web-mode wc-mode use-package terraform-mode smart-tabs-mode slim-mode scss-mode rainbow-delimiters php-mode org-evil olivetti mu4e-alert mmm-jinja2 markdown-preview-mode helm-projectile helm-ag go-eldoc go-add-tags flycheck evil-surround evil-org evil-numbers evil-mu4e evil-magit evil-args dockerfile-mode disable-mouse default-text-scale crux cmake-font-lock ag)))) + (langtool clang-format+ keycast gif-screencast py-autopep8 elpy inf-ruby move-text git-timemachine debbugs async-await request emojify auctex diminish bats-mode bool-flip salt-mode flycheck-rust rust-playground rust-mode vue-mode coffee-mode json-reformat erc-hl-nicks emoji-cheat-sheet-plus helm-circe htmlize cmake-mode websocket markdown-mode go-mode magit evil-leader evil helm projectile org-eldoc evil-commentary yasnippet yaml-mode which-key web-mode wc-mode use-package terraform-mode smart-tabs-mode slim-mode scss-mode rainbow-delimiters php-mode org-evil olivetti mu4e-alert mmm-jinja2 markdown-preview-mode helm-projectile helm-ag go-eldoc go-add-tags flycheck evil-surround evil-org evil-numbers evil-mu4e evil-magit evil-args dockerfile-mode disable-mouse default-text-scale crux cmake-font-lock ag)))) (custom-set-faces ;; custom-set-faces was added by Custom. ;; If you edit it by hand, you could mess it up, so be careful. diff --git a/.emacs.d/init.org b/.emacs.d/init.org index a5c2c04..d07b784 100644 --- a/.emacs.d/init.org +++ b/.emacs.d/init.org @@ -238,22 +238,6 @@ Some editing tweaks like tabs vs spaces, maximum column width, etc. (show-paren-mode 1) #+END_SRC -** Abbreviations - -Basic abbreviation settings: - -#+BEGIN_SRC elisp -(setq abbrev-file-name "~/.emacs.d/abbrevs.el" - save-abbrevs 'silent) -#+END_SRC - -Automatically enable abbreviation mode for some modes: - -#+BEGIN_SRC elisp -(dolist (hook '(erc-mode-hook org-mode-hook text-mode-hook)) - (add-hook hook #'abbrev-mode)) -#+END_SRC - ** Font and theme I'm using "Droid Sans Mono" simply because I've grown used to it. @@ -412,12 +396,6 @@ Enable y/n answers (fset 'yes-or-no-p 'y-or-n-p) #+END_SRC -Let flyspell be performant. - -#+BEGIN_SRC elisp - (defvar flyspell-issue-message-flag nil) -#+END_SRC - Save custom-variables somewhere else. #+BEGIN_SRC elisp @@ -632,6 +610,7 @@ binding to @@html:<kbd>,a</kbd>@@ a function that calls to the proper function. #+END_SRC * Edit +** General In this section I define some useful packages for editing. First of all, one of the coolest packages out there is =undo-tree=. It allows you to navigate through @@ -651,27 +630,6 @@ recent versions of GNU Emacs. (diminish 'undo-tree-mode)) #+END_SRC -Another important package is =flycheck=, which is an on-the-fly syntax checking -extension. This works with lots of languages with proper glue code. - -#+BEGIN_SRC elisp -(use-package let-alist - :ensure t) - -(use-package flycheck - :ensure t - :diminish - :config - (add-hook 'after-init-hook 'global-flycheck-mode) - - ;; Only show the errors buffer if it isn't there and if I'm saving the - ;; buffer. - (setq flycheck-emacs-lisp-load-path 'inherit) - (setq flycheck-check-syntax-automatically '(mode-enabled save)) - (setq flycheck-display-errors-function - #'flycheck-display-error-messages-unless-error-list)) -#+END_SRC - A recurring issue in speeches and presentations is that when showing something with your editor, you have to increase/decrease the fonts. I use the =default-text-scale= package for this. @@ -700,51 +658,6 @@ Enable =electric-pair-mode=, which automatically closes pairs like brackets: (electric-pair-mode 1) #+END_SRC -I never use the mouse. - -#+BEGIN_SRC elisp -(use-package disable-mouse - :ensure t - :config - (global-disable-mouse-mode) - (setq global-disable-mouse-mode-lighter "")) -#+END_SRC - -Sometimes you begin typing a prefix, but then you forget the following -chord. For this reason =which-key= was created. It will show the available -commands for the current chord as a list. - -#+BEGIN_SRC elisp -(use-package which-key - :ensure t - :diminish which-key-mode - :config - (which-key-mode)) -#+END_SRC - -For some modes it is important to count the number of words in the text. For -this, we have =wc-mode=. - -#+BEGIN_SRC elisp - (use-package wc-mode - :ensure t) -#+END_SRC - -Editing files as root is a bit of a pain because usually the root user doesn't -have the same configuration as the current one, and attempting to do so can be -messy. So, instead of that, we could advice the =find-file= function so if the -file is not writable by the current user, then GNU Emacs will ask for editing -this same file as root: - -#+BEGIN_SRC elisp -(defadvice find-file (after find-file-sudo activate) - "Find file as root if necessary." - (if (and buffer-file-name - (not (file-writable-p buffer-file-name))) - (if (yes-or-no-p "Do you want to edit this file as root?") - (find-alternate-file (concat "/sudo:root@localhost:" buffer-file-name))))) -#+END_SRC - =YASnippet= allows people to define shortcuts for writing some common blocks. Moreover, it comes with a set of builtin snippets already. Since I don't remember some of these snippets, I've mapped @@html:<kbd>, h</kbd>@@ to @@ -759,14 +672,6 @@ remember some of these snippets, I've mapped @@html:<kbd>, h</kbd>@@ to (yas-global-mode 1)) #+END_SRC -=bool-flip= is a very simple utility that toggles truthy/falsey values. - -#+BEGIN_SRC elisp -(use-package bool-flip - :ensure t - :config - (global-set-key (kbd "C-c b") 'bool-flip-do-flip)) -#+END_SRC =move-text= is a small package that allows you to move lines with a keybinding. This might be feasible with Evil mode, but still this might help @@ -837,6 +742,171 @@ If this is not the case, then this function is synonimous to `end-of-line'." (advice-add 'evil-previous-line :around 'evil-previous-line--check-visual-line-mode)) #+END_SRC +** Spell checking + +Basic =flycheck= configuration: + +#+BEGIN_SRC elisp +(use-package let-alist + :ensure t) + +(use-package flycheck + :ensure t + :diminish + :config + (add-hook 'after-init-hook 'global-flycheck-mode) + + ;; Only show the errors buffer if it isn't there and if I'm saving the + ;; buffer. + (setq flycheck-emacs-lisp-load-path 'inherit) + (setq flycheck-check-syntax-automatically '(mode-enabled save)) + (setq flycheck-display-errors-function + #'flycheck-display-error-messages-unless-error-list)) +#+END_SRC + +Enable spell checking generally for any text-related mode: + +#+BEGIN_SRC elisp +(dolist (hook '(erc-mode-hook org-mode-hook text-mode-hook)) + (add-hook hook (lambda () (flyspell-mode 1)))) +#+END_SRC + +Also check the spelling of comments in programming languages: + +#+BEGIN_SRC elisp +(dolist (mode '(emacs-lisp-mode-hook + inferior-lisp-mode-hook + python-mode-hook + js-mode-hook + go-mode-hook + ruby-mode-hook + rust-mode-hook + php-mode-hook + c-mode-common-hook)) + (add-hook mode + '(lambda () + (flyspell-prog-mode)))) +#+END_SRC + +Let's use =<f8>= for checking words, and =M-<f8>= for moving into the next highlighted word: + +#+BEGIN_SRC elisp +(global-set-key (kbd "<f8>") 'ispell-word) + +(defun flyspell-check-next-highlighted-word () + "Custom function to spell check next highlighted word" + (interactive) + (flyspell-goto-next-error) + (ispell-word)) + +(global-set-key (kbd "M-<f8>") 'flyspell-check-next-highlighted-word) +#+END_SRC + +If possible, use [[https://hunspell.github.io/][hunspell]] instead of aspell. This program is used by LibreOffice, Firefox, etc. so it's pretty reliable and it supports rather complex languages such as Hungarian. The language being picked is the one from =LC_ALL= and similar environment variables. You can change that by setting =ispell-local-dictionary= and similar: + +#+BEGIN_SRC elisp +(cond + ((executable-find "hunspell") + (setq ispell-program-name "hunspell") + (setq ispell-really-hunspell t)) + + ((executable-find "aspell") + (setq ispell-program-name "aspell"))) +#+END_SRC + +Moreover, let's use [[https://github.com/languagetool-org/languagetool][languagetool]] for further checks: + +#+BEGIN_SRC elisp +(use-package langtool + :ensure t) + +(let ((lt-path "/usr/share/languagetool")) + (setq langtool-language-tool-jar (concat lt-path "/languagetool-commandline.jar") + langtool-mother-tongue "ca")) + +(when (fboundp 'langtool-check) + (global-set-key (kbd "<f9>") 'langtool-check-buffer) + (global-set-key (kbd "M-<f9>") 'langtool-correct-buffer)) +#+END_SRC + +Let flyspell be performant: + +#+BEGIN_SRC elisp +(defvar flyspell-issue-message-flag nil) +#+END_SRC + +** Abbreviations + +Basic abbreviation settings: + +#+BEGIN_SRC elisp +(setq abbrev-file-name "~/.emacs.d/abbrevs.el" + save-abbrevs 'silent) +#+END_SRC + +Automatically enable abbreviation mode for some modes: + +#+BEGIN_SRC elisp +(dolist (hook '(erc-mode-hook org-mode-hook text-mode-hook)) + (add-hook hook #'abbrev-mode)) +#+END_SRC + +** Misc + +I never use the mouse. + +#+BEGIN_SRC elisp +(use-package disable-mouse + :ensure t + :config + (global-disable-mouse-mode) + (setq global-disable-mouse-mode-lighter "")) +#+END_SRC + +Sometimes you begin typing a prefix, but then you forget the following +chord. For this reason =which-key= was created. It will show the available +commands for the current chord as a list. + +#+BEGIN_SRC elisp +(use-package which-key + :ensure t + :diminish which-key-mode + :config + (which-key-mode)) +#+END_SRC + +For some modes it is important to count the number of words in the text. For +this, we have =wc-mode=. + +#+BEGIN_SRC elisp + (use-package wc-mode + :ensure t) +#+END_SRC + +Editing files as root is a bit of a pain because usually the root user doesn't +have the same configuration as the current one, and attempting to do so can be +messy. So, instead of that, we could advice the =find-file= function so if the +file is not writable by the current user, then GNU Emacs will ask for editing +this same file as root: + +#+BEGIN_SRC elisp +(defadvice find-file (after find-file-sudo activate) + "Find file as root if necessary." + (if (and buffer-file-name + (not (file-writable-p buffer-file-name))) + (if (yes-or-no-p "Do you want to edit this file as root?") + (find-alternate-file (concat "/sudo:root@localhost:" buffer-file-name))))) +#+END_SRC + +=bool-flip= is a very simple utility that toggles truthy/falsey values. + +#+BEGIN_SRC elisp +(use-package bool-flip + :ensure t + :config + (global-set-key (kbd "C-c b") 'bool-flip-do-flip)) +#+END_SRC + * Dired I use dired mode mainly for attaching document into emails. That being said, @@ -1403,10 +1473,7 @@ Adding hooks for composing and viewing messages. (use-hard-newlines t 'guess) ; So it's easy to encrypt/decrypt emails. - (epa-mail-mode) - - ; Spellz - (flyspell-mode)) + (epa-mail-mode)) (add-hook 'mu4e-compose-mode-hook 'mssola-compose-mode) @@ -1993,12 +2060,11 @@ First of all, define a function that identifies some warning keywords #+END_SRC Text mode is not a programming language, but it's used quite often in this -context too. In this case, I want spell check and =wc-mode= activated. +context too. In this case, I want =wc-mode= activated. #+BEGIN_SRC elisp (add-hook 'text-mode-hook (lambda () - (flyspell-mode 1) (wc-mode 1))) #+END_SRC @@ -2048,13 +2114,11 @@ Add =rainbow-delimiters= and =warnings-mode-hook= also for =lisp-mode=: ** C and C++ -C and C++ only require the =warnings-mode-hook= function, spell checking for the -comments and the usage of tabs instead of spaces. +C and C++ only require the =warnings-mode-hook= function and the usage of tabs instead of spaces. #+BEGIN_SRC elisp ; Note that C-common includes languages with a similar syntax of C. (add-hook 'c-mode-common-hook 'warnings-mode-hook) -(add-hook 'c-mode-common-hook (lambda() (flyspell-prog-mode))) ;; C (add-hook 'c-mode-hook @@ -2141,7 +2205,6 @@ And now my Go configuration. This includes stuff like the usage of =goimports=, (require 'go-flycheck) (setq indent-tabs-mode t) - (flyspell-prog-mode) ; eldoc support (use-package go-eldoc |
