diff options
author | Thierry Volpiatto <thierry.volpiatto@gmail.com> | 2018-10-02 06:59:18 +0200 |
---|---|---|
committer | Thierry Volpiatto <thierry.volpiatto@gmail.com> | 2018-10-02 06:59:18 +0200 |
commit | cfa78aab0f5b9064d015e75e1f372b5e2c59d838 (patch) | |
tree | 8cb3a194f42d8aa9770f4281c2262b83cbb6e554 /helm-buffers.el | |
parent | 5bca5679ea6ac60c63182e0153f5ca521ae5fcf3 (diff) |
New user var to prevent using format-mode-line (#2089)
as much as possible.
* helm-buffers.el (helm-buffer--pretty-names): New alist.
(helm-buffer--format-mode-name): New.
(helm-buffer--details): Use it.
(helm-buffers-list--init): Use it.
Diffstat (limited to 'helm-buffers.el')
-rw-r--r-- | helm-buffers.el | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/helm-buffers.el b/helm-buffers.el index a5e3deba..65f37359 100644 --- a/helm-buffers.el +++ b/helm-buffers.el @@ -107,6 +107,18 @@ this source is accessible and properly loaded." "Separator for columns in buffer listing." :type 'string :group 'helm-buffers) + +(defcustom helm-buffer--pretty-names '((dired-mode . "Dired") + (lisp-interaction-mode . "Lisp Inter")) + "An alist specifying pretty names for modes. +Most of the time buffer's `mode-name' is a string so no need to add it +here as there is no need to compute it, but sometimes it may be a +mode-line specification which may be costly to compute, in this case +add here the pretty name as a string to avoid this costly computation. +Also if some pretty names are too long you can add your own +abbreviation here." + :type '(alist :key-type symbol :value-type string) + :group 'helm-buffers) ;;; Faces ;; @@ -242,10 +254,7 @@ Note that this variable is buffer-local.") (helm-attr 'candidates) helm-source-buffers-list)) maximize (length b) into len-buf - maximize (length (with-current-buffer b - (if (stringp mode-name) - mode-name - (format-mode-line mode-name)))) + maximize (length (helm-buffer--format-mode-name b)) into len-mode finally return (cons len-buf len-mode)))) (unless (default-value 'helm-buffer-max-length) @@ -361,9 +370,17 @@ See `ido-make-buffer-list' for more infos." (format "(in `%s')" dir)) 'face face2))))) +(defun helm-buffer--format-mode-name (buf) + "Prevent using `format-mode-line' as much as possible." + (with-current-buffer buf + (helm-acond ((assq major-mode helm-buffer--pretty-names) + (cdr it)) + ((stringp mode-name) mode-name) + (t (format-mode-line mode-name))))) + (defun helm-buffer--details (buffer &optional details) (require 'dired) - (let* ((mode (with-current-buffer buffer (format-mode-line mode-name))) + (let* ((mode (helm-buffer--format-mode-name buffer)) (buf (get-buffer buffer)) (size (propertize (helm-buffer-size buf) 'face 'helm-buffer-size)) |