Modeline: Use own variant of PDF modeline

There are a few changes here to improve the appearance of the PDF modeline:
+ Prioritise the page information, move segment in front of buffer name
+ Create (and use) new buffer-name segment, that doesn't include any
  mode or state information
+ Left-pad `doom-modeline--pdf-pages' to ensure that for a given PDF
  it's always the same width
+ Add a `pdf-icon' segment and place it in front of the buffer name
This commit is contained in:
TEC 2021-03-12 15:37:20 +08:00
parent 09ece2a303
commit a9e237a6c9
Signed by: tec
GPG Key ID: 779591AFDB81F06C
1 changed files with 49 additions and 0 deletions

View File

@ -1733,6 +1733,55 @@ We then configure the dictionary we're using in [[*Ispell][Ispell]].
#+begin_src emacs-lisp
(set-company-backend! 'ess-r-mode '(company-R-args company-R-objects company-dabbrev-code :separate))
#+end_src
** Doom modeline
Very nice and pretty, however I think the PDF modeline could do with tweaking.
I raised [[https://github.com/seagle0128/doom-modeline/pull/425][an issue]] on this, however the response was basically "put your
preferences in your personal config, the current default is sensible" --- so
here we are.
First up I'm going to want a segment for just the buffer file name, and a PDF
icon. Then we'll redefine two functions used to generate the modeline.
#+begin_src emacs-lisp
(after! doom-modeline
(doom-modeline-def-segment buffer-name
"Display the current buffer's name, without any other information."
(concat
(doom-modeline-spc)
(doom-modeline--buffer-name)))
(doom-modeline-def-segment pdf-icon
"PDF icon from all-the-icons."
(concat
(doom-modeline-spc)
(doom-modeline-icon 'octicon "file-pdf" nil nil
:face (if (doom-modeline--active)
'all-the-icons-red
'mode-line-inactive)
:v-adjust 0.02)))
(defun doom-modeline-update-pdf-pages ()
"Update PDF pages."
(setq doom-modeline--pdf-pages
(let ((current-page-str (number-to-string (eval `(pdf-view-current-page))))
(total-page-str (number-to-string (pdf-cache-number-of-pages))))
(concat
(propertize
(concat (make-string (- (length total-page-str) (length current-page-str)) ? )
" P" current-page-str)
'face 'mode-line)
(propertize (concat "/" total-page-str) 'face 'doom-modeline-buffer-minor-mode)))))
(doom-modeline-def-segment pdf-pages
"Display PDF pages."
(if (doom-modeline--active) doom-modeline--pdf-pages
(propertize doom-modeline--pdf-pages 'face 'mode-line-inactive)))
(doom-modeline-def-modeline 'pdf
'(bar window-number pdf-pages pdf-icon buffer-name)
'(misc-info matches major-mode process vcs)))
#+end_src
** Elcord
#+begin_src emacs-lisp
(setq elcord-use-major-mode-as-main-icon t)