From b06890364e869b446d1c42e94542c9cd5effadf3 Mon Sep 17 00:00:00 2001 From: Sameer Rahmani Date: Sun, 25 Jun 2023 23:00:41 +0100 Subject: [PATCH] Add a default and minimalist view --- noether-units.el | 34 ++++++++++++++++++++++++++--- noether-views.el | 56 ++++++++++++++++++++++++++++++++++++++++++++++++ noether.el | 2 +- noether.example | 3 ++- 4 files changed, 90 insertions(+), 5 deletions(-) create mode 100644 noether-views.el diff --git a/noether-units.el b/noether-units.el index 832086a..ff55eeb 100644 --- a/noether-units.el +++ b/noether-units.el @@ -141,16 +141,16 @@ Emacs knowing." (defvar noether--project "") (defun noether--set-project () - "Set the current time to the internal var which is being watched." + "Set the current project for the current buffer." (setq noether--project (projectile-project-name))) (defun noether--format-project (_ v _ _) - "Just return the current time V." + "Just return the current project V." v) (noether-defunit projectile-project-unit - "just the time for your bar." + "Show the current project name for the current buffer" :label "P:" :len 30 :init (lambda () @@ -163,6 +163,34 @@ Emacs knowing." :var 'noether--project :fn #'noether--format-project) +;; ============================================================================ +;; Git branch +;; ============================================================================ + +(defvar noether--git-branch "") + +(defun noether--set-git-branch () + "Set the branch name for the current buffer." + (setq noether--git-branch + (emacs-repository-branch-git (file-name-directory (buffer-file-name))))) + +(defun noether--format-git-branch (_ v _ _) + "Just return the branch name V}." + v) + + +(noether-defunit git-branch-unit + "Show the git branch for the current buffer." + :label "B:" + :len 40 + :init (lambda () + (add-hook 'noether-on-buffer-change-hook #'noether--set-git-branch)) + :deinit (lambda () + (remove-hook 'noether-on-buffer-change-hook #'noether--set-git-branch)) + + :var 'noether--git-branch + :fn #'noether--format-git-branch) + (provide 'noether-units) ;;; noether-units.el ends here diff --git a/noether-views.el b/noether-views.el new file mode 100644 index 0000000..5e6b797 --- /dev/null +++ b/noether-views.el @@ -0,0 +1,56 @@ +;;; noether.el --- A modeline which plays hide and seek -*- lexical-binding: t; -*- +;; +;; Copyright (c) 2023 Sameer Rahmani +;; +;; Author: Sameer Rahmani +;; URL: https://devheroes.codes/lxsameer/noether +;; Version: 0.1.0 +;; Keywords: frames, modeline +;; +;; 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 . +;; +;;; Commentary: +;;; Change Log: +;;; Code: +(require 'posframe) + +(require 'noether) +(require 'noether-units) + + +(noether-defview noether-minimal-mode-line + "A simple and minimalist mode-line like status bar" + :managed? t + :buffer "*mainview*" + :binding (kbd "C-c 1") + :separator "|" + :frame + (list + :position nil + :poshandler #'posframe-poshandler-frame-top-center + :border-width 1 + :border-color "#bd93f9") + + :units + (list + (line-unit :label "") + (buffer-name-unit :label "B: ") + (mode-name-unit :label "M: ") + (projectile-project-unit :label "P: ") + (git-branch-unit :label "Br: "))) + + + +(provide 'noether-views) +;;; noether-views.el ends here diff --git a/noether.el b/noether.el index 4a2babd..90092d9 100644 --- a/noether.el +++ b/noether.el @@ -116,7 +116,7 @@ function." BODY will be parsed in a way that any starting pair of keyword and value will be used as the view properties and the rest will be the body of the show function." - (declare (doc-string 2)) + (declare (doc-string 2) (indent defun)) (let* ((parsed-body (noether--extract-props body)) (show-body (car parsed-body)) (props (cdr parsed-body)) diff --git a/noether.example b/noether.example index 8eb8ebc..34be4de 100644 --- a/noether.example +++ b/noether.example @@ -27,6 +27,7 @@ (require 'projectile) (require 'all-the-icons) (require 'noether-units) +(require 'noether-views) ;;(debug-on-entry 'noether--update-buffer-name) (noether-defview example-bar @@ -73,7 +74,7 @@ :group 'noether) -(setq noether-views (list example-bar)) +(setq noether-views (list noether-minimal-mode-line)) (add-hook 'noether-global-mode-hook