Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability to selectively show or hide minor mode indicators #159

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 49 additions & 2 deletions powerline.el
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,36 @@ converted to equivalent Apple RGB colors before image generation."
:group 'powerline
:type 'string)

(defcustom powerline-minor-mode-filter-mode 'include
"The way in which minor mode indicators are filtered using ‘powerline-minor-mode-filter-regexp-list’.

Valid values:

- include (the default): any minor-mode whose indicator string
does not match any of the regexps in
‘powerline-minor-mode-filter-regexp-list’ will NOT be
displayed (white-list mode). Use this filter mode if you would
like to hide all but a select, few minor mode indicators.

- exclude: any minor-mode whose indicator string does not match
any of the regexps in ‘powerline-minor-mode-filter-regexp-list’
will be displayed (black-list mode). Unse this filter mode if
you would like to show all but a select, few minor mode
indicators."
:group 'powerline
:type '(choice (const include)
(const exclude)))

(defcustom powerline-minor-mode-filter-regexp-list nil
"List of regular experssions for filtering minor mode indicators accoring to ‘powerline-minor-mode-filter-mode’.

When nil (the default) or an empty list, all minor mode
indicators will be shown. For details on regular expressions, see
info node ‘(elisp) Regular Expressions’. Also note well that an
empty regular expression (\"\") matches everything."
:group 'powerline
:type '(repeat regexp))

(defun pl/create-or-get-cache ()
"Return a frame-local hash table that acts as a memoization cache for powerline. Create one if the frame doesn't have one yet."
(let ((table (frame-parameter nil 'powerline-cache)))
Expand Down Expand Up @@ -469,8 +499,9 @@ static char * %s[] = {
[header-line down-mouse-3]
(powerline-mouse 'minor 'menu mm))
map)))
(split-string (format-mode-line minor-mode-alist))
(propertize " " 'face face)))
(pl/filter-minor-modes (split-string (format-mode-line minor-mode-alist)))
(propertize " " 'face face)
))

;;;###autoload (autoload 'powerline-narrow "powerline")
(defpowerline powerline-narrow
Expand Down Expand Up @@ -604,6 +635,22 @@ static char * %s[] = {
'face (plist-get (cdr item) :face)))
(item item)))

(defun pl/filter-minor-modes (mlist)
"Filter minor mode indicators in MLIST."
(if (and (not (equal powerline-minor-mode-filter-regexp-list nil))
(< 0 (length powerline-minor-mode-filter-regexp-list)))
(if (equal powerline-minor-mode-filter-mode 'include)
(setq mlist (cl-delete-if-not #'pl/minor-mode-filter-list-match-p mlist))
(setq mlist (cl-delete-if #'pl/minor-mode-filter-list-match-p mlist))))
(identity mlist))

(defun pl/minor-mode-filter-list-match-p (str)
"Returns t if STR matches at least one of the regular expressions in ‘powerline-minor-mode-filter-regexp-list’, otherwise nil."
(let (foundp)
(cl-dolist (rgx powerline-minor-mode-filter-regexp-list)
(if (string-match rgx str) (setq foundp t)))
(identity foundp)))

(defun powerline-render (values)
"Render a list of powerline VALUES."
(mapconcat 'pl/render values ""))
Expand Down