diff options
Diffstat (limited to '')
| -rw-r--r-- | config/emacs/modeline/simple-modeline-core.el | 102 | ||||
| -rw-r--r-- | config/emacs/modeline/simple-modeline-segments.el | 92 | ||||
| -rw-r--r-- | config/emacs/modeline/simple-modeline.el | 73 | 
3 files changed, 267 insertions, 0 deletions
diff --git a/config/emacs/modeline/simple-modeline-core.el b/config/emacs/modeline/simple-modeline-core.el new file mode 100644 index 0000000..03df894 --- /dev/null +++ b/config/emacs/modeline/simple-modeline-core.el @@ -0,0 +1,102 @@ +;;; simple-modeline-core.el --- The core libraries for simple-modeline -*- lexical-binding: t; -*- + +;; Copyright (C) 2019-2021  Eder Elorriaga + +;; 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: + +;; The core libraries for simple-modeline. + +;;; Code: + +(defgroup simple-modeline nil +  "A simple mode line." +  :prefix "simple-modeline-" +  :group 'mode-line) + +(defvar simple-modeline--default-mode-line mode-line-format +  "The former value of `mode-line-format'.") + +;; +;; Options +;; + +(defcustom simple-modeline-segments +  '((simple-modeline-segment-modified +     simple-modeline-segment-buffer-name) +    (simple-modeline-segment-vc +     simple-modeline-segment-major-mode)) +  "Simple modeline segments." +  :type '(list (repeat :tag "Left aligned" function) +               (repeat :tag "Right aligned" function)) +  :package-version '(simple-modeline . "1.2")) + +;; +;; Faces +;; + +(defface simple-modeline-space +  '((t)) +  "Face for space used to alight the right segments in the mode-line.") + +(defface simple-modeline-unimportant +  '((t (:inherit (shadow)))) +  "Face for less important mode-line elements.") + +(defface simple-modeline-status-modified +  '((t (:inherit (font-lock-variable-name-face)))) +  "Face for the 'modified' indicator symbol in the mode-line.") + +(defface simple-modeline-status-info +  '((t (:inherit (font-lock-string-face)))) +  "Face for generic status indicators in the mode-line.") + +(defface simple-modeline-status-success +  '((t (:inherit (success)))) +  "Face used for success status indicators in the mode-line.") + +(defface simple-modeline-status-warning +  '((t (:inherit (warning)))) +  "Face for warning status indicators in the mode-line.") + +(defface simple-modeline-status-error +  '((t (:inherit (error)))) +  "Face for error status indicators in the mode-line.") + +;; +;; Helpers +;; + +(defun simple-modeline--format (left-segments right-segments) +  "Return a string of `window-width' length containing LEFT-SEGMENTS and RIGHT-SEGMENTS, aligned respectively." +  (let* ((left (simple-modeline--format-segments left-segments)) +         (right (simple-modeline--format-segments right-segments)) +         (reserve (length right))) +    (concat +     left +     (propertize " " +                 'display `((space :align-to (- right ,reserve))) +                 'face '(:inherit simple-modeline-space)) +     right))) + +(defun simple-modeline--format-segments (segments) +  "Return a string from a list of SEGMENTS." +  (format-mode-line (mapcar +                     (lambda (segment) +                       `(:eval (,segment))) +                     segments))) + +(provide 'simple-modeline-core) +;;; simple-modeline-core.el ends here diff --git a/config/emacs/modeline/simple-modeline-segments.el b/config/emacs/modeline/simple-modeline-segments.el new file mode 100644 index 0000000..9a5c2e5 --- /dev/null +++ b/config/emacs/modeline/simple-modeline-segments.el @@ -0,0 +1,92 @@ +;;; simple-modeline-segments.el --- The segments for simple-modeline -*- lexical-binding: t; -*- + +;; Copyright (C) 2019-2021  Eder Elorriaga + +;; 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: + +;; The segments for simple-modeline + +;;; Code: + +(require 'subr-x) + +(defun simple-modeline-make-mouse-map (mouse function) +  "Return a keymap with single entry for mouse key MOUSE on the mode line. +MOUSE is defined to run function FUNCTION with no args in the buffer +corresponding to the mode line clicked." +  (let ((map (make-sparse-keymap))) +    (define-key map (vector 'mode-line mouse) function) +    map)) + +(defun simple-modeline-segment-modified () +  "Displays a color-coded buffer modification/read-only indicator in the mode-line." +  (if (not (string-match-p "\\*.*\\*" (buffer-name))) +      (let* ((read-only (and buffer-read-only (buffer-file-name))) +             (modified (buffer-modified-p))) +        (propertize +         (if read-only " " (if modified " ●" " ○")) +         'face `(:inherit +                 ,(if modified 'simple-modeline-status-modified +                    (if read-only 'simple-modeline-status-error +                      'simple-modeline-unimportant))) +         'help-echo (format +                     "Buffer is %s and %smodified\nmouse-1: Toggle read-only status." +                     (if read-only "read-only" "writable") +                     (if modified "" "not ")) +         'local-map (purecopy (simple-modeline-make-mouse-map +                               'mouse-1 +                               (lambda (event) +                                 (interactive "e") +                                 (with-selected-window (posn-window (event-start event)) +                                   (read-only-mode 'toggle))))) +         'mouse-face 'mode-line-highlight)))) + +(defun simple-modeline-segment-buffer-name () + "Displays the name of the current buffer in the mode-line." + (propertize " %b" 'face 'mode-line-buffer-id)) + +(defun simple-modeline-segment-vc () + "Displays color-coded version control information in the mode-line." + '(:eval (when vc-mode (concat "" (substring vc-mode 5))))) + +(defvar simple-modeline-segment-encoding-map +  (let ((map (make-sparse-keymap))) +    (define-key map [mode-line mouse-1] +      (lambda (e) +	(interactive "e") +	(with-selected-window (posn-window (event-start e)) +	  (when (and enable-multibyte-characters +		     buffer-file-coding-system) +	    (describe-coding-system buffer-file-coding-system))))) +    (define-key map [mode-line mouse-3] +      (lambda (e) +	(interactive "e") +	(with-selected-window (posn-window (event-start e)) +	  (call-interactively #'set-buffer-file-coding-system)))) +    (purecopy map)) +  "Local keymap for the coding-system part of the simple-modeline.") + +(defun simple-modeline-segment-major-mode () + "Displays the current major mode in the mode-line." + (propertize +  (concat " " +          (or (and (boundp 'delighted-modes) +                   (cadr (assq major-mode delighted-modes))) +              (format-mode-line mode-name))) +  'face 'bold)) + +(provide 'simple-modeline-segments) +;;; simple-modeline-segments.el ends here diff --git a/config/emacs/modeline/simple-modeline.el b/config/emacs/modeline/simple-modeline.el new file mode 100644 index 0000000..7e90389 --- /dev/null +++ b/config/emacs/modeline/simple-modeline.el @@ -0,0 +1,73 @@ +;;; simple-modeline.el --- A simple mode-line configuration for Emacs -*- lexical-binding: t; -*- + +;; Copyright (C) 2019-2021  Eder Elorriaga + +;; Author: Eder Elorriaga <gexplorer8@gmail.com> +;; URL: https://github.com/gexplorer/simple-modeline +;; Keywords: mode-line faces +;; Version: 1.4 +;; Package-Requires: ((emacs "26.1")) + +;; 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: + +;; A simple mode-line configuration for Emacs. +;; To enable, put this code in your init file: +;; (require 'simple-modeline) +;; (simple-modeline-mode 1) +;; or +;; (use-package simple-modeline +;;   :ensure t +;;   :hook (after-init . simple-modeline-mode)) +;; + +;;; Code: + +(require 'simple-modeline-core) +(require 'simple-modeline-segments) + +(defvar simple-modeline--mode-line +  '((:eval +     (simple-modeline--format +      (car simple-modeline-segments) +      (cadr simple-modeline-segments))))) + +;;;###autoload +(define-minor-mode simple-modeline-mode +  "Minor mode to get a simple mode line. + +When called interactively, toggle +`simple-modeline-mode'.  With prefix ARG, enable +`simple-modeline--mode' if ARG is positive, otherwise +disable it. + +When called from Lisp, enable `simple-modeline-mode' if ARG is omitted, +nil or positive.  If ARG is `toggle', toggle `simple-modeline-mode'. +Otherwise behave as if called interactively." +  :init-value nil +  :keymap nil +  :lighter "" +  :group 'simple-modeline +  :global t +  (if simple-modeline-mode +      (progn +        ;; Set the new mode-line-format +        (setq-default mode-line-format '(:eval simple-modeline--mode-line))) +    (progn +      ;; Restore the original mode-line format +      (setq-default mode-line-format simple-modeline--default-mode-line)))) + +(provide 'simple-modeline) +;;; simple-modeline.el ends here  | 
