1

I managed to display the current buffer and complete file path in the title bar with the following snippet

(setq frame-title-format
                            '(buffer-file-name "%b - %f" ; File buffer
                          '(line-number-at-pos
                                             )))

But the line-number-at-pos does not work, i.e. the current line number is not displayed. What am I doing wrong here?

Also, is there an efficient way to display the lines of code in the currently visited file as well?

1 Answer 1

1

Interesting that the %l is indeed ignored for the frame-title-format. But you can wrap line-number-at-pos in an eval form and return a string:

(setq frame-title-format
      '("%b - %f " (:eval (number-to-string (line-number-at-pos)))))

;; To have it working on line change you have to add this to post-command-hook:
(add-hook 'post-command-hook
          #'(lambda () (setq frame-title-format
      '("%b - %f " (:eval (number-to-string (line-number-at-pos)))))))

;; To add total line count, use this instead (remove above hook first)
(add-hook 'post-command-hook
          #'(lambda () (setq frame-title-format
      '("%b - %f " (:eval (number-to-string (line-number-at-pos))) ":"
        (:eval (number-to-string (count-lines (point-min) (point-max))))))))

To display lines of code you can activate display-line-numbers-mode.

6
  • thanks. Unfortunately this does not update dynamically but only upon certain actions like e.g. isearch
    – CD86
    Jun 23 at 15:14
  • as for the total number of lines per file, I dont want to have visual noise in the form of a large column with line numbers but rather one integer which specifies the total line numbers
    – CD86
    Jun 23 at 15:20
  • see a working example now. Since changing the line numbers dynamically requires a refresh, you have to somehow add the the expression to a hook
    – dangom
    Jun 23 at 17:11
  • many thanks good sir!
    – CD86
    Jun 23 at 19:24
  • still does not update upon using c-n and c-p oO
    – CD86
    Jun 27 at 7:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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