diff options
Diffstat (limited to 'modeline.el')
-rw-r--r-- | modeline.el | 68 |
1 files changed, 65 insertions, 3 deletions
diff --git a/modeline.el b/modeline.el index 62e4781..46d9080 100644 --- a/modeline.el +++ b/modeline.el @@ -36,7 +36,9 @@ (modeline-spc) (modeline-format-position) (modeline-spc) - (modeline-format-buffer-size))) + (modeline-format-buffer-size) + (modeline-spc) + (modeline-format-minor-modes))) ;;;###autoload (defun modeline-format-right () @@ -360,14 +362,74 @@ W is the width, H is the height of the bar." (format-mode-line (file-size-human-readable (string-to-number (format-mode-line "%i"))) (cond - ((modeline-active-window-p) - 'mode-line) + ((modeline-active-window-p) 'mode-line) (t 'mode-line-inactive))) nil "Buffer size\nmouse-1: Display Line and Column Mode Menu" mode-line-column-line-number-mode-map)) ;;;###autoload +(defvar modeline-minor-modes-name-len-max 150 + "The maximal length for the display of minor modes in the mode line.") + +;;;###autoload +(defun modeline-format-minor-modes () + "Display some minor modes information." + (declare (pure t) (side-effect-free t)) + (modeline-propertize + (let ((orig + (format-mode-line + minor-mode-alist + (cond + ((modeline-active-window-p) 'mode-line) + ('mode-line-inactive))))) + (cond + ((<= (length orig) modeline-minor-modes-name-len-max) + orig) + ((concat + (substring orig 0 (- modeline-minor-modes-name-len-max + 3)) + "...")))) + nil + "Minor mode +mouse-1: Display minor mode menu +mouse-2: Show help for minor mode +mouse-3: Toggle minor modes" + mode-line-minor-mode-keymap)) + +;;; NOTE: The minor mode menu does not work with my custom mode line. + +;;;###autoload +(defun durand-mouse-minor-mode-menu (event) + "Show minor-mode menu for EVENT on minor modes area of the mode line. +Modified for my custom mode line." + (interactive "@e") + (let* ((string-obj (nth 4 (car (cdr event)))) + (str (car string-obj)) + (str-pos (cdr string-obj)) + invalid indicator) + (cond + ((string= str "") (setq invalid t)) + ((= (aref str str-pos) 32) (setq str-pos (1+ str-pos)))) + (cond + (invalid) + ((= (aref str str-pos) 32)) + (t + (let* ((orig str-pos) + (start str-pos) + (end str-pos)) + (while (and (>= start 0) + (/= (aref str start) 32)) + (setq start (1- start))) + (while (and (< end (length str)) + (/= (aref str end) 32)) + (setq end (1+ end))) + (setq indicator (substring-no-properties str (1+ start) end)) + (minor-mode-menu-from-indicator indicator)))))) + +(advice-add 'mouse-minor-mode-menu :override #'durand-mouse-minor-mode-menu) + +;;;###autoload (defvar modeline-buffer-name-len-max 50 "The maximal length of the name of the buffer to be displayed in the mode line.") |