Skip to content

Instantly share code, notes, and snippets.

@ZaneA
Forked from lateau/simple-mode-line.el
Last active December 16, 2015 05:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ZaneA/5386451 to your computer and use it in GitHub Desktop.
Save ZaneA/5386451 to your computer and use it in GitHub Desktop.
Remove some warnings.
;;; simple-mode-line.el --- Simplified Mode Line for Emacs 24
;; Author: Daehyub Kim <lateau at gmail.com>
;; URL: https://gist.github.com/4511988
;; Version: 0.1
;; Keywords: mode-line, color
;;; Commentary:
;; This simplified mode line is adjusted to *white* themes.
;; Use this mode line with white themes is highly recommended
;; but some colors are modifiable and customize them to fit your
;; favorite theme. For more description see below defcustom macros.
;;
;; To run:
;; (require 'simple-mode-line)
;; (activate-simple-mode-line)
;;
;; To display global-mode-string informations:
;; (setq simple-mode-line-display-global-mode-string t)
;;
;;; Code:
(defgroup simple-mode-line nil
"Simplified Mode Line.")
(defcustom simple-mode-line-display-global-mode-string nil
"Hide global-mode-string in default."
:group 'simple-mode-line
:type 'boolean)
(defcustom simple-mode-line-font-height (face-attribute 'default :height)
"Set default font height."
:group 'simple-mode-line
:type 'integer)
(defcustom simple-mode-line-small-font-height (- simple-mode-line-font-height 20)
"Set default small font height for inactivated mode line."
:group 'simple-mode-line
:type 'integer)
(defcustom simple-mode-line-dir-lmax 1
"Set how many directories display."
:group 'simple-mode-line
:type 'integer)
(defcustom simple-mode-line-dir-rmax 3
"Set how many directories display."
:group 'simple-mode-line
:type 'integer)
(defcustom simple-mode-line-line-width 8
"Set default line width."
:group 'simple-mode-line
:type 'integer)
(defcustom simple-mode-line-inactive-line-width 5
"Set default line width."
:group 'simple-mode-line
:type 'integer)
(defcustom simple-mode-line-background "#000"
"Set default background color."
:group 'simple-mode-line
:type 'string)
(defcustom simple-mode-line-foreground "#fff"
"Set default foreground color."
:group 'simple-mode-line
:type 'string)
(defcustom simple-mode-line-inactive-background "#000"
"Set background color for inactivated mode-line."
:group 'simple-mode-line
:type 'string)
(defcustom simple-mode-line-inactive-foreground "#888"
"Set foreground color for inactivated mode-line."
:group 'simple-mode-line
:type 'string)
(defcustom simple-mode-line-highlight "dark orange"
"Set highlight color such like col80+ and input method."
:group 'simple-mode-line
:type 'string)
(defcustom simple-mode-line-read-only "#fff"
"Set foreground color for read only file buffer name."
:group 'simple-mode-line
:type 'string)
(defcustom simple-mode-line-editable "sky blue"
"Set foreground color for editable file buffer name."
:group 'simple-mode-line
:type 'string)
(defcustom simple-mode-line-modified "pink"
"Set foreground color for modified file buffer name."
:group 'simple-mode-line
:type 'string)
(defface mode-line-position-face '()
"Cursor line position in mode-line."
:group 'simple-mode-line)
(defun simple-path (truepath lmax rmax)
"Generates simplified path from file path"
(let ((path (cdr (split-string truepath "/")))
(result ""))
(if (<= (length path) (+ lmax rmax))
(let ((file-name-length (length (car (reverse path)))))
(substring truepath 0 (- (length truepath) file-name-length)))
(let ((start-point (substring truepath 0 1))
(lcount 0)
(rcount 0))
(while (and path (< lcount lmax))
(setq result (concat result "/" (car path)))
(setq lcount (1+ lcount))
(setq path (cdr path)))
(setq path (last path (+ rmax 1)))
(setq result (concat result "/..."))
(while (and path (< rcount rmax))
(setq result (concat result "/" (car path)))
(setq rcount (1+ rcount))
(setq path (cdr path)))
(if (string= start-point "~")
(setq result (concat "~" result)))
(setq result (concat result "/"))
result))))
(setq simple-mode-line-format
'(;; input method
(:propertize current-input-method-title face mode-line-input-method-title-face)
" "
"%z"
" "
;; Display current buffer file path or name
(:eval (simple-path (if buffer-file-truename
buffer-file-truename
"")
simple-mode-line-dir-lmax
simple-mode-line-dir-rmax))
(:eval
(cond (buffer-read-only
(propertize "%b" 'face 'mode-line-read-only-face))
((buffer-modified-p)
(propertize "%b" 'face 'mode-line-modified-face))
(t (propertize "%b" 'face 'mode-line-editable-face))))
" "
;; is remote or local?
(:eval (if buffer-file-name mode-line-remote))
(:eval (if buffer-file-name " "))
;; Display a current cursor position
(:propertize (:eval (if buffer-file-name "%l")) 'face mode-line-position-face)
(:eval (propertize (if buffer-file-name ":%c " "")
'face
(if (>= (current-column) 80) 'mode-line-80+-face
'mode-line-position-face)))
;; Other buffer file infomations
(:eval (if buffer-file-name "%p "))
(:eval (if buffer-file-name "%I "))
;; vc mode
(vc-mode vc-mode)
" "
;; Major mode
"%m"
;; global-mode-string
(:eval (if simple-mode-line-display-global-mode-string " "))
(:eval (if simple-mode-line-display-global-mode-string global-mode-string))))
(defun set-simple-mode-line-face ()
""
(make-face 'mode-line-input-method-title-face)
(make-face 'mode-line-editable-face)
(make-face 'mode-line-read-only-face)
(make-face 'mode-line-modified-face)
(make-face 'mode-line-80+-face)
(set-face-attribute 'mode-line nil
:height simple-mode-line-font-height
:foreground simple-mode-line-foreground
:background simple-mode-line-background
:inverse-video nil
:box (list :line-width simple-mode-line-line-width :color simple-mode-line-background :style nil))
(set-face-attribute 'mode-line-inactive nil
:height simple-mode-line-small-font-height
:foreground simple-mode-line-inactive-foreground
:background simple-mode-line-inactive-background
:inverse-video nil
:box (list :line-width simple-mode-line-inactive-line-width :color simple-mode-line-inactive-background :style nil))
(set-face-attribute 'mode-line-editable-face nil
:inherit 'mode-line-face
:foreground simple-mode-line-editable)
(set-face-attribute 'mode-line-input-method-title-face nil
:inherit 'mode-line-face
:foreground simple-mode-line-highlight
:background simple-mode-line-background)
(set-face-attribute 'mode-line-read-only-face nil
:inherit 'mode-line-face
:foreground simple-mode-line-read-only)
(set-face-attribute 'mode-line-modified-face nil
:inherit 'mode-line-face
:foreground simple-mode-line-modified)
(set-face-attribute 'mode-line-80+-face nil
:inherit 'mode-line-face
:foreground simple-mode-line-highlight))
(defun activate-simple-mode-line ()
(interactive)
(setq-default mode-line-format nil)
(set-simple-mode-line-face)
(setq-default mode-line-format simple-mode-line-format))
;;;###autoload
(when load-file-name
(add-to-list 'load-path
(file-name-as-directory (file-name-directory load-file-name))))
(provide 'simple-mode-line)
;; Local Variables:
;; no-byte-compile: t
;; End:
;;; simple-mode-line.el ends here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment