kkk-whitespace.el 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. ;;; kkk-whitespace.el --- Custom Whitespace Mode -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2023 Vinicius Teshima <vini.tes@pm.me>
  3. ;; Author: Vinicius Teshima <vini.tes@pm.me>
  4. ;; This program is free software; you can redistribute it and/or modify
  5. ;; it under the terms of the GNU General Public License as published by
  6. ;; the Free Software Foundation, either version 3 of the License, or
  7. ;; (at your option) any later version.
  8. ;; This program is distributed in the hope that it will be useful,
  9. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. ;; GNU General Public License for more details.
  12. ;; You should have received a copy of the GNU General Public License
  13. ;; along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. ;;; Commentary:
  15. ;; Adding custom global mode for whitespace mode
  16. ;;; Code:
  17. (defgroup kkk-whitespace nil
  18. "Custom config for whitespace."
  19. :group 'info)
  20. (defcustom kkk-whitespace-global-modes t
  21. "This is a copy of `company-global-modes` for `whitespace-mode`."
  22. :type '(choice (const :tag "none" nil)
  23. (const :tag "all" t)
  24. (set :menu-tag "mode specific" :tag "modes"
  25. :value (not)
  26. (const :tag "Except" not)
  27. (repeat :inline t (symbol :tag "mode"))))
  28. :group 'kkk-whitespace)
  29. (defun kkk-whitespace-mode--turn-on ()
  30. "Turn on `whitespace-mode` on the current buffer.
  31. Using `whitespace-global-modes` as a filter."
  32. (when (and (not (or noninteractive (eq (aref (buffer-name) 0) ?\s)))
  33. (cond ((eq kkk-whitespace-global-modes t) t)
  34. ((eq (car-safe kkk-whitespace-global-modes) 'not)
  35. (not (memq major-mode kkk-whitespace-global-modes)))
  36. (t (memq major-mode kkk-whitespace-global-modes))))
  37. (whitespace-mode t)))
  38. (define-globalized-minor-mode
  39. global-kkk-whitespace-mode
  40. whitespace-mode
  41. kkk-whitespace-mode--turn-on)
  42. (provide 'kkk-whitespace)
  43. ;;; kkk-whitespace.el ends here