From a98f799d98dd0d416f9bd00e30ba4f3d1daa7bf6 Mon Sep 17 00:00:00 2001 From: benjamin Date: Wed, 3 Oct 2018 21:36:05 +0200 Subject: New customization API == strict improvement --- feebleline.el | 310 ++++++++++++++++++++++++++++------------------------------ 1 file changed, 152 insertions(+), 158 deletions(-) (limited to 'feebleline.el') diff --git a/feebleline.el b/feebleline.el index af4fff9..4e2a640 100644 --- a/feebleline.el +++ b/feebleline.el @@ -1,3 +1,4 @@ + ;;; feebleline.el --- Replace modeline with a slimmer proxy ;; Copyright 2018 Benjamin Lindqvist @@ -5,8 +6,8 @@ ;; Author: Benjamin Lindqvist ;; Maintainer: Benjamin Lindqvist ;; URL: https://github.com/tautologyclub/feebleline -;; Package-Version: 1.1 -;; Version: 1.1 +;; Package-Version: 2.0 +;; Version: 2.0 ;; This file is not part of GNU Emacs. @@ -33,143 +34,126 @@ ;; for anything else (but if you switch frame/window, it will replace whatever ;; message is currently displayed). -;; To customize feebleline's format, modify `feebleline-mode-line-text'. - -;; NOTE: -;; feebleline.el will look considerably better with the following -;; settings: +;; Feebleline now has a much improved customization interface. Simply set +;; feebleline-msg-functions to whatever you want! Example: -;; (window-divider-mode t) -;; (setq window-divider-default-bottom-width 1) -;; (setq window-divider-default-places (quote bottom-only)) +;; (setq +;; feebleline-msg-functions +;; '((feebleline-line-number) +;; (feebleline-column-number) +;; (feebleline-file-directory) +;; (feebleline-file-or-buffer-name) +;; (feebleline-file-modified-star) +;; (magit-get-current-branch) +;; (projectile-project-name))) -;; But this mode does not work for all EMACS versions and may not work with -;; terminal EMACS (but I haven't checked). If you're on GUI EMACS and your -;; version supports it, just place the following in your init file: +;; The elements should be functions, accepting no arguments, returning either +;; nil or a valid string. Even lambda functions work (but don't forget to quote +;; them). Optionally, you can include an alist after each function, like so: -;; (feebleline-default-settings) +;; (feebleline-line-number ((post . "") (fmt . "%5s"))) -;; Otherwise, do (feebleline-mode t) instead, but be warned that I'm not sure -;; if it will look good. +;; Accepted keys are pre, post, face, fmt and right-align (last one is +;; experimental). See source code for inspiration. ;;; Code: -(require 'advice) +(defcustom feebleline-msg-functions nil + "Fixme -- document me." + :type 'list + :group 'feebleline) -(defvar feebleline-use-legacy-settings nil) -(when (< emacs-major-version 25) - (setq feebleline-use-legacy-settings t)) +(defcustom feebleline-timer-interval 0.1 + "Refresh interval of feebleline mode-line proxy." + :type 'float + :group 'feebleline) -(setq feebleline-use-legacy-settings nil) +(defcustom feebleline-use-legacy-settings nil + "Hacky settings only applicable to releases older than 25." + :type 'boolean + :group 'feebleline + ) -(defface feebleline-time-face '((t :inherit 'font-lock-comment-face)) - "Feebleline timestamp face." - :group 'feebleline) -(defface feebleline-linum-face '((t :inherit 'default)) - "Feebleline linum face." - :group 'feebleline) -(defface feebleline-bufname-face '((t :inherit 'font-lock-function-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 filename face." +(defvar feebleline--home-dir nil) +(defvar feebleline--msg-timer) +(defvar feebleline/mode-line-format-previous) + +(defface feebleline-git-branch-face '((t :foreground "#444444" :italic t)) + "Example face for git branch." :group 'feebleline) + (defface feebleline-dir-face '((t :inherit 'font-lock-variable-name-face)) - "Feebleline filename face." - :group 'feebleline) -(defface feebleline-git-branch-face '((t :inherit 'font-lock-comment-face :bold nil :italic t)) - "Feebleline filename face." + "Example face for dir face." :group 'feebleline) -;; Customizations -(defcustom feebleline-show-time nil - "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 proxy." - :group 'feebleline) -(defcustom feebleline-show-previous-buffer nil - "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 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-linecol-string () + "Hey guy!" + (format "%4s:%-2s" (format-mode-line "%l") (current-column))) (defun feebleline-previous-buffer-name () "Get name of previous buffer." (buffer-name (other-buffer (current-buffer) 1))) -(defvar feebleline-mode-line-text nil - "Each element is a list with the following format: - - (FORMAT-STRING FORMAT-ARGS PROPS) - -FORMAT-STRING will be used as the first argument to `format', and -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'.") - -(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) - (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-line-number () + "Line number as string." + (if (buffer-file-name) + (format "%s" (line-number-at-pos)))) + +(defun feebleline-column-number () + "Column number as string." + (if (buffer-file-name) + (format "%s" (current-column)))) + +(defun feebleline-file-directory () + "Current directory, if buffer is displaying a file." + (if (buffer-file-name) + (replace-regexp-in-string + (concat "^" feebleline--home-dir) "~" + default-directory) + "")) + +(defun feebleline-file-or-buffer-name () + "Current file, or just buffer name if not a file." + (if (buffer-file-name) + (file-name-nondirectory (buffer-file-name)) + (buffer-name))) + +(defun feebleline-file-modified-star () + "Display star if buffer file was modified." + (when (and (buffer-file-name) (buffer-modified-p)) "*")) + +(defun feebleline-project-name () + "Return projectile project name if exists, otherwise nil." + (unless (string-equal "-" (projectile-project-name)) + (projectile-project-name))) + +;; -- TODO: +;; right-align property doesn't work with post/pre and it also messes up other +;; frames that don't have the same font size. Furthermore it has to be the last +;; element of the list and no more than one element can have the property. +;; Shortly, it's shite. (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))) - ) - + feebleline-msg-functions + '((feebleline-line-number ((post . "") (fmt . "%5s"))) + (feebleline-column-number ((pre . ":") (fmt . "%-2s"))) + (feebleline-file-directory ((face . feebleline-dir-face) (post . ""))) + (feebleline-file-or-buffer-name ((face . font-lock-keyword-face) (post . ""))) + (feebleline-file-modified-star ((face . font-lock-warning-face) (post . ""))) + (magit-get-current-branch ((face . feebleline-git-branch-face) (pre . " - "))) + ;; (feebleline-project-name ((right-align . t))) + )) + +(defmacro feebleline-append-msg-function (&rest b) + "Macro for adding B to the feebleline mode-line, at the end." + `(add-to-list 'feebleline-msg-functions ,@b t (lambda (x y) nil))) + +(defmacro feebleline-prepend-msg-function (&rest b) + "Macro for adding B to the feebleline mode-line, at the beginning." + `(add-to-list 'feebleline-msg-functions ,@b nil (lambda (x y) nil))) + +;; (feebleline-append-msg-function '((lambda () "end") ((pre . "/")))) +;; (feebleline-append-msg-function '(magit-get-current-branch ((pre . "/")))) +;; (feebleline-prepend-msg-function '((lambda () "-") ((post . "/")))) (defun feebleline-default-settings-on () "Some default settings that works well with feebleline." @@ -183,8 +167,46 @@ sent to `add-text-properties'.") "Some default settings for EMACS < 25." (set-face-attribute 'mode-line nil :height 0.1)) -(defvar feebleline/timer) -(defvar feebleline/mode-line-format-previous) +(defun feebleline--insert () + "Insert stuff into the mini buffer." + (unless (current-message) + (let ((tmp-string "")) + (dolist (idx feebleline-msg-functions) + (let ((string-func (car idx)) + (props (cadr idx))) + (let ((msg (apply string-func nil)) + (string-face (cdr (assoc 'face props))) + (pre (cdr (assoc 'pre props))) + (post (cdr (assoc 'post props))) + (fmt (cdr (assoc 'fmt props))) + (right-align (cdr (assoc 'right-align props))) + ) + (when msg + (unless string-face (setq string-face 'default)) + (unless post (setq post " ")) + (unless fmt (setq fmt "%s")) + (when right-align + (setq fmt + (concat "%" + (format "%s" (- (window-width) (length tmp-string) 1)) + "s")) + ;; (message "%s" fmt) + ) + (setq tmp-string + (concat + tmp-string + (propertize + (concat pre (format fmt msg) post) + 'face string-face))))))) + (with-current-buffer " *Minibuf-0*" + (erase-buffer) + (insert tmp-string))))) + +(defun feebleline--clear-echo-area () + "Erase echo area." + (with-current-buffer " *Minibuf-0*" + (erase-buffer)) + ) ;;;###autoload (define-minor-mode feebleline-mode @@ -196,53 +218,25 @@ sent to `add-text-properties'.") (progn (setq feebleline--home-dir (expand-file-name "~")) (setq feebleline/mode-line-format-previous mode-line-format) - (setq feebleline/timer - (run-with-timer 0 0.5 'feebleline-mode-line-proxy-fn)) + (setq feebleline--msg-timer (run-with-timer 0 feebleline-timer-interval 'feebleline--insert)) (if feebleline-use-legacy-settings (feebleline-legacy-settings-on) (feebleline-default-settings-on)) - ;; (ad-activate 'handle-switch-frame) - (add-hook 'focus-in-hook 'feebleline-mode-line-proxy-fn)) + (add-hook 'focus-in-hook 'feebleline--insert) + ) ;; Deactivation: (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) + (cancel-timer feebleline--msg-timer) + (remove-hook 'focus-in-hook 'feebleline--insert) (force-mode-line-update) (redraw-display) - (with-current-buffer " *Minibuf-0*" - (erase-buffer)))) - -(defun feebleline--mode-line-part (part) - "Return a PART (an element) of `feebleline-mode-line-text` as a propertized string." - (let ((text (apply #'format (append (list (car part)) - (mapcar #'eval (cadr part))))) - (props (elt part 2))) - (when props - (add-text-properties 0 (length text) props text)) - text)) - -(defvar feebleline-placeholder) -(defun feebleline-write-buffer-name-maybe () - "Replace echo-area message with mode-line proxy." - (progn (setq feebleline-placeholder (mapconcat #'feebleline--mode-line-part - feebleline-mode-line-text "")) - (with-current-buffer " *Minibuf-0*" - (erase-buffer) - (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-write-buffer-name-maybe))) + (feebleline--clear-echo-area))) + + -;; (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 -- cgit v1.2.3 From 948bf699b23d3cb756a17f651a90b240facc166c Mon Sep 17 00:00:00 2001 From: Kevin Boulain Date: Sat, 6 Oct 2018 17:01:58 +0200 Subject: magit-get-current-branch may not be bound or return anything It's probably better to try to import the required packages than to check if it is bound because the user may not load magit itself. Also fallback on rev-parse to display something in case the branch isn't available (for example, detached HEAD). --- feebleline.el | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'feebleline.el') diff --git a/feebleline.el b/feebleline.el index 4e2a640..e0d6f16 100644 --- a/feebleline.el +++ b/feebleline.el @@ -78,7 +78,7 @@ (defvar feebleline--msg-timer) (defvar feebleline/mode-line-format-previous) -(defface feebleline-git-branch-face '((t :foreground "#444444" :italic t)) +(defface feebleline-git-face '((t :foreground "#444444" :italic t)) "Example face for git branch." :group 'feebleline) @@ -118,6 +118,13 @@ (file-name-nondirectory (buffer-file-name)) (buffer-name))) +(defun feebleline-git-object () + "Current branch, when magit is available." + (when (and (require 'magit-git nil t) + (require 'magit-process nil t)) + (or (magit-get-current-branch) ; may return nil when not on a branch + (magit-rev-parse "--short" "HEAD")))) + (defun feebleline-file-modified-star () "Display star if buffer file was modified." (when (and (buffer-file-name) (buffer-modified-p)) "*")) @@ -139,7 +146,7 @@ (feebleline-file-directory ((face . feebleline-dir-face) (post . ""))) (feebleline-file-or-buffer-name ((face . font-lock-keyword-face) (post . ""))) (feebleline-file-modified-star ((face . font-lock-warning-face) (post . ""))) - (magit-get-current-branch ((face . feebleline-git-branch-face) (pre . " - "))) + (feebleline-git-object ((face . feebleline-git-face) (pre . " - "))) ;; (feebleline-project-name ((right-align . t))) )) -- cgit v1.2.3 From fe6abeba276d524bec972beaf838126a705f4015 Mon Sep 17 00:00:00 2001 From: Kevin Boulain Date: Sat, 6 Oct 2018 18:15:08 +0200 Subject: always return line and column numbers For example, buffer-file-name returns nothing for the scratch buffer, which is probably not what we want. --- feebleline.el | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'feebleline.el') diff --git a/feebleline.el b/feebleline.el index e0d6f16..ee83bae 100644 --- a/feebleline.el +++ b/feebleline.el @@ -96,13 +96,11 @@ (defun feebleline-line-number () "Line number as string." - (if (buffer-file-name) - (format "%s" (line-number-at-pos)))) + (format "%s" (line-number-at-pos))) (defun feebleline-column-number () "Column number as string." - (if (buffer-file-name) - (format "%s" (current-column)))) + (format "%s" (current-column))) (defun feebleline-file-directory () "Current directory, if buffer is displaying a file." -- cgit v1.2.3 From 68c0255b78868fb02bb5481db1247d67df241da8 Mon Sep 17 00:00:00 2001 From: Kevin Boulain Date: Sat, 6 Oct 2018 18:12:12 +0200 Subject: use keywords instead of alist in feebleline-msg-functions So it's a bit easier to customize. --- feebleline.el | 61 +++++++++++++++++++++++++---------------------------------- 1 file changed, 26 insertions(+), 35 deletions(-) (limited to 'feebleline.el') diff --git a/feebleline.el b/feebleline.el index ee83bae..928950c 100644 --- a/feebleline.el +++ b/feebleline.el @@ -49,9 +49,9 @@ ;; The elements should be functions, accepting no arguments, returning either ;; nil or a valid string. Even lambda functions work (but don't forget to quote -;; them). Optionally, you can include an alist after each function, like so: +;; them). Optionally, you can include keywords after each function, like so: -;; (feebleline-line-number ((post . "") (fmt . "%5s"))) +;; (feebleline-line-number :post "" :fmt "%5s") ;; Accepted keys are pre, post, face, fmt and right-align (last one is ;; experimental). See source code for inspiration. @@ -139,13 +139,13 @@ ;; Shortly, it's shite. (setq feebleline-msg-functions - '((feebleline-line-number ((post . "") (fmt . "%5s"))) - (feebleline-column-number ((pre . ":") (fmt . "%-2s"))) - (feebleline-file-directory ((face . feebleline-dir-face) (post . ""))) - (feebleline-file-or-buffer-name ((face . font-lock-keyword-face) (post . ""))) - (feebleline-file-modified-star ((face . font-lock-warning-face) (post . ""))) - (feebleline-git-object ((face . feebleline-git-face) (pre . " - "))) - ;; (feebleline-project-name ((right-align . t))) + '((feebleline-line-number :post "" :fmt "%5s") + (feebleline-column-number :pre ":" :fmt "%-2s") + (feebleline-file-directory :face feebleline-dir-face :post "") + (feebleline-file-or-buffer-name :face font-lock-keyword-face :post "") + (feebleline-file-modified-star :face font-lock-warning-face :post "") + (feebleline-git-object :face feebleline-git-face :pre " - ") + ;; (feebleline-project-name :right-align t) )) (defmacro feebleline-append-msg-function (&rest b) @@ -172,37 +172,28 @@ "Some default settings for EMACS < 25." (set-face-attribute 'mode-line nil :height 0.1)) +(cl-defun feebleline--insert-func (func &key (face 'default) pre (post " ") (fmt "%s") right-align) + "Format an element of feebleline-msg-functions based on its properties." + (when right-align + (setq fmt (concat "%" + (format "%s" (- (window-width) (length tmp-string) 1)) + "s"))) + (let* ((msg (apply func nil)) + (string (concat pre (format fmt msg) post))) + (if msg + (if face + (propertize string 'face face) + string) + ""))) + (defun feebleline--insert () "Insert stuff into the mini buffer." (unless (current-message) (let ((tmp-string "")) (dolist (idx feebleline-msg-functions) - (let ((string-func (car idx)) - (props (cadr idx))) - (let ((msg (apply string-func nil)) - (string-face (cdr (assoc 'face props))) - (pre (cdr (assoc 'pre props))) - (post (cdr (assoc 'post props))) - (fmt (cdr (assoc 'fmt props))) - (right-align (cdr (assoc 'right-align props))) - ) - (when msg - (unless string-face (setq string-face 'default)) - (unless post (setq post " ")) - (unless fmt (setq fmt "%s")) - (when right-align - (setq fmt - (concat "%" - (format "%s" (- (window-width) (length tmp-string) 1)) - "s")) - ;; (message "%s" fmt) - ) - (setq tmp-string - (concat - tmp-string - (propertize - (concat pre (format fmt msg) post) - 'face string-face))))))) + (setq tmp-string + (concat tmp-string + (apply 'feebleline--insert-func idx)))) (with-current-buffer " *Minibuf-0*" (erase-buffer) (insert tmp-string))))) -- cgit v1.2.3 From b747ffc766321d3aa11dd9981c3c452bce3097cc Mon Sep 17 00:00:00 2001 From: Kevin Boulain Date: Mon, 8 Oct 2018 23:03:22 +0200 Subject: review: don't require magit User should load magit if desired. Or simply remove the function from feebleline-msg-functions. --- feebleline.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'feebleline.el') diff --git a/feebleline.el b/feebleline.el index 928950c..346f829 100644 --- a/feebleline.el +++ b/feebleline.el @@ -118,8 +118,8 @@ (defun feebleline-git-object () "Current branch, when magit is available." - (when (and (require 'magit-git nil t) - (require 'magit-process nil t)) + (when (and (fboundp 'magit-get-current-branch) + (fboundp 'magit-rev-parse)) (or (magit-get-current-branch) ; may return nil when not on a branch (magit-rev-parse "--short" "HEAD")))) -- cgit v1.2.3 From f16e8d715f1b801c18d00a458cb2985880e2673b Mon Sep 17 00:00:00 2001 From: benjamin Date: Mon, 8 Oct 2018 20:50:29 +0200 Subject: forgot to include the actual error ignoring in last commit --- feebleline.el | 115 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 58 insertions(+), 57 deletions(-) (limited to 'feebleline.el') diff --git a/feebleline.el b/feebleline.el index 4e2a640..6979334 100644 --- a/feebleline.el +++ b/feebleline.el @@ -76,7 +76,7 @@ (defvar feebleline--home-dir nil) (defvar feebleline--msg-timer) -(defvar feebleline/mode-line-format-previous) +(defvar feebleline--mode-line-format-previous) (defface feebleline-git-branch-face '((t :foreground "#444444" :italic t)) "Example face for git branch." @@ -96,21 +96,18 @@ (defun feebleline-line-number () "Line number as string." - (if (buffer-file-name) - (format "%s" (line-number-at-pos)))) + (when (buffer-file-name) (format "%s" (line-number-at-pos)))) (defun feebleline-column-number () "Column number as string." - (if (buffer-file-name) - (format "%s" (current-column)))) + (when (buffer-file-name) (format "%s" (current-column)))) (defun feebleline-file-directory () "Current directory, if buffer is displaying a file." - (if (buffer-file-name) - (replace-regexp-in-string - (concat "^" feebleline--home-dir) "~" - default-directory) - "")) + (when (buffer-file-name) + (replace-regexp-in-string + (concat "^" feebleline--home-dir) "~" + default-directory))) (defun feebleline-file-or-buffer-name () "Current file, or just buffer name if not a file." @@ -167,46 +164,53 @@ "Some default settings for EMACS < 25." (set-face-attribute 'mode-line nil :height 0.1)) -(defun feebleline--insert () - "Insert stuff into the mini buffer." +(defun feebleline--insert-ignore-errors () + "Insert stuff into the echo area, ignoring potential errors." (unless (current-message) - (let ((tmp-string "")) - (dolist (idx feebleline-msg-functions) - (let ((string-func (car idx)) - (props (cadr idx))) - (let ((msg (apply string-func nil)) - (string-face (cdr (assoc 'face props))) - (pre (cdr (assoc 'pre props))) - (post (cdr (assoc 'post props))) - (fmt (cdr (assoc 'fmt props))) - (right-align (cdr (assoc 'right-align props))) - ) - (when msg - (unless string-face (setq string-face 'default)) - (unless post (setq post " ")) - (unless fmt (setq fmt "%s")) - (when right-align - (setq fmt - (concat "%" - (format "%s" (- (window-width) (length tmp-string) 1)) - "s")) - ;; (message "%s" fmt) - ) - (setq tmp-string - (concat - tmp-string - (propertize - (concat pre (format fmt msg) post) - 'face string-face))))))) - (with-current-buffer " *Minibuf-0*" - (erase-buffer) - (insert tmp-string))))) + (condition-case nil (feebleline--insert) + (error nil)))) + +(defun feebleline--force-insert () + "Insert stuff into the echo area even if it's displaying something." + (condition-case nil (feebleline--clear-echo-area) + (error nil))) + +(defun feebleline--fmt-string-right-align (string-to-align) + "Format string usable for right-aligning STRING-TO-ALIGN." + (concat "%" (format "%s" (- (window-width) (length string-to-align) 1)) "s")) + +(defvar feebleline--minibuf " *Minibuf-0*") + +(defun feebleline--insert () + "Insert stuff into the echo area." + (let ((tmp-string "")) + (dolist (element feebleline-msg-functions) + (let ((string-func (car element)) + (props (cadr element))) + (let ((msg (apply string-func nil)) + (string-face (cdr (assoc 'face props))) + (pre (cdr (assoc 'pre props))) + (post (cdr (assoc 'post props))) + (fmt (cdr (assoc 'fmt props))) + (right-align (cdr (assoc 'right-align props)))) + (when msg + (unless string-face (setq string-face 'default)) + (unless post (setq post " ")) + (unless fmt (setq fmt "%s")) + (when right-align + (setq fmt (feebleline--fmt-string-right-align tmp-string))) + (setq tmp-string + (concat tmp-string + (propertize (concat pre (format fmt msg) post) + 'face string-face))))))) + (with-current-buffer feebleline--minibuf + (erase-buffer) + (insert tmp-string)))) (defun feebleline--clear-echo-area () "Erase echo area." - (with-current-buffer " *Minibuf-0*" - (erase-buffer)) - ) + (with-current-buffer feebleline--minibuf + (erase-buffer))) ;;;###autoload (define-minor-mode feebleline-mode @@ -217,26 +221,23 @@ ;; Activation: (progn (setq feebleline--home-dir (expand-file-name "~")) - (setq feebleline/mode-line-format-previous mode-line-format) - (setq feebleline--msg-timer (run-with-timer 0 feebleline-timer-interval 'feebleline--insert)) + (setq feebleline--mode-line-format-previous mode-line-format) + (setq feebleline--msg-timer + (run-with-timer 0 feebleline-timer-interval + 'feebleline--insert-ignore-errors)) (if feebleline-use-legacy-settings (feebleline-legacy-settings-on) (feebleline-default-settings-on)) - (add-hook 'focus-in-hook 'feebleline--insert) - ) + (add-hook 'focus-in-hook 'feebleline--insert-ignore-errors)) ;; Deactivation: (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) + (setq-default mode-line-format feebleline--mode-line-format-previous) + (setq mode-line-format feebleline--mode-line-format-previous) (cancel-timer feebleline--msg-timer) - (remove-hook 'focus-in-hook 'feebleline--insert) + (remove-hook 'focus-in-hook 'feebleline--insert-ignore-errors) (force-mode-line-update) (redraw-display) (feebleline--clear-echo-area))) - - - - ; (provide 'feebleline) ;;; feebleline.el ends here -- cgit v1.2.3 From 6f55e4fbcb2279ed13441efdeb482dc7b569bbe9 Mon Sep 17 00:00:00 2001 From: benjamin Date: Thu, 11 Oct 2018 18:54:52 +0200 Subject: removed magit-get-current-branch as default option (should recommend in README tho) --- feebleline.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'feebleline.el') diff --git a/feebleline.el b/feebleline.el index 7337b7b..914030a 100644 --- a/feebleline.el +++ b/feebleline.el @@ -136,7 +136,7 @@ (feebleline-file-directory :face feebleline-dir-face :post "") (feebleline-file-or-buffer-name :face font-lock-keyword-face :post "") (feebleline-file-modified-star :face font-lock-warning-face :post "") - (magit-get-current-branch :face feebleline-git-face :pre " - ") + ;; (magit-get-current-branch :face feebleline-git-face :pre " - ") ;; (feebleline-project-name :right-align t) )) -- cgit v1.2.3 From f8445e4d789c4191f1e9330c4a98a65bbc9911af Mon Sep 17 00:00:00 2001 From: Kevin Boulain Date: Sun, 21 Oct 2018 18:04:28 +0200 Subject: less hackish alignment handling It could easily be extended to provide middle alignment if desired. --- feebleline.el | 59 +++++++++++++++++++++++++++++------------------------------ 1 file changed, 29 insertions(+), 30 deletions(-) (limited to 'feebleline.el') diff --git a/feebleline.el b/feebleline.el index 914030a..32fe817 100644 --- a/feebleline.el +++ b/feebleline.el @@ -53,8 +53,8 @@ ;; (feebleline-line-number :post "" :fmt "%5s") -;; Accepted keys are pre, post, face, fmt and right-align (last one is -;; experimental). See source code for inspiration. +;; Accepted keys are pre, post, face, fmt and align. +;; See source code for inspiration. ;;; Code: (require 'cl-macs) @@ -124,11 +124,10 @@ (unless (string-equal "-" (projectile-project-name)) (projectile-project-name))) -;; -- TODO: -;; right-align property doesn't work with post/pre and it also messes up other -;; frames that don't have the same font size. Furthermore it has to be the last -;; element of the list and no more than one element can have the property. -;; Shortly, it's shite. +;; align semantics may be a bit confusing as the user isn't required to +;; put them in order (three formats may be specified with right, left and right alignments +;; and feebleline will still figure out that the first and third formats should be joined +;; together and put in the right column while the second one should be put in the left column). (setq feebleline-msg-functions '((feebleline-line-number :post "" :fmt "%5s") @@ -137,7 +136,7 @@ (feebleline-file-or-buffer-name :face font-lock-keyword-face :post "") (feebleline-file-modified-star :face font-lock-warning-face :post "") ;; (magit-get-current-branch :face feebleline-git-face :pre " - ") - ;; (feebleline-project-name :right-align t) + ;; (feebleline-project-name :align right) )) (defmacro feebleline-append-msg-function (&rest b) @@ -176,37 +175,37 @@ (condition-case nil (feebleline--clear-echo-area) (error nil))) -(defun feebleline--fmt-string-right-align (string-to-align) - "Format string usable for right-aligning STRING-TO-ALIGN." - (concat "%" (format "%s" (- (window-width) (length string-to-align) 1)) "s")) - (defvar feebleline--minibuf " *Minibuf-0*") -(cl-defun feebleline--insert-func (func &key (face 'default) pre (post " ") (fmt "%s") right-align) - "Format an element of feebleline-msg-functions based on its properties." - (when right-align - (setq fmt (concat "%" - (format "%s" (- (window-width) (length tmp-string) 1)) - "s"))) - (let* ((msg (apply func nil)) - (string (concat pre (format fmt msg) post))) - (if msg - (if face - (propertize string 'face face) - string) - ""))) +(cl-defun feebleline--insert-func (func &key (face 'default) pre (post " ") (fmt "%s") (align 'left)) + "Format an element of feebleline-msg-functions based on its properties. +Returns a pair with desired column and string." + (list align + (let* ((msg (apply func nil)) + (string (concat pre (format fmt msg) post))) + (if msg + (if face + (propertize string 'face face) + string) + "")))) (defun feebleline--insert () "Insert stuff into the mini buffer." (unless (current-message) - (let ((tmp-string "")) + (let ((left ()) + (right ())) (dolist (idx feebleline-msg-functions) - (setq tmp-string - (concat tmp-string - (apply 'feebleline--insert-func idx)))) + (let* ((fragment (apply 'feebleline--insert-func idx)) + (align (car fragment)) + (string (cadr fragment))) + (push string (symbol-value align)))) (with-current-buffer " *Minibuf-0*" (erase-buffer) - (insert tmp-string))))) + (let* ((left-string (string-join (reverse left))) + (right-string (string-join (reverse right))) + (free-space (- (window-width) (length left-string) (length right-string))) + (padding (make-string (max 0 free-space) ?\ ))) + (insert (concat left-string padding right-string))))))) (defun feebleline--clear-echo-area () "Erase echo area." -- cgit v1.2.3 From c84541adb5999206d96c1b4644875dc1e3e359be Mon Sep 17 00:00:00 2001 From: Kevin Boulain Date: Sun, 21 Oct 2018 18:05:40 +0200 Subject: replace hard-coded name --- feebleline.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'feebleline.el') diff --git a/feebleline.el b/feebleline.el index 32fe817..bf3faba 100644 --- a/feebleline.el +++ b/feebleline.el @@ -199,7 +199,7 @@ Returns a pair with desired column and string." (align (car fragment)) (string (cadr fragment))) (push string (symbol-value align)))) - (with-current-buffer " *Minibuf-0*" + (with-current-buffer feebleline--minibuf (erase-buffer) (let* ((left-string (string-join (reverse left))) (right-string (string-join (reverse right))) -- cgit v1.2.3 From 1956533963a4f5680827974ae34bfc80c2bc52f9 Mon Sep 17 00:00:00 2001 From: Benjamin Lindqvist Date: Tue, 2 Apr 2019 14:38:00 +0200 Subject: Don't bloat echo area vertically --- feebleline.el | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'feebleline.el') diff --git a/feebleline.el b/feebleline.el index bf3faba..06ee7a2 100644 --- a/feebleline.el +++ b/feebleline.el @@ -202,10 +202,12 @@ Returns a pair with desired column and string." (with-current-buffer feebleline--minibuf (erase-buffer) (let* ((left-string (string-join (reverse left))) + (message-truncate-lines t) + (max-mini-window-height 1) (right-string (string-join (reverse right))) (free-space (- (window-width) (length left-string) (length right-string))) (padding (make-string (max 0 free-space) ?\ ))) - (insert (concat left-string padding right-string))))))) + (insert (concat left-string (if right-string (concat padding right-string))))))))) (defun feebleline--clear-echo-area () "Erase echo area." @@ -224,17 +226,17 @@ Returns a pair with desired column and string." (setq feebleline--mode-line-format-previous mode-line-format) (setq feebleline--msg-timer (run-with-timer 0 feebleline-timer-interval - 'feebleline--insert)) + 'feebleline--insert-ignore-errors)) (if feebleline-use-legacy-settings (feebleline-legacy-settings-on) (feebleline-default-settings-on)) - (add-hook 'focus-in-hook 'feebleline--insert)) + (add-hook 'focus-in-hook 'feebleline--insert-ignore-errors)) ;; Deactivation: (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--msg-timer) - (remove-hook 'focus-in-hook 'feebleline--insert) + (remove-hook 'focus-in-hook 'feebleline--insert-ignore-errors) (force-mode-line-update) (redraw-display) (feebleline--clear-echo-area))) -- cgit v1.2.3 From cc2a9633e02e5d1e021e7a494266f872882177b2 Mon Sep 17 00:00:00 2001 From: Benjamin Lindqvist Date: Tue, 2 Apr 2019 14:39:03 +0200 Subject: Disable git branch info when file is remote Using magit-get-current-branch caused emacs to completely blow up when using tramp. Workaround is to not even try on remote files, just return "-" --- feebleline.el | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'feebleline.el') diff --git a/feebleline.el b/feebleline.el index 06ee7a2..259a8b7 100644 --- a/feebleline.el +++ b/feebleline.el @@ -58,7 +58,22 @@ ;;; Code: (require 'cl-macs) -(defcustom feebleline-msg-functions nil + +(defun feebleline-git-branch () + "Return current git branch, unless file is remote." + (if (file-remote-p (buffer-file-name)) + "-" + (magit-get-current-branch))) + +(defcustom feebleline-msg-functions + '((feebleline-line-number :post "" :fmt "%5s") + (feebleline-column-number :pre ":" :fmt "%-2s") + (feebleline-file-directory :face feebleline-dir-face :post "") + (feebleline-file-or-buffer-name :face font-lock-keyword-face :post "") + (feebleline-file-modified-star :face font-lock-warning-face :post "") + (feebleline-git-branch :face feebleline-git-face :pre " - ") + ;; (feebleline-project-name :align right) + ) "Fixme -- document me." :type 'list :group 'feebleline) @@ -78,7 +93,7 @@ (defvar feebleline--msg-timer) (defvar feebleline--mode-line-format-previous) -(defface feebleline-git-face '((t :foreground "#444444" :italic t)) +(defface feebleline-git-face '((t :foreground "#444444")) "Example face for git branch." :group 'feebleline) @@ -124,21 +139,6 @@ (unless (string-equal "-" (projectile-project-name)) (projectile-project-name))) -;; align semantics may be a bit confusing as the user isn't required to -;; put them in order (three formats may be specified with right, left and right alignments -;; and feebleline will still figure out that the first and third formats should be joined -;; together and put in the right column while the second one should be put in the left column). -(setq - feebleline-msg-functions - '((feebleline-line-number :post "" :fmt "%5s") - (feebleline-column-number :pre ":" :fmt "%-2s") - (feebleline-file-directory :face feebleline-dir-face :post "") - (feebleline-file-or-buffer-name :face font-lock-keyword-face :post "") - (feebleline-file-modified-star :face font-lock-warning-face :post "") - ;; (magit-get-current-branch :face feebleline-git-face :pre " - ") - ;; (feebleline-project-name :align right) - )) - (defmacro feebleline-append-msg-function (&rest b) "Macro for adding B to the feebleline mode-line, at the end." `(add-to-list 'feebleline-msg-functions ,@b t (lambda (x y) nil))) -- cgit v1.2.3