Emacs: Move whitespace-mode to text/common
This commit is contained in:
parent
2a2a76fda6
commit
601c6dcdd0
|
@ -79,85 +79,5 @@
|
|||
(global-display-line-numbers-mode)
|
||||
)
|
||||
|
||||
;; Visualize whitespace.
|
||||
(use-package whitespace
|
||||
:after (company)
|
||||
:functions (my/whitespace-mode-enabled-p my/on-off-whitespace-before-company)
|
||||
|
||||
:custom
|
||||
(whitespace-line-column nil) ; Set to fill-column.
|
||||
|
||||
:config
|
||||
(delete 'newline-mark whitespace-style) ; Don't paint $ at eol.
|
||||
(delete 'lines whitespace-style) ; Don't mark whole overly long lines.
|
||||
(add-to-list 'whitespace-style 'lines-tail) ; Mark end of overly long lines.
|
||||
|
||||
;; Workaround to not show dots in popup menus.
|
||||
(defun my/whitespace-mode-enabled-p ()
|
||||
(symbol-value 'whitespace-mode))
|
||||
(defvar-local my/ws-enabled nil)
|
||||
|
||||
;; company:
|
||||
(defun my/on-off-whitespace-before-company(command)
|
||||
(when (string= "show" command)
|
||||
(setq-local my/ws-enabled (my/whitespace-mode-enabled-p))
|
||||
(if my/ws-enabled
|
||||
(whitespace-mode -1)))
|
||||
(when (string= "hide" command)
|
||||
(if my/ws-enabled
|
||||
(whitespace-mode t))))
|
||||
(advice-add 'company-call-frontends
|
||||
:before #'my/on-off-whitespace-before-company)
|
||||
|
||||
(defun my/whitespace-mode-off ()
|
||||
(setq-local my/ws-enabled (my/whitespace-mode-enabled-p))
|
||||
(if my/ws-enabled
|
||||
(whitespace-mode -1)))
|
||||
(defun my/whitespace-mode-on ()
|
||||
(if my/ws-enabled
|
||||
(whitespace-mode t)))
|
||||
|
||||
;; popup:
|
||||
(defadvice popup-create (before my/popup-suppress-whitespace-mode activate)
|
||||
"Suspend whitespace-mode while popups are visible."
|
||||
(my/whitespace-mode-off))
|
||||
(defadvice popup-delete (after my/popup-restore-whitespace-mode 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")
|
||||
;; :underline (:color "dark red")
|
||||
)))))
|
||||
(custom-set-faces ; else
|
||||
'(whitespace-line ((t (:inherit whitespace-line
|
||||
:background nil
|
||||
:underline t
|
||||
)))))
|
||||
)
|
||||
|
||||
(defun my/ws-load-local-vars-first ()
|
||||
"Loads local variables (fill-column) before enabling whitespace-mode."
|
||||
(hack-local-variables)
|
||||
(whitespace-mode)
|
||||
)
|
||||
|
||||
:bind
|
||||
("C-x 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)
|
||||
|
||||
:custom-face
|
||||
(whitespace-space ((nil :foreground "gray18")))
|
||||
)
|
||||
|
||||
(provide 'basics/appearance)
|
||||
;;; appearance.el ends here
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
;;; common.el --- Common settings for text files. -*- lexical-binding: t; -*-
|
||||
|
||||
;; Time-stamp: <2019-10-14T16:01:54+00:00>
|
||||
;; Time-stamp: <2019-11-09T12:04:11+00:00>
|
||||
|
||||
;;; Commentary:
|
||||
|
||||
|
@ -168,5 +168,86 @@
|
|||
("C-s" . 'swiper)
|
||||
)
|
||||
|
||||
;; Visualize and transform whitespace.
|
||||
(use-package whitespace
|
||||
:after (company)
|
||||
:functions (my/whitespace-mode-enabled-p my/on-off-whitespace-before-company)
|
||||
|
||||
:custom
|
||||
(whitespace-line-column nil) ; Set to fill-column.
|
||||
|
||||
:config
|
||||
(delete 'newline-mark whitespace-style) ; Don't paint $ at eol.
|
||||
(delete 'lines whitespace-style) ; Don't mark whole overly long lines.
|
||||
(add-to-list 'whitespace-style 'lines-tail) ; Mark end of overly long lines.
|
||||
|
||||
;; Workaround to not show dots in popup menus.
|
||||
(defun my/whitespace-mode-enabled-p ()
|
||||
(symbol-value 'whitespace-mode))
|
||||
(defvar-local my/ws-enabled nil)
|
||||
|
||||
;; company:
|
||||
(defun my/on-off-whitespace-before-company(command)
|
||||
(when (string= "show" command)
|
||||
(setq-local my/ws-enabled (my/whitespace-mode-enabled-p))
|
||||
(if my/ws-enabled
|
||||
(whitespace-mode -1)))
|
||||
(when (string= "hide" command)
|
||||
(if my/ws-enabled
|
||||
(whitespace-mode t))))
|
||||
(advice-add 'company-call-frontends
|
||||
:before #'my/on-off-whitespace-before-company)
|
||||
|
||||
(defun my/whitespace-mode-off ()
|
||||
(setq-local my/ws-enabled (my/whitespace-mode-enabled-p))
|
||||
(if my/ws-enabled
|
||||
(whitespace-mode -1)))
|
||||
(defun my/whitespace-mode-on ()
|
||||
(if my/ws-enabled
|
||||
(whitespace-mode t)))
|
||||
|
||||
;; popup:
|
||||
(defadvice popup-create (before my/popup-suppress-whitespace-mode activate)
|
||||
"Suspend whitespace-mode while popups are visible."
|
||||
(my/whitespace-mode-off))
|
||||
(defadvice popup-delete (after my/popup-restore-whitespace-mode 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")
|
||||
;; :underline (:color "dark red")
|
||||
)))))
|
||||
(custom-set-faces ; else
|
||||
'(whitespace-line ((t (:inherit whitespace-line
|
||||
:background nil
|
||||
:underline t
|
||||
)))))
|
||||
)
|
||||
|
||||
(defun my/ws-load-local-vars-first ()
|
||||
"Loads local variables (fill-column) before enabling whitespace-mode."
|
||||
(hack-local-variables)
|
||||
(whitespace-mode)
|
||||
)
|
||||
|
||||
:bind
|
||||
("C-x 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)
|
||||
(before-save . whitespace-cleanup)
|
||||
|
||||
:custom-face
|
||||
(whitespace-space ((nil :foreground "gray18")))
|
||||
)
|
||||
|
||||
(provide 'text/common)
|
||||
;;; common.el ends here
|
||||
|
|
Loading…
Reference in New Issue
Block a user