2019-10-14 17:38:14 +02:00
|
|
|
;;; common.el --- Common settings for text files. -*- lexical-binding: t; -*-
|
|
|
|
|
2020-12-02 11:51:28 +01:00
|
|
|
;; Time-stamp: <2020-12-02T11:51:07+0100>
|
2019-10-14 17:38:14 +02:00
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
2020-03-18 15:00:17 +01:00
|
|
|
(require 'basics/package-management)
|
2019-10-14 17:38:14 +02:00
|
|
|
(require 'basics/global-variables)
|
|
|
|
|
|
|
|
(use-package emacs
|
2020-11-18 18:38:55 +01:00
|
|
|
:straight (:type built-in)
|
2020-05-24 22:59:31 +02:00
|
|
|
:demand t
|
2020-03-19 16:52:35 +01:00
|
|
|
:custom ((require-final-newline t) ; Always add newline at end of file.
|
|
|
|
(fill-column 80) ; Documents are 80 chars wide by default.
|
|
|
|
(word-wrap t)) ; Wrap at word for continuation lines.
|
2020-05-18 16:09:26 +02:00
|
|
|
:config (defun my/toggle-truncate-lines ()
|
|
|
|
"Toggle `truncate-lines'."
|
|
|
|
(interactive)
|
|
|
|
(if truncate-lines
|
|
|
|
(setq truncate-lines nil)
|
|
|
|
(setq truncate-lines t)))
|
2020-03-21 12:24:54 +01:00
|
|
|
:bind (("C-r" . jump-to-register) ; Move point to location in register.
|
2020-04-15 01:09:50 +02:00
|
|
|
("C-S-r" . point-to-register); Store location of point in register.
|
2020-03-21 12:24:54 +01:00
|
|
|
("M-W" . copy-to-register) ; Store text in register.
|
2020-04-15 01:09:50 +02:00
|
|
|
("C-S-y" . insert-register) ; Insert text from register.
|
2020-05-18 16:09:26 +02:00
|
|
|
("M-<f7>" . list-registers) ; List all registers.
|
|
|
|
("C-c t" . my/toggle-truncate-lines))
|
2020-03-21 12:24:54 +01:00
|
|
|
:hook (text-mode . auto-fill-mode)) ; Enable word-wrapping at fill-column.
|
2019-10-14 17:38:14 +02:00
|
|
|
|
2020-02-19 23:55:32 +01:00
|
|
|
;; Quickly jump to next/previous register.
|
|
|
|
(use-package register-quicknav
|
2020-03-15 23:38:06 +01:00
|
|
|
:straight (register-quicknav
|
|
|
|
:type git
|
|
|
|
:repo "https://schlomp.space/tastytea/register-quicknav.git"
|
|
|
|
:branch "main")
|
|
|
|
;; ^^^^^^^ See <https://github.com/raxod502/straight.el/issues/279>.
|
2020-03-02 06:09:40 +01:00
|
|
|
:custom (register-quicknav-buffer-only t)
|
2020-03-15 23:38:06 +01:00
|
|
|
:bind (("C-<f5>" . register-quicknav-prev-register)
|
|
|
|
("C-<f6>" . register-quicknav-next-register)
|
|
|
|
("C-<f7>" . register-quicknav-point-to-unused-register)
|
2020-03-27 17:52:59 +01:00
|
|
|
("C-S-<f7>" . register-quicknav-clear-current-register)))
|
2020-02-19 23:55:32 +01:00
|
|
|
|
2019-10-14 17:38:14 +02:00
|
|
|
;; Save cursor position.
|
|
|
|
(use-package saveplace
|
2020-05-24 22:59:31 +02:00
|
|
|
:demand t
|
2020-03-27 17:52:59 +01:00
|
|
|
:config (save-place-mode t))
|
2019-10-14 17:38:14 +02:00
|
|
|
|
|
|
|
;; Ruler with fill-column marker.
|
|
|
|
(use-package ruler-mode
|
2020-11-29 09:12:26 +01:00
|
|
|
:after (doom-themes display-line-numbers)
|
|
|
|
:demand t
|
2020-03-27 17:52:59 +01:00
|
|
|
:config (progn
|
2020-11-29 09:12:26 +01:00
|
|
|
(defun my/ruler-set-colors ()
|
|
|
|
(set-face-background 'ruler-mode-default
|
|
|
|
(face-foreground 'line-number))
|
|
|
|
(set-face-foreground 'ruler-mode-default
|
|
|
|
(face-background 'default))
|
|
|
|
(set-face-foreground 'ruler-mode-column-number
|
|
|
|
(face-background 'default))
|
|
|
|
(if (and (window-system)
|
|
|
|
(>= emacs-major-version 27))
|
|
|
|
(set-face-foreground 'ruler-mode-fill-column
|
|
|
|
(face-foreground
|
|
|
|
'fill-column-indicator nil t))
|
2020-04-17 13:52:28 +02:00
|
|
|
(set-face-foreground 'ruler-mode-fill-column
|
2020-11-29 09:12:26 +01:00
|
|
|
(face-foreground 'shadow)))
|
|
|
|
(set-face-foreground 'ruler-mode-comment-column
|
|
|
|
(face-foreground 'ruler-mode-fill-column))
|
|
|
|
(set-face-foreground 'ruler-mode-goal-column
|
|
|
|
(face-foreground 'ruler-mode-fill-column))
|
|
|
|
(set-face-foreground 'ruler-mode-current-column
|
|
|
|
(face-foreground 'line-number-current-line)))
|
|
|
|
(my/ruler-set-colors)
|
2020-05-17 19:33:54 +02:00
|
|
|
|
2020-03-27 17:52:59 +01:00
|
|
|
(defun my/ruler-on ()
|
|
|
|
"Turn `ruler-mode' on."
|
|
|
|
(ruler-mode 1)))
|
2020-04-17 03:51:57 +02:00
|
|
|
:custom-face (ruler-mode-default ((t (:inherit·default
|
|
|
|
:box·nil))))
|
2020-03-27 17:52:59 +01:00
|
|
|
:hook ((find-file . my/ruler-on)
|
2020-11-29 09:12:26 +01:00
|
|
|
(text-mode . my/ruler-on) ; For the scratch buffer.
|
|
|
|
(server-after-make-frame . my/ruler-set-colors)))
|
2019-10-14 17:38:14 +02:00
|
|
|
|
2020-03-27 17:52:59 +01:00
|
|
|
;; Show a fill-column indicator vertically across the buffer.
|
|
|
|
(when (>= emacs-major-version 27)
|
|
|
|
(use-package display-fill-column-indicator
|
|
|
|
:hook ((find-file . display-fill-column-indicator-mode)
|
|
|
|
(text-mode . display-fill-column-indicator-mode))))
|
2019-10-14 17:38:14 +02:00
|
|
|
|
2020-08-22 20:52:00 +02:00
|
|
|
;; spell checking.
|
|
|
|
(use-package ispell
|
2020-11-18 18:38:55 +01:00
|
|
|
:straight (:type built-in)
|
2020-08-22 20:55:23 +02:00
|
|
|
;; Use hunspell if possible and configure multiple dictionaries.
|
2020-08-22 20:52:00 +02:00
|
|
|
;; <https://200ok.ch/posts/2020-08-22_setting_up_spell_checking_with_multiple_dictionaries.html>
|
|
|
|
:config (when (executable-find "hunspell")
|
|
|
|
(customize-set-variable 'ispell-program-name
|
|
|
|
(executable-find "hunspell"))
|
|
|
|
;; (customize-set-variable 'ispell-dictionary "en_US,de_DE")
|
|
|
|
(ispell-set-spellchecker-params)
|
2020-08-22 20:55:23 +02:00
|
|
|
(ispell-hunspell-add-multi-dic "en_US,de_DE")
|
|
|
|
(ispell-hunspell-add-multi-dic "en_GB,de_DE")
|
|
|
|
(ispell-hunspell-add-multi-dic "de_DE,de_AT,de_CH")))
|
2020-08-22 20:52:00 +02:00
|
|
|
|
|
|
|
;; Interactive spell checking.
|
2019-10-14 17:38:14 +02:00
|
|
|
(unless slow-computer
|
|
|
|
(use-package flyspell
|
|
|
|
:if (or (executable-find "aspell")
|
|
|
|
(executable-find "hunspell")
|
|
|
|
(executable-find "ispell"))
|
2020-02-11 17:48:50 +01:00
|
|
|
:diminish flyspell-mode
|
2020-08-22 20:52:00 +02:00
|
|
|
:custom ((flyspell-default-dictionary "en_US"))
|
2020-03-27 17:52:59 +01:00
|
|
|
:config (progn
|
|
|
|
(defun my/toggle-flyspell ()
|
|
|
|
"Toggle flyspell-mode and run flyspell-buffer after activating."
|
|
|
|
(interactive)
|
|
|
|
(if (bound-and-true-p flyspell-mode)
|
|
|
|
(flyspell-mode 0)
|
|
|
|
(flyspell-mode)
|
|
|
|
(flyspell-buffer)))
|
|
|
|
|
|
|
|
(defun my/flyspell-german ()
|
|
|
|
"Set dictionary to german."
|
|
|
|
(interactive)
|
2020-08-22 20:52:00 +02:00
|
|
|
(ispell-change-dictionary "de_DE")))
|
2020-04-15 14:24:44 +02:00
|
|
|
:bind (("<f8>" . my/toggle-flyspell)
|
2020-03-27 17:52:59 +01:00
|
|
|
(:map flyspell-mode-map
|
2020-11-13 18:02:16 +01:00
|
|
|
("C-;" . nil) ; iedit needs C-;.
|
|
|
|
("C-M-i" . nil))) ; imenu-anywhere needs it.
|
2020-03-27 17:52:59 +01:00
|
|
|
:hook ((prog-mode . flyspell-prog-mode) ; Spellcheck comments.
|
|
|
|
(text-mode . flyspell-mode) ; Spellcheck text documents ↓.
|
|
|
|
(LaTeX-mode . my/flyspell-german)
|
|
|
|
(LaTeX-mode . flyspell-mode)
|
|
|
|
(adoc-mode . flyspell-mode)
|
|
|
|
(markdown-mode . flyspell-mode)
|
|
|
|
(git-commit-mode . flyspell-mode))
|
|
|
|
:mode ("COMMIT_EDITMSG\\'" . flyspell-mode))
|
2019-10-14 17:38:14 +02:00
|
|
|
) ; unless slow-computer.
|
|
|
|
|
|
|
|
;; The string Time-stamp: <> in the first 8 lines of the file will be updated
|
|
|
|
;; with the current timestamp.
|
|
|
|
(use-package time-stamp
|
2020-03-27 17:52:59 +01:00
|
|
|
:config (progn
|
|
|
|
(if (>= emacs-major-version 27)
|
|
|
|
(setq time-stamp-format "%Y-%02m-%02dT%02H:%02M:%02S%5z")
|
|
|
|
;; Set to UTC since ISO 8601 is not supported.
|
|
|
|
(setq time-stamp-format "%Y-%02m-%02dT%02H:%02M:%02S+0000")
|
|
|
|
(setq time-stamp-time-zone t)))
|
|
|
|
:hook (before-save . time-stamp))
|
2019-10-14 17:38:14 +02:00
|
|
|
|
|
|
|
;; A template system.
|
|
|
|
(use-package yasnippet
|
2019-12-23 03:52:07 +01:00
|
|
|
:after (company)
|
|
|
|
:defines (company-candidates)
|
2019-10-14 17:38:14 +02:00
|
|
|
:functions (yas-reload-all yas-expand-snippet)
|
2020-02-11 17:48:50 +01:00
|
|
|
:diminish yas-minor-mode
|
2020-03-27 17:52:59 +01:00
|
|
|
:config (progn
|
|
|
|
(defun my/tab-yas-or-company ()
|
|
|
|
"Complete with company if possible, jump to next field otherwise."
|
|
|
|
(interactive)
|
|
|
|
(if company-candidates
|
|
|
|
(company-complete-selection)
|
|
|
|
(yas-next-field)))
|
2020-08-24 01:40:30 +02:00
|
|
|
(yas-reload-all)
|
|
|
|
|
|
|
|
(defun my/string-to-var (string)
|
|
|
|
"Replace characters that usually are illegal in variable names in STRING with _."
|
|
|
|
(interactive)
|
|
|
|
(replace-regexp-in-string
|
|
|
|
"[[:space:]]" "_"
|
|
|
|
(replace-regexp-in-string "[^[:ascii:]]" "_" string))))
|
2020-03-27 17:52:59 +01:00
|
|
|
:bind (:map yas-keymap
|
|
|
|
("<tab>" . my/tab-yas-or-company)
|
|
|
|
("TAB" . my/tab-yas-or-company))
|
|
|
|
|
2020-08-24 01:40:30 +02:00
|
|
|
:hook ((prog-mode . yas-minor-mode)
|
|
|
|
(org-mode . yas-minor-mode)))
|
2019-10-14 17:38:14 +02:00
|
|
|
|
|
|
|
;; Install snippet-collection but don't use it.
|
|
|
|
(use-package yasnippet-snippets
|
2020-05-24 22:59:31 +02:00
|
|
|
:demand t
|
2020-02-12 14:34:19 +01:00
|
|
|
:after (yasnippet)
|
2020-03-27 17:52:59 +01:00
|
|
|
;; Don't add the snippets.
|
|
|
|
:config (delete 'yasnippet-snippets-dir yas-snippet-dirs))
|
2019-10-14 17:38:14 +02:00
|
|
|
|
|
|
|
;; Automatically insert text in new files.
|
|
|
|
(use-package autoinsert
|
|
|
|
:after (yasnippet)
|
2020-03-27 17:52:59 +01:00
|
|
|
:init (progn
|
|
|
|
(defun my/autoinsert-yas-expand ()
|
|
|
|
"Replace text in yasnippet template."
|
|
|
|
(yas-minor-mode t)
|
|
|
|
(yas-expand-snippet (buffer-string) (point-min) (point-max))))
|
|
|
|
:custom ((auto-insert-directory (concat user-emacs-directory "auto-insert"))
|
|
|
|
(auto-insert-query nil)) ; Don't ask before inserting.
|
|
|
|
:config (progn
|
|
|
|
(add-to-list
|
|
|
|
'auto-insert-alist '(("\\.c\\(pp\\|c\\|xx\\|\\+\\+\\)$" .
|
|
|
|
"C++ program") .
|
|
|
|
["cpp" my/autoinsert-yas-expand]))
|
|
|
|
(add-to-list
|
|
|
|
'auto-insert-alist '(("\\.h\\(pp\\|h\\|xx\\|\\+\\+\\)$" .
|
|
|
|
"C++ header") .
|
|
|
|
["hpp" my/autoinsert-yas-expand]))
|
|
|
|
(add-to-list
|
|
|
|
'auto-insert-alist '(("\\.[1-9]\\.adoc$" . "AsciiDoc manpage") .
|
|
|
|
["manpage.adoc" my/autoinsert-yas-expand]))
|
|
|
|
(add-to-list
|
|
|
|
'auto-insert-alist '(("\\.user.js$" . "Userscript") .
|
|
|
|
["user.js" my/autoinsert-yas-expand])))
|
|
|
|
:hook (find-file . auto-insert))
|
2019-10-14 17:38:14 +02:00
|
|
|
|
2019-10-14 18:02:20 +02:00
|
|
|
;; Better search.
|
|
|
|
(use-package swiper
|
|
|
|
:after (ivy)
|
|
|
|
:functions (swiper)
|
2020-03-27 17:55:12 +01:00
|
|
|
:bind ("C-s" . swiper))
|
2019-10-14 18:02:20 +02:00
|
|
|
|
2019-11-09 18:55:07 +01:00
|
|
|
;; Visualize and transform whitespace.
|
|
|
|
(use-package whitespace
|
|
|
|
:after (company)
|
2020-03-27 17:52:59 +01:00
|
|
|
:functions (my/on-off-whitespace-before-company)
|
2020-02-11 17:48:50 +01:00
|
|
|
:diminish whitespace-mode
|
2020-03-27 17:52:59 +01:00
|
|
|
:custom (whitespace-line-column nil) ; Set to fill-column.
|
|
|
|
:config (progn (delete 'newline-mark whitespace-style) ; Don't paint $ at eol.
|
|
|
|
(delete 'lines whitespace-style) ; Don't mark whole long lines.
|
|
|
|
(when (< emacs-major-version 27) ; Mark end of too long lines.
|
|
|
|
(add-to-list 'whitespace-style 'lines-tail))
|
|
|
|
|
|
|
|
;; Workaround to not show dots in popup menus.
|
|
|
|
(defvar-local my/ws-enabled nil)
|
|
|
|
(defun my/whitespace-mode-off ()
|
|
|
|
(setq-local my/ws-enabled whitespace-mode)
|
|
|
|
(when my/ws-enabled
|
|
|
|
(whitespace-mode -1)))
|
|
|
|
(defun my/whitespace-mode-on ()
|
|
|
|
(when my/ws-enabled
|
|
|
|
(whitespace-mode t)))
|
|
|
|
;; company:
|
|
|
|
(defun my/on-off-whitespace-before-company (command)
|
|
|
|
(when (string= "show" command)
|
|
|
|
(my/whitespace-mode-off))
|
|
|
|
(when (string= "hide" command)
|
2020-03-28 01:03:27 +01:00
|
|
|
(my/whitespace-mode-on)))
|
2020-03-27 17:52:59 +01:00
|
|
|
(advice-add 'company-call-frontends
|
|
|
|
:before #'my/on-off-whitespace-before-company)
|
|
|
|
;; popup:
|
|
|
|
(defadvice popup-create (before my/popup-suspend-ws activate)
|
|
|
|
"Suspend whitespace-mode while popups are visible."
|
|
|
|
(my/whitespace-mode-off))
|
|
|
|
(defadvice popup-delete (after my/popup-restore-ws activate)
|
|
|
|
"Restore whitespace-mode when all popups have closed."
|
|
|
|
(my/whitespace-mode-on))
|
|
|
|
|
|
|
|
(if (display-graphic-p)
|
|
|
|
(custom-set-faces
|
|
|
|
'(whitespace-line
|
|
|
|
((t (:inherit whitespace-line
|
|
|
|
:weight normal
|
|
|
|
:foreground nil
|
|
|
|
:background nil
|
|
|
|
:box
|
|
|
|
(:line-width 1 :color "dark red"))))))
|
|
|
|
(custom-set-faces ; else
|
|
|
|
'(whitespace-line ((t (:inherit whitespace-line
|
|
|
|
:background nil
|
|
|
|
:underline t))))))
|
|
|
|
|
|
|
|
;; Workaround for
|
|
|
|
;; <https://debbugs.gnu.org/cgi/bugreport.cgi?bug=36837>, fixed
|
|
|
|
;; in 28.1.
|
|
|
|
(defun my/ws-load-local-vars-first ()
|
|
|
|
"Loads fill-column before enabling whitespace-mode."
|
|
|
|
;; We don't use 'lines-tail in Emacs >= 27.
|
|
|
|
(when (< emacs-major-version 27)
|
|
|
|
(hack-local-variables))
|
|
|
|
(whitespace-mode))
|
|
|
|
|
|
|
|
(defun my/ws-maybe-cleanup ()
|
2020-10-27 09:50:20 +01:00
|
|
|
"Run `whitespace-cleanup' if `my/reformat-save' is t."
|
|
|
|
(when my/reformat-save
|
2020-03-27 17:52:59 +01:00
|
|
|
(whitespace-cleanup))))
|
|
|
|
:bind ("C-c w" . whitespace-mode)
|
|
|
|
:hook ((prog-mode . my/ws-load-local-vars-first)
|
|
|
|
(conf-mode . my/ws-load-local-vars-first)
|
|
|
|
(text-mode . my/ws-load-local-vars-first)
|
2020-04-17 03:51:57 +02:00
|
|
|
(before-save . my/ws-maybe-cleanup)))
|
2019-11-09 18:55:07 +01:00
|
|
|
|
2020-10-14 21:40:05 +02:00
|
|
|
;; ripgrep.
|
2020-05-05 17:47:29 +02:00
|
|
|
(use-package rg
|
|
|
|
:bind ("C-c s" . rg-menu))
|
2020-01-20 02:55:24 +01:00
|
|
|
|
2020-10-14 21:40:05 +02:00
|
|
|
;; Insert pseudo latin text.
|
|
|
|
(use-package lorem-ipsum)
|
|
|
|
|
|
|
|
;; Translate ANSI escape color codes.
|
|
|
|
(use-package ansi-color
|
|
|
|
:config (progn
|
|
|
|
(defun my/apply-ansi-colors-on-buffer ()
|
|
|
|
"Apply ANSI colors in the current buffer."
|
|
|
|
(interactive)
|
|
|
|
(let ((inhibit-read-only t))
|
|
|
|
(ansi-color-apply-on-region (point-min) (point-max))))
|
|
|
|
|
|
|
|
(defun my/apply-ansi-colors-compilation ()
|
|
|
|
"Apply ANSI colors in the compilation window."
|
|
|
|
(let ((inhibit-read-only t))
|
|
|
|
(ansi-color-apply-on-region compilation-filter-start (point)))))
|
|
|
|
:mode ("\\.log$" . my/apply-ansi-colors-on-buffer)
|
|
|
|
:hook (compilation-filter . my/apply-ansi-colors-compilation))
|
|
|
|
|
2020-10-14 21:43:27 +02:00
|
|
|
;; Colorize color names.
|
|
|
|
(use-package rainbow-mode
|
|
|
|
:demand t
|
|
|
|
:diminish rainbow-mode
|
2020-12-02 11:51:28 +01:00
|
|
|
:hook ((prog-mode . rainbow-mode)
|
|
|
|
(conf-mode . rainbow-mode)))
|
2020-10-14 21:43:27 +02:00
|
|
|
|
2020-11-13 18:02:16 +01:00
|
|
|
;; Tries to find points of interest in buffer and jumps to them.
|
|
|
|
(use-package imenu
|
|
|
|
:custom (imenu-auto-rescan t))
|
|
|
|
|
|
|
|
;; Tries to find points of interest in all open buffers and jumps to them.
|
|
|
|
(use-package imenu-anywhere
|
|
|
|
:after (imenu ivy)
|
|
|
|
:bind ("C-M-i" . ivy-imenu-anywhere))
|
|
|
|
|
2019-10-14 17:38:14 +02:00
|
|
|
(provide 'text/common)
|
|
|
|
;;; common.el ends here
|