summaryrefslogtreecommitdiff
path: root/modeline.el
diff options
context:
space:
mode:
authorJSDurand <mmemmew@gmail.com>2021-01-23 00:23:05 +0800
committerJSDurand <mmemmew@gmail.com>2021-01-24 00:49:45 +0800
commit2066e827155ae2893097360024ffd975166a44ef (patch)
treee15bb118a4a0e622575847c05ef1dcfae30e58ef /modeline.el
parent588b6031e152b031be1dee04c7b38938ea7eb706 (diff)
More custom functions and adjust for custom completion framework
* LICENSE: Add GPLv3. * basic.el (durand-enlarge-window): (durand-shrink-window): (durand-enlarge-window-horizontally): (durand-shrink-window-horizontally): Now I can easily maximize or minimize windows. * comb/orderless-conf.el ("orderless"): Now I try to use my own completion framework. * common.el (durand-embark-scroll-down-or-go-to-completions): (durand-embark-scroll-up-or-go-to-completions): (durand-completion-scroll-down-or-go-to-minibuffer): (durand-completion-scroll-up-or-go-to-minibuffer): Move these functions here since they do not belong to the completion framework in my opinion. (register): (register-val-jump-to): Rewrite this method so that it does not have to ask me if I want to open a file while jumping. * completion-conf.el: My intended completion framework, which is still work in progress. * init.el ("comb/orderless-conf.el"): ("completion-conf.el"): Adjust things accordingly. ("durand-simple"): My custom functions for viewing and for opening things. * modeline.el (modeline-propertize): (modeline-format-minor-modes): (modeline-format-major-mode): Now the macro `modeline-propertize' won't override properties that it does not intend to define. This has the effect that the properties of the original constructs will go through and have effect. (modeline-format-main): Make sure the space has a positive length. (modeline-format-buffer-name): Make sure the length does not exceed half the width of the window.
Diffstat (limited to 'modeline.el')
-rw-r--r--modeline.el72
1 files changed, 43 insertions, 29 deletions
diff --git a/modeline.el b/modeline.el
index 212db07..12893ea 100644
--- a/modeline.el
+++ b/modeline.el
@@ -8,10 +8,12 @@
(left-len (length left))
(right-len (length right))
(middle (propertize " " 'display
- (make-string (- (window-total-width)
- left-len
- right-len)
- 32))))
+ (make-string
+ (max (- (window-total-width)
+ left-len
+ right-len)
+ 0)
+ 32))))
(concat left middle right)))
(setq-default mode-line-format '("%e" (:eval (modeline-format-main))))
@@ -22,7 +24,9 @@
(concat
;; (modeline-format-bar)
(modeline-spc)
- (modeline-format-directory)))
+ (modeline-format-directory)
+ (modeline-spc)
+ (modeline-format-minor-modes)))
;;;###autoload
(defun modeline-format-left ()
@@ -56,11 +60,14 @@
MOUSE-FACE is used when the mouse is over the text.
HELP-ECHO is the additional information displayed when the mouse is over the text.
MAP is the local keymap of the text."
- (let ((mouse-face (or mouse-face 'mode-line-highlight)))
- `(propertize ,str
- 'mouse-face ',mouse-face
- 'help-echo ,help-echo
- 'local-map ,map)))
+ (let ((mouse-face (or mouse-face 'mode-line-highlight))
+ (help-echo-form (cond (help-echo (list (quote 'help-echo) help-echo))))
+ (map-form (cond (map (list (quote 'local-map) map)))))
+ (append
+ `(propertize ,str
+ 'mouse-face ',mouse-face)
+ help-echo-form
+ map-form)))
;;; Determination of the active mode-line
@@ -377,12 +384,16 @@ W is the width, H is the height of the bar."
"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)))))
+ (let* ((raw
+ (format-mode-line
+ minor-mode-alist
+ (cond
+ ((modeline-active-window-p) 'mode-line)
+ ('mode-line-inactive))))
+ (orig (cond
+ ((and (not (string= raw ""))
+ (= (aref raw 0) 32)) (substring raw 1))
+ (raw))))
(cond
((<= (length orig) modeline-minor-modes-name-len-max)
orig)
@@ -446,13 +457,15 @@ This will be displayed in the mode line."
(modeline-propertize
(let* ((face (cond ((modeline-active-window-p) 'mode-line-buffer-id)
(t 'mode-line-inactive)))
+ (name-max (min modeline-buffer-name-len-max
+ (floor (window-width) 2)))
(orig (format-mode-line "%b" face)))
(concat
(format-mode-line "%[" face)
(cond
- ((> (length orig) modeline-buffer-name-len-max)
+ ((> (length orig) name-max)
(concat
- (substring orig 0 (- modeline-buffer-name-len-max 3))
+ (substring orig 0 (max (- name-max 3) 1))
"..."))
(t orig))
(format-mode-line "%]" face)))
@@ -466,17 +479,18 @@ This will be displayed in the mode line."
(defun modeline-format-major-mode ()
"The major mode to display in the mode line."
(declare (pure t) (side-effect-free t))
- (concat
- (modeline-propertize
- (format-mode-line
- '("%m" global-mode-string)
- (cond ((modeline-active-window-p)
- 'doom-modeline-buffer-major-mode)
- (t 'mode-line-inactive)))
- nil
- "Major mode\nmouse-1: Display major mode menu\nmouse-2: Show help for major mode\nmouse-3: Toggle minor modes"
- mode-line-major-mode-keymap)
- (modeline-spc)))
+ (let ((face (cond ((modeline-active-window-p) 'doom-modeline-buffer-major-mode)
+ ('mode-line-inactive))))
+ (concat
+ (modeline-propertize
+ (format-mode-line '("%m") face)
+ nil
+ "Major mode\nmouse-1: Display major mode menu\nmouse-2: Show help for major mode\nmouse-3: Toggle minor modes"
+ mode-line-major-mode-keymap)
+ (modeline-spc)
+ (modeline-propertize
+ (format-mode-line global-mode-string face))
+ (modeline-spc))))
;;;###autoload
(defvar-local modeline-vcs-str ""