summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbenjamin <benjamin.lindqvist@gmail.com>2018-10-02 22:47:15 +0200
committerbenjamin <benjamin.lindqvist@gmail.com>2018-10-02 22:47:15 +0200
commite4581850dd705740a5ccc2acdc91cce0eef1b0ae (patch)
tree0815038dd68ce363011ab068b644f0b058af8941
parentb903bcf5a1d628443aa31cba24fb397998406c52 (diff)
parent89ddf31ecad885e5491e8d6b71b48c1591b3faec (diff)
Merge branch 'master' of https://github.com/tautologyclub/feebleline into development
-rw-r--r--feebleline.el191
1 files changed, 91 insertions, 100 deletions
diff --git a/feebleline.el b/feebleline.el
index 2cf3779..af4fff9 100644
--- a/feebleline.el
+++ b/feebleline.el
@@ -1,4 +1,3 @@
-
;;; feebleline.el --- Replace modeline with a slimmer proxy
;; Copyright 2018 Benjamin Lindqvist
@@ -61,6 +60,8 @@
(when (< emacs-major-version 25)
(setq feebleline-use-legacy-settings t))
+(setq feebleline-use-legacy-settings nil)
+
(defface feebleline-time-face '((t :inherit 'font-lock-comment-face))
"Feebleline timestamp face."
:group 'feebleline)
@@ -68,58 +69,43 @@
"Feebleline linum face."
:group 'feebleline)
(defface feebleline-bufname-face '((t :inherit 'font-lock-function-name-face))
- "Feebleline buffer name face."
+ "Feebleline filename face."
:group 'feebleline)
(defface feebleline-asterisk-face '((t :foreground "salmon"))
"Feebleline file modified asterisk face."
:group 'feebleline)
(defface feebleline-previous-buffer-face '((t :foreground "#7e7e7e"))
- "Feebleline prev buffer face."
+ "Feebleline filename face."
:group 'feebleline)
(defface feebleline-dir-face '((t :inherit 'font-lock-variable-name-face))
- "Feebleline direcory face."
+ "Feebleline filename face."
:group 'feebleline)
(defface feebleline-git-branch-face '((t :inherit 'font-lock-comment-face :bold nil :italic t))
- "Feebleline git branch face."
+ "Feebleline filename face."
:group 'feebleline)
;; Customizations
(defcustom feebleline-show-time nil
- "Set this if you want to show the time in the modeline.
-
-Note: Toggling feebleline-mode is necessary for changes to take effect."
+ "Set this if you want to show the time in the modeline proxy."
:group 'feebleline)
-
(defcustom feebleline-show-git-branch nil
- "Set this if you want to show the git branch in the modeline.
-
-Note: Toggling feebleline-mode is necessary for changes to take effect."
+ "Set this if you want to show the git branch in the modeline proxy."
:group 'feebleline)
-
(defcustom feebleline-show-previous-buffer nil
- "Set this if you want to show the previous 'buffer-name' in the modeline.
-
-Note: Toggling feebleline-mode is necessary for changes to take effect."
+ "Set this if you want to show the previous 'buffer-name' in the modeline proxy."
:group 'feebleline)
-
(defcustom feebleline-show-directory t
- "Set this if you want to show the direcory path in the modeline.
-
-Note: Toggling feebleline-mode is necessary for changes to take effect."
+ "Set this if you want to show the direcory path as well as the file-name in the modeline proxy."
+ :group 'feebleline)
+(defcustom feebleline-show-linenum t
+ "Set this if you want to show line number and column number in the modeline proxy."
:group 'feebleline)
(defun feebleline-previous-buffer-name ()
"Get name of previous buffer."
(buffer-name (other-buffer (current-buffer) 1)))
-(defvar feebleline-mode-line-text
- '(("%s" ((feebleline-time-fn)) (face feebleline-time-face))
- ("%6s" ((feebleline-linum-fn)) (face feebleline-linum-face))
- (" %s" ((feebleline-dir-fn)) (face feebleline-dir-face))
- ("%s" ((feebleline-bufname-fn)) (face feebleline-bufname-face))
- ("%s" ((feebleline-buf-modified-fn)) (face feebleline-asterisk-face))
- ("%s" ((feebleline-git-branch-fn)) (face feebleline-git-branch-face))
- ("%s" ((feebleline-previous-buf-fn)) (face feebleline-previous-buffer-face)))
+(defvar feebleline-mode-line-text nil
"Each element is a list with the following format:
(FORMAT-STRING FORMAT-ARGS PROPS)
@@ -129,64 +115,76 @@ FORMAT-ARGS (a list) will be expanded as the rest of `format'
arguments. If PROPS is given, it should be a list which will be
sent to `add-text-properties'.")
-(defun feebleline--git-branch-string ()
- "Return current git branch as a string, or the empty string if pwd is not in a git repo (or the git command is not found)."
- (interactive)
+(require 'magit nil t)
+(if (fboundp 'magit-get-current-branch)
+ (defun feebleline--git-branch-string ()
+ "Return current git branch as a string, or the empty string if pwd is not in a git repo (or the git command is not found)."
+ (interactive)
+ (require 'esh-ext)
+ (let ((git-output (magit-get-current-branch)))
+ (if (> (length git-output) 0)
+ git-output
+ "(no branch)")))
+
+ (message "Warning: Feebleline couldn't find magit! Using hacky version to obtain git branch.")
(require 'esh-ext)
- (when (and (eshell-search-path "git")
- (locate-dominating-file default-directory ".git"))
- (let ((git-output (shell-command-to-string (concat "cd " default-directory " && git branch | grep '\\*' | sed -e 's/^\\* //'"))))
- (if (> (length git-output) 0)
- (concat " : " (substring git-output 0 -1))
- "(no branch)"))))
+ (defun feebleline--git-branch-string ()
+ "Return current git branch as a string, or the empty string if pwd is not in a git repo (or the git command is not found)."
+ (interactive)
+ (when (and (eshell-search-path "git")
+ (locate-dominating-file default-directory ".git"))
+ (let ((git-output (shell-command-to-string (concat "cd " default-directory " && git branch | grep '\\*' | sed -e 's/^\\* //'"))))
+ (if (> (length git-output) 0)
+ (substring git-output 0 -1)
+ "(no branch)")))))
(defvar feebleline--home-dir nil)
-(defun feebleline-buf-modified-fn ()
- "Return asterisk if buffer is a file and it was modified."
- (if (and (buffer-file-name) (buffer-modified-p)) "*" ""))
-
-(defun feebleline-bufname-fn ()
- "Return name of buffer."
- (buffer-name))
-
-(defun feebleline-linum-fn ()
- "Return linum:colnum."
- (format "%s:%s" (format-mode-line "%l") (current-column)))
-
-(defun feebleline-previous-buf-fn ()
- "Return name of previous buffer."
- (concat " | " (feebleline-previous-buffer-name)))
-
-(defun feebleline-dir-fn ()
- "Return linum:colnum."
- (if (buffer-file-name)
- (replace-regexp-in-string
- feebleline--home-dir "~"
- (file-name-directory (buffer-file-name)))
- ""))
-
-(defun feebleline-time-fn ()
- "Return timestamp."
- (format-time-string "[%H:%M:%S] "))
+(setq
+ feebleline-mode-line-text
+ '(
+ ("%s" ((if feebleline-show-time (format-time-string "[%H:%M:%S] ") ""))
+ (face feebleline-time-face))
+ ("%s"
+ ((if feebleline-show-linenum
+ (format "%5s:%-2s" (format-mode-line "%l") (current-column))
+ ""))
+ (face feebleline-linum-face))
+ (" %s" ((if (and feebleline-show-directory (buffer-file-name))
+ (replace-regexp-in-string
+ feebleline--home-dir "~"
+ (file-name-directory (buffer-file-name)))
+ ""))
+ (face feebleline-dir-face))
+ ("%s" ((if (buffer-file-name) (file-name-nondirectory (buffer-file-name))
+ (buffer-name)))
+ (face feebleline-bufname-face))
+ ("%s" ((if (and (buffer-file-name) (buffer-modified-p)) "*"
+ "" ))
+ (face feebleline-asterisk-face))
+ ("%s" ((if feebleline-show-git-branch (concat " : " (feebleline--git-branch-string))
+ ""))
+ (face feebleline-git-branch-face))
+ ("%s" ((if feebleline-show-previous-buffer (concat " | " (feebleline-previous-buffer-name))
+ ""))
+ (face feebleline-previous-buffer-face)))
+ )
-(defun feebleline-git-branch-fn ()
- "Show git branch."
- (feebleline--git-branch-string))
(defun feebleline-default-settings-on ()
"Some default settings that works well with feebleline."
(setq window-divider-default-bottom-width 1
window-divider-default-places (quote bottom-only))
(window-divider-mode t)
- (setq-default mode-line-format nil))
+ (setq-default mode-line-format nil)
+ (setq mode-line-format nil))
(defun feebleline-legacy-settings-on ()
"Some default settings for EMACS < 25."
(set-face-attribute 'mode-line nil :height 0.1))
-(defvar feebleline--timer)
-(defvar feebleline--mode-line-format-previous)
+(defvar feebleline/timer)
+(defvar feebleline/mode-line-format-previous)
;;;###autoload
(define-minor-mode feebleline-mode
@@ -197,29 +195,23 @@ sent to `add-text-properties'.")
;; Activation:
(progn
(setq feebleline--home-dir (expand-file-name "~"))
- (setq feebleline--mode-line-format-previous mode-line-format)
- (setq feebleline--timer
+ (setq feebleline/mode-line-format-previous mode-line-format)
+ (setq feebleline/timer
(run-with-timer 0 0.5 'feebleline-mode-line-proxy-fn))
- (if feebleline-use-legacy-settings
- (feebleline-legacy-settings-on)
+ (if feebleline-use-legacy-settings (feebleline-legacy-settings-on)
(feebleline-default-settings-on))
- (unless feebleline-show-time
- (defun feebleline-time-fn () ""))
- (unless feebleline-show-directory
- (defun feebleline-dir-fn () ""))
- (unless feebleline-show-git-branch
- (defun feebleline-git-branch-fn () ""))
- (unless feebleline-show-previous-buffer
- (defun feebleline-previous-buf-fn () ""))
- (ad-activate 'handle-switch-frame)
+ ;; (ad-activate 'handle-switch-frame)
(add-hook 'focus-in-hook 'feebleline-mode-line-proxy-fn))
;; Deactivation:
- (set-face-attribute 'mode-line nil :height 1)
- (setq-default mode-line-format feebleline--mode-line-format-previous)
- (cancel-timer feebleline--timer)
- (ad-deactivate 'handle-switch-frame)
+ (set-face-attribute 'mode-line nil :height 1.0)
+ (setq-default mode-line-format feebleline/mode-line-format-previous)
+ (setq mode-line-format feebleline/mode-line-format-previous)
+ (cancel-timer feebleline/timer)
+ ;; (ad-deactivate 'handle-switch-frame)
(remove-hook 'focus-in-hook 'feebleline-mode-line-proxy-fn)
+ (force-mode-line-update)
+ (redraw-display)
(with-current-buffer " *Minibuf-0*"
(erase-buffer))))
@@ -232,26 +224,25 @@ sent to `add-text-properties'.")
(add-text-properties 0 (length text) props text))
text))
-(defun feebleline--message-maybe ()
+(defvar feebleline-placeholder)
+(defun feebleline-write-buffer-name-maybe ()
"Replace echo-area message with mode-line proxy."
- (progn
- (let ((feebleline-placeholder
- (mapconcat #'feebleline--mode-line-part
- feebleline-mode-line-text "")))
- (with-current-buffer " *Minibuf-0*"
+ (progn (setq feebleline-placeholder (mapconcat #'feebleline--mode-line-part
+ feebleline-mode-line-text ""))
+ (with-current-buffer " *Minibuf-0*"
(erase-buffer)
- (insert feebleline-placeholder)))))
+ (insert feebleline-placeholder))))
(defun feebleline-mode-line-proxy-fn ()
"Put a mode-line proxy in the echo area *if* echo area is empty."
(unless (current-message)
- (feebleline--message-maybe)))
+ (feebleline-write-buffer-name-maybe)))
-(defadvice handle-switch-frame (after switch-frame-message-name)
- "Get the modeline proxy to work with i3 switch focus."
- (feebleline--message-maybe)
- ad-do-it
- (feebleline--message-maybe))
+;; (defadvice handle-switch-frame (after switch-frame-message-name)
+;; "Get the modeline proxy to work with i3 switch focus."
+;; (feebleline-write-buffer-name-maybe)
+;; ad-do-it
+;; (feebleline-write-buffer-name-maybe))
(provide 'feebleline)
;;; feebleline.el ends here