Given the following modeline configuration:

(setq-default mode-line-format
   (list
    ;; Current buffer name
    "%b "
    ;; Major mode
    "[%m] "
    ;; Modified status
    "[%*] "
    ;; Cursor position
    "Line: %l/%i Column: %c"))

I would like for the last item to appear right-aligned.

share|improve this question
1  
Here is a link to a related thread: stackoverflow.com/q/16775855/2112489 – lawlist Dec 18 '14 at 16:53
1  
Since you asked for a specific mode-line-format this isn't a proper answer, but smart-mode-line right-aligns the mode-line-misc-info by default, and it can right-align the list of minor-modes by setting sml/mode-width to 'right. – Malabarba Dec 18 '14 at 21:51

Like the answer in the comments, you can do this yourself by writing code to return a nicely spaced string.

Here is a simple way that supports only left and right aligned text applied to your specifications.

;; write a function to do the spacing
(defun simple-mode-line-render (left right)
  "Return a string of `window-width' length containing LEFT, and RIGHT
 aligned respectively."
  (let* ((available-width (- (window-width) (length left) 2)))
    (format (format " %%s %%%ds " available-width) left right)))


;; use the function in conjunction with :eval and format-mode-line in your mode-line-format
(setq mode-line-format
      '((:eval (simple-mode-line-render
                ;; left
                (format-mode-line "%b [%m] [%*]")
                ;; right
                (format-mode-line "Line: %l/%i Column: %c")))))

it ends up looking like this: enter image description here

Also note, I used your mode-line-format args as you specified, but I believe your are using %i incorrectly, which prints the byte size of the buffer, not the number of lines. You can use something like (line-number-at-pos (point-max)) to get the number of lines in your buffer.

share|improve this answer
    
One addition - you need to use window-total-width to calculate also linum and fringes additional paddings. – sandric Jul 16 '16 at 22:59

This isn't supported out-of-the-box but the smart-mode-line package does support this. You could either use that package, or if it does more than what you want, extract just the bits that implement the feature you are asking for.

share|improve this answer
    
Since the op did not follow up, I have turned @Malabarba's comment into an answer. This way the question isn't "unanswered" and this package might very well be what other users having the same question would want to use. – tarsius Jan 18 '15 at 11:14
    
That's what I ended up doing, extracting the relevant functionality from smart-mode-line and adding it to my dotemacs. It requires me figuring out how much space I want to the right, but it's better than nothing. Unless someone posts a way to get rid of the manual char counting, I won't accept an answer, though. – mkaito Jan 18 '15 at 15:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.