So I started using the powerline addon for emacs, and I noticed that among other things, by default it hides the page number of the pdf file (for instance P1/4) in the mode line. Is there any way to configure powerline to put that feature back? I like being able to see how long the pdf document is (not to mention, it doubles as a download counter when viewing pdfs through eww).
2 Answers
You can define your own powerline theme.
Just look into M-x find-library
RET powerline-themes.el
RET, copy the theme function of your joice to your init file and insert
(powerline-raw mode-line-position face0 'l)
at an appropriate place.
Note, that you should always (require 'powerline)
before setting a theme. Otherwise you cannot revert the powerline to the normal emacs version.
Maybe, it is wise to add (require 'powerline)
behind the (interactive)
form of your customized theme function.
If you do not like to define a whole powerline theme you can also add mode-line-position
to an existing theme with the following Elisp snippet.
It is demonstrated with powerline-default-theme
, but you can apply it to other themes with small obvious modifications.
(require 'powerline)
(defun find-branch (node tree)
"Find the cons with car NODE in TREE."
(catch 'found
(cl-nsublis (list (list node)) tree
:test (lambda (ref item)
(when (and
(listp item)
(equal ref (car item)))
(throw 'found item))))
nil))
;; Test:
;; (find-branch 'lhs mode-line-format)
;; (find-branch 'gotcha '(first (second gotcha third)))
(defun add-car (list car &rest cars)
"Add CAR as first element of LIST by modifying it.
May also be applied to an argument list of CARS."
(if cars
(dolist (next-car (nreverse (cons car cars)))
(add-car list next-car))
(setcdr list (cons (car list) (cdr list)))
(setcar list car))
list)
;; (let ((l (list -1 1 2 3))) (add-car (cdr l) 0) l)
;; (let ((l (list -1 1 2 3))) (add-car (cdr l) -0.5 0 0.5) l)
(defun my-powerline-add-position ()
"Add mode-line-position to powerline."
(let ((branch (cdadr (find-branch 'lhs mode-line-format))))
(unless (find-branch 'mode-line-position branch)
(add-car (cl-member 'powerline-buffer-id branch :key 'car)
'(powerline-raw mode-line-position face0 'r)))))
(advice-add 'powerline-default-theme :after #'my-powerline-add-position)
I noticed the same thing today when testing telephone-line, spaceline or simple-modeline
The one that worked out-of-the-box was doom-modeline (See screenshot below).
From the installation instructions it is only necessary to add the following lines to the init.el
file:
(require 'doom-modeline)
(doom-modeline-mode 1)
In my case I use straight.el
so the following is the code I use. No extra configuration is needed to show the page number.
(use-package doom-modeline
:straight (doom-modeline :type git
:flavor melpa
:host github
:repo "seagle0128/doom-modeline")
:init (doom-modeline-mode 1)
)