Refactore the modeline module for a cleaner code

This commit is contained in:
Sameer Rahmani 2024-04-10 20:39:35 +01:00
parent 04ae06edcb
commit 2a4333de0c
Signed by: lxsameer
GPG Key ID: 8741FACBF412FFA5
7 changed files with 186 additions and 70 deletions

View File

@ -253,16 +253,16 @@
"nixpkgs": "nixpkgs_4" "nixpkgs": "nixpkgs_4"
}, },
"locked": { "locked": {
"lastModified": 1712755154, "lastModified": 1712776989,
"narHash": "sha256-ilCQqdi203dGpAhEh6EBL5Foxo2Bxu/Vhbz+0NBNmIc=", "narHash": "sha256-DiZoTYM8FptB4DkyrzdFDMDIMECNCdYpnthjhi0NaRs=",
"ref": "refs/heads/main", "ref": "refs/heads/main",
"rev": "e6f3fd58ab283867733e940d1287923e6f0efae4", "rev": "5241f9f243cb6099a185db12552a32f70509ada6",
"revCount": 46, "revCount": 48,
"type": "git", "type": "git",
"url": "https://devheroes.codes/lxsameer/noether" "url": "https://devheroes.codes/lxsameer/noether"
}, },
"original": { "original": {
"rev": "e6f3fd58ab283867733e940d1287923e6f0efae4", "rev": "5241f9f243cb6099a185db12552a32f70509ada6",
"type": "git", "type": "git",
"url": "https://devheroes.codes/lxsameer/noether" "url": "https://devheroes.codes/lxsameer/noether"
} }

View File

@ -17,7 +17,7 @@
description = "FG42 - Emacs Editor for advance users"; description = "FG42 - Emacs Editor for advance users";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/442d407992384ed9c0e6d352de75b69079904e4e"; inputs.nixpkgs.url = "github:NixOS/nixpkgs/442d407992384ed9c0e6d352de75b69079904e4e";
inputs.noether.url = "git+https://devheroes.codes/lxsameer/noether?rev=e6f3fd58ab283867733e940d1287923e6f0efae4"; inputs.noether.url = "git+https://devheroes.codes/lxsameer/noether?rev=5241f9f243cb6099a185db12552a32f70509ada6";
inputs.emacs-overlay.url = "github:nix-community/emacs-overlay/0f7f3b39157419f3035a2dad39fbaf8a4ba0448d"; inputs.emacs-overlay.url = "github:nix-community/emacs-overlay/0f7f3b39157419f3035a2dad39fbaf8a4ba0448d";
inputs.flake-parts.url = "github:hercules-ci/flake-parts"; inputs.flake-parts.url = "github:hercules-ci/flake-parts";
@ -46,8 +46,10 @@
default = default.fg42; default = default.fg42;
} // (pkgs.lib.optionalAttrs (system == "x86_64-linux") { } // (pkgs.lib.optionalAttrs (system == "x86_64-linux") {
# Gtk causes a flickering issue on WM mode # Gtk causes a flickering issue on WM mode
wm = (factory { emacsParams.toolkit = "lucid"; }).fg42; lucid = (factory { emacsParams.toolkit = "lucid"; }).fg42;
motif = (factory { emacsParams.toolkit = "motif"; }).fg42; gtk3 = (factory { emacsParams.withGTK3 = true; }).fg42;
pgtk = (factory { emacsParams.withPgtk = true; }).fg42;
gtk2 = (factory { emacsParams.withGTK2 = true; }).fg42;
}); });
devShells.default = pkgs.mkShell { devShells.default = pkgs.mkShell {

View File

@ -42,7 +42,6 @@
(require 'server) (require 'server)
(defvar fg42/font '("Fira Mono" 12) (defvar fg42/font '("Fira Mono" 12)
"Font name and size to be used with FG42. (Default (\"Fira Mono\" 12).") "Font name and size to be used with FG42. (Default (\"Fira Mono\" 12).")

View File

@ -74,68 +74,13 @@ to Emacs modeline."
(default-value 'face-remapping-alist) face-remaps)) (default-value 'face-remapping-alist) face-remaps))
(when-not-wm (when-not-wm
(require 'noether-units) (require 'fg42/modeline/views)
(require 'nerd-icons)
(require 'projectile)
(defvar noether--mode-icon) (when-not-wm
(setq-default noether-views (list fg42/modeline))))
(defun noether--update-mode-icon ()
"Set the current buffer name to the watched var."
(setq noether--mode-icon major-mode))
(defun noether--format-mode-icon (_ v _ _)
"Format the icon V."
(nerd-icons-icon-for-mode v))
(noether-defunit mode-icon
"Draws an icon for the current major mode."
:label ""
:len 1
:init (lambda ()
(add-hook 'post-command-hook #'noether--update-mode-icon))
:deinit (lambda ()
(remove-hook 'post-command-hook #'noether--update-mode-icon))
:var 'noether--mode-icon
:fn #'noether--format-mode-icon)
(noether-defview fg42-modeline
"A simple and minimalist mode-line like status bar"
:managed? t
:binding (kbd "C-c 0")
:buffer "*modeline"
:visible? t
:timeout 0
:frame
(list
:position
(cons (- (frame-inner-width) 690)
(- (frame-outer-height) 20))
:border-width 0
:border-color "#bd93f9")
:units
(list
(buffer-name-unit :label (format "%s " (nerd-icons-codicon "nf-cod-layers"))
:len 20)
;; (mode-name-unit :label " " :len 4)
(projectile-project-unit :label (format "%s " (nerd-icons-octicon "nf-oct-project"))
:len 20)
(git-branch-unit :label (format "%s " (nerd-icons-devicon "nf-dev-git_branch"))
:len 20)
(mode-icon)
(line-unit :label "")))
(setq-default noether-views (list fg42-modeline)))
(when-wm (when-wm
(setq-default noether-views (list noether-minimal-exwm)))) (setq-default noether-views (list fg42/minimal-exwm))))
(provide 'fg42/modeline) (provide 'fg42/modeline)
;;; modeline.el ends here ;;; modeline.el ends here

View File

@ -0,0 +1,87 @@
;;; FG42 --- The mighty editor for the emacsians -*- lexical-binding: t; -*-
;;
;; Copyright (c) 2010-2024 Sameer Rahmani <lxsameer@gnu.org>
;;
;; Author: Sameer Rahmani <lxsameer@gnu.org>
;; URL: https://devheroes.codes/FG42/FG42
;; Version: 4.0.0
;;
;; 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 <http://www.gnu.org/licenses/>.
;;
;;; Commentary:
;;; Code:
(eval-when-compile
(require 'fpkg))
(require 'noether)
(require 'noether-units)
(require 'projectile)
(require 'nerd-icons)
(defvar fg42/-mode-icon)
(defun fg42/-update-mode-icon ()
"Set the current buffer name to the watched var."
(setq fg42/-mode-icon major-mode))
(defun fg42/-format-mode-icon (_ v _ _)
"Format the icon V."
(nerd-icons-icon-for-mode v))
(noether-defunit fg42/mode-icon
"Draws an icon for the current major mode."
:label ""
:len 1
:init (lambda ()
(add-hook 'post-command-hook #'fg42/-update-mode-icon))
:deinit (lambda ()
(remove-hook 'post-command-hook #'fg42/-update-mode-icon))
:var 'fg42/-mode-icon
:fn #'fg42/-format-mode-icon)
;; ============================================================================
;; Exwm input mode
;; ============================================================================
(defvar fg42/-exwm-input-mode nil)
(defun fg42/-set-exwm-input-mode ()
"Set the EXWM input mode for the current buffer."
(setq fg42/-exwm-input-mode (format "%s" exwm--input-mode)))
(defun fg42/-format-exwm-input-mode (_ v _ _)
"Just return the input mode name V."
v)
(noether-defunit fg42/exwm-input-mode-unit
"Show the input mode of EXWM for the current buffer."
:label "I:"
:len 4
:init (lambda ()
(when (featurep 'exwm)
(add-hook 'noether-on-buffer-change-hook #'fg42/-set-exwm-input-mode)))
:deinit (lambda ()
(when (featurep 'exwm)
(remove-hook 'noether-on-buffer-change-hook #'fg42/-set-exwm-input-mode)))
:var 'fg42/-exwm-input-mode
:fn #'fg42/-format-exwm-input-mode)
(provide 'fg42/modeline/units)
;;; units.el ends here

View File

@ -0,0 +1,83 @@
;;; FG42 --- The mighty editor for the emacsians -*- lexical-binding: t; -*-
;;
;; Copyright (c) 2010-2024 Sameer Rahmani <lxsameer@gnu.org>
;;
;; Author: Sameer Rahmani <lxsameer@gnu.org>
;; URL: https://devheroes.codes/FG42/FG42
;; Version: 4.0.0
;;
;; 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 <http://www.gnu.org/licenses/>.
;;
;;; Commentary:
;;; Code:
(eval-when-compile
(require 'fpkg))
(require 'fg42/modeline/units)
(noether-defview fg42/modeline
"A simple and minimalist mode-line like status bar"
:managed? t
:binding (kbd "C-c 0")
:buffer "*modeline"
:visible? t
:timeout 0
:frame
(list
:position
(cons (- (frame-inner-width) 690)
(- (frame-outer-height) 20))
:border-width 0
:border-color "#bd93f9")
:units
(list
(buffer-name-unit :label (format "%s " (nerd-icons-codicon "nf-cod-layers"))
:len 20)
;; (mode-name-unit :label " " :len 4)
(projectile-project-unit :label (format "%s " (nerd-icons-octicon "nf-oct-project"))
:len 20)
(git-branch-unit :label (format "%s " (nerd-icons-devicon "nf-dev-git_branch"))
:len 20)
(fg42/mode-icon)
(line-unit :label "")))
(when-wm
(noether-defview fg42/minimal-exwm
"A super simple bar containing the line number and column number that
Appears on the center of the current window."
:managed? t
:buffer "*exwm-status*"
:binding (kbd "C-c 3")
:separator "|"
:frame
(list
;; Such a big numbers for X and Y will cause the frame to appear on the
;; bottom right corner and covering the minibuffer
:position '(10000 . 10000)
:border-width 0
:timeout 5
:border-color "#bd93f9")
:units
(list
(fg42/exwm-input-mode-unit :label "")
(buffer-name-unit :label "")
(time-unit :label ""))))
(provide 'fg42/modeline/views)
;;; views.el ends here

View File

@ -18,9 +18,9 @@
fg42Params ? {} fg42Params ? {}
} : } :
let let
lemacs = emacs29.override { lemacs = emacs29.override ({
withTreeSitter = true; withTreeSitter = true;
} // emacsParams; } // emacsParams);
elispDepsFile = ../lisp/fg42/deps.el; elispDepsFile = ../lisp/fg42/deps.el;