aboutsummaryrefslogtreecommitdiffstats
path: root/yoshi-mode-line.el
blob: f84e1a4332c2ce99e257b959d92f6994d8c0fed4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
;;; yoshi-mode-line.el --- Custom mode-line settings for Yoshi theme  -*- lexical-binding: t; -*-

;; Copyright (C) 2023  Tom Willemse

;; Author: Tom Willemse <tom@ryuslash.org>
;; Keywords:

;; 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:

;; This module defines the mode-line that is meant to be used with with the
;; ‘yoshi-theme’ theme. This module is heavily inspired by the ‘nano-modeline’
;; module from the ‘nano-emacs’ project.

;;; Code:

(defconst yoshi-mode-line-root
  (file-name-directory
   (or load-file-name
       (buffer-file-name)))
  "The directory where ‘yoshi-mode-line’ was loaded from.")

(defconst yoshi-mode-line-icons-dir
  (expand-file-name "icons" yoshi-mode-line-root)
  "The directory where ‘yoshi-mode-line’ stores its icons.")

;;; These files were all downloaded from the Font Awesome website.
(defun yoshi-mode-line-buffer-status-display ()
  "Display an icon for the status of the buffer."
  (cond
   ((derived-mode-p 'comint-mode 'eshell-mode)
    (propertize "term" 'display `(image :type svg :file ,(expand-file-name "terminal-solid.svg" yoshi-mode-line-icons-dir) :ascent center :height ,(window-default-font-height))))
   ((derived-mode-p 'wdired-mode)
    (propertize "wdired" 'display `(image :type svg :file ,(expand-file-name "folder-open-solid.svg" yoshi-mode-line-icons-dir) :ascent center :height ,(window-default-font-height))))
   ((derived-mode-p 'dired-mode)
    (propertize "dired" 'display `(image :type svg :file ,(expand-file-name "folder-solid.svg" yoshi-mode-line-icons-dir) :ascent center :height ,(window-default-font-height))))
   ((null buffer-file-name)
    (propertize "no-file" 'display `(image :type svg :file ,(expand-file-name "file-circle-minus-solid.svg" yoshi-mode-line-icons-dir) :ascent center :height ,(window-default-font-height))))
   ((buffer-modified-p)
    (propertize "modified" 'display `(image :type svg :file ,(expand-file-name "file-pen-solid.svg" yoshi-mode-line-icons-dir) :ascent center :height ,(window-default-font-height))))
   (buffer-read-only
    (propertize "read-only" 'display `(image :type svg :file ,(expand-file-name "file-shield-solid.svg" yoshi-mode-line-icons-dir) :ascent center :height ,(window-default-font-height))))
   ((derived-mode-p 'prog-mode)
    (propertize "code" 'display `(image :type svg :file ,(expand-file-name "file-code-solid.svg" yoshi-mode-line-icons-dir) :ascent center :height ,(window-default-font-height))))
   ((derived-mode-p 'text-mode)
    (propertize "text" 'display `(image :type svg :file ,(expand-file-name "file-lines-solid.svg" yoshi-mode-line-icons-dir) :ascent center :height ,(window-default-font-height))))
   (t
    (propertize "read-write" 'display `(image :type svg :file ,(expand-file-name "file-solid.svg" yoshi-mode-line-icons-dir) :ascent center :height ,(window-default-font-height))))))

(defun yoshi-mode-line-vc-display ()
  "Display information about the current version control."
  (let ((backend (vc-backend (buffer-file-name))))
    (cl-case backend
      (Git
       (concat (vc-git--symbolic-ref (buffer-file-name))
               " "
               (propertize "git" 'display `(image :type svg :file ,(expand-file-name  "git-svgrepo-com.svg" yoshi-mode-line-icons-dir) :ascent center :height ,(window-default-font-height)))))
      (t (if backend (symbol-name backend) "")))))

(setq vc-display-status nil)
(setq-default mode-line-format
              `("%e" mode-line-front-space (:eval (yoshi-mode-line-buffer-status-display)) " %z" ,@(cdr (cddadr (car (get 'mode-line-format 'standard-value))))
                mode-line-format-right-align
                mode-name " " (:eval (yoshi-mode-line-vc-display)) mode-line-front-space))

(provide 'yoshi-mode-line)
;;; yoshi-mode-line.el ends here