;;; kkk-linenumbers.el --- Line Numbers              -*- lexical-binding: t; -*-

;; Copyright (C) 2023  Vinicius Teshima <vini.tes@pm.me>

;; Author: Vinicius Teshima <vini.tes@pm.me>

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program.  If not, see <https://www.gnu.org/licenses/>.

;;; Commentary:

;; Custom global display line number

;;; Code:
(require 'display-line-numbers)

(defgroup kkk-linenumbers nil
  "Custom config for line numbers."
  :group 'info)

(defcustom kkk-linenumbers-global-modes t
  "This is a copy of `company-global-modes` for `whitespace-mode`."
  :type '(choice (const :tag "none" nil)
		 (const :tag "all" t)
		 (set :menu-tag "mode specific" :tag "modes"
		      :value (not)
		      (const :tag "Except" not)
		      (repeat :inline t (symbol :tag "mode"))))
  :group 'kkk-linenumbers)

(defun kkk-linenumbers-mode--turn-on ()
  "Turn on `display-line-numbers-mode'."
  (when (and (not (or noninteractive (eq (aref (buffer-name) 0) ?\s)))
	     (cond ((eq kkk-linenumbers-global-modes t) t)
		   ((eq (car-safe kkk-linenumbers-global-modes) 'not)
		    (not (memq major-mode kkk-linenumbers-global-modes)))
		   (t (memq major-mode kkk-linenumbers-global-modes))))
    (display-line-numbers-mode t)))

(defvaralias 'kkk-linenumbers-type 'display-line-numbers-type)

(define-globalized-minor-mode
  global-kkk-linenumbers-mode
  display-line-numbers-mode
  kkk-linenumbers-mode--turn-on)

(provide 'kkk-linenumbers)
;;; kkk-linenumbers.el ends here
