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(-) 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(-) 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 1e04c540b46b377c7d3271dcd36c0b87a9c36228 Mon Sep 17 00:00:00 2001 From: Kevin Boulain Date: Sun, 21 Oct 2018 18:17:55 +0200 Subject: update readme --- README.md | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 178bca3..9d849c9 100644 --- a/README.md +++ b/README.md @@ -27,11 +27,19 @@ to see what you can do. An example init snippet would look something like: (use-package feebleline :ensure t - :custom (feebleline-show-git-branch t) - (feebleline-show-dir t) - (feebleline-show-time nil) - (feebleline-show-previous-buffer nil) - :config (feebleline-mode 1)) + :config (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))) + (feebleline-mode 1)) + +The minibuffer should now show something similar to: + + 1:0 ~/feebleline/feebleline.el - development feebleline ## Screenshots This is a screenshow from the latest version (yes that is my -- cgit v1.2.3