|
166 | 166 | (right-list (reverse jcs-modeline-right))) |
167 | 167 | (setq jcs-modeline--render-left nil |
168 | 168 | jcs-modeline--render-right nil) ; reset |
| 169 | + ;; Loop through the entire `left' + `right' list |
169 | 170 | (while (< count (length (append jcs-modeline-left jcs-modeline-right))) |
170 | | - (when (or (and is-left (<= (length jcs-modeline-left) left-index)) |
171 | | - (and (not is-left) (<= (length jcs-modeline-right) right-index))) |
| 171 | + ;; Check if the index exceed it's length, then flip the left/right |
| 172 | + ;; toggle variable `is-left' to ensure we iterate through the whole |
| 173 | + ;; render list! |
| 174 | + (when (<= (length (if is-left jcs-modeline-left jcs-modeline-right)) |
| 175 | + (if is-left left-index right-index)) |
172 | 176 | (setq is-left (not is-left))) |
| 177 | + ;; Select the item, check the length and add it to the render list! |
173 | 178 | (let* ((item (nth (if is-left left-index right-index) |
174 | 179 | (if is-left jcs-modeline-left right-list))) |
175 | 180 | (format (format-mode-line item)) |
176 | 181 | (width (jcs-modeline--str-len format)) |
177 | 182 | (new-width (+ current-width width))) |
178 | | - (when (<= new-width (window-width)) |
179 | | - (setq current-width new-width) |
| 183 | + ;; Can the new item added to the list? |
| 184 | + (when (<= new-width (window-width)) ; can be displayed properly! |
| 185 | + (setq current-width new-width) ; update string/display width |
| 186 | + ;; Add the item to render list! |
180 | 187 | (push item (if is-left jcs-modeline--render-left |
181 | 188 | jcs-modeline--render-right)))) |
182 | | - (cl-incf (if is-left left-index right-index)) |
| 189 | + (cl-incf (if is-left left-index right-index)) ; increment index |
183 | 190 | (cl-incf count) |
184 | | - (setq is-left (not is-left)))) |
| 191 | + (setq is-left (not is-left)))) ; flip `left' and `right' |
185 | 192 | (setq jcs-modeline--render-left (reverse jcs-modeline--render-left) |
186 | 193 | ;; Since we iterate it from the edge, we don't need to reverse the right |
187 | 194 | jcs-modeline--render-right jcs-modeline--render-right)) |
|
0 commit comments