aboutsummaryrefslogtreecommitdiffstats
path: root/yoshi-mode-line.el
blob: 840bfb9467f5c10cb78ee8fa9dd4afaa4216f85d (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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
;;; 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) "")))))

(defun yoshi-mode-line-mode-name ()
  "Display the current mode in a nice way."
  (cond
   ((derived-mode-p '(org-journal-mode))
    (propertize mode-name 'display `(image :type svg :file ,(expand-file-name "org-journal.svg" yoshi-mode-line-icons-dir) :ascent center :height ,(window-default-font-height))))
   ((derived-mode-p '(php-mode))
    (propertize mode-name 'display `(image :type svg :file ,(expand-file-name "php.svg" yoshi-mode-line-icons-dir) :ascent center :height ,(window-default-font-height))))
   ((derived-mode-p '(emacs-lisp-mode))
    (propertize mode-name 'display `(image :type svg :file ,(expand-file-name "emacs.svg" yoshi-mode-line-icons-dir) :ascent center :height ,(window-default-font-height))))
   ((derived-mode-p '(magit-mode))
    (propertize mode-name 'display `(image :type svg :file ,(expand-file-name "magit.svg" yoshi-mode-line-icons-dir) :ascent center :height ,(window-default-font-height))))
   (t
    mode-name)))

(setq vc-display-status nil)
(setq-default mode-line-buffer-identification
              (list
               (apply 'propertize " %b " (text-properties-at 0 (car mode-line-buffer-identification)))))
(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
                (:eval (yoshi-mode-line-mode-name)) " " (:eval (yoshi-mode-line-vc-display)) mode-line-front-space))
;;; Remove the major mode from the main mode line area.
(setq mode-line-modes (seq-remove-at-position mode-line-modes 3))

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