Skip to content

Commit

Permalink
refac(position): render default construct for {doc,pdf}-view
Browse files Browse the repository at this point in the history
  • Loading branch information
Walheimat committed Oct 11, 2023
1 parent 83a9522 commit af7fc3f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Changed

- Position segment now renders the default `mode-line-position`
construct if `doc-view` or `pdf-view` are used.

## [v0.7.3]

### Removed
Expand Down
8 changes: 3 additions & 5 deletions test/whale-line-segments-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,9 @@

(should (string= "(%l, %c)" (whale-line-segments--position--line-and-column)))))

(ert-deftest position--doc-view ()
(bydi ((:mock image-mode-window-get :return 1)
(:mock doc-view-last-page-number :return 42))

(should (string= "1/42" (whale-line-segments--position--doc-view)))))
(ert-deftest position--default ()
(bydi ((:mock format-mode-line :return " 2% 5/6"))
(should (string= "2%% 5/6" (whale-line-segments--position--default)))))

;;; -- Selection

Expand Down
25 changes: 15 additions & 10 deletions whale-line-segments.el
Original file line number Diff line number Diff line change
Expand Up @@ -145,23 +145,28 @@ to 2, only the 3rd level is elided."
;;;; -- Position

(defvar wls--position
'((doc-view--buffer-file-name
((:propertize (:eval (wls--position--doc-view))
'((pdf-view--server-file-name
((:propertize (:eval (wls--position--default))
face whale-line-shadow))

((:propertize ("" mode-line-percent-position)
face whale-line-shadow)
(:eval (whale-line--spacer))
(:propertize (:eval (wls--position--line-and-column)) face whale-line-shadow)))))
(doc-view--buffer-file-name
((:propertize (:eval (wls--position--default))
face whale-line-shadow))
((:propertize ("" mode-line-percent-position)
face whale-line-shadow)
(:eval (whale-line--spacer))
(:propertize (:eval (wls--position--line-and-column)) face whale-line-shadow))))))

(defun wls--position--line-and-column ()
"Get the line and column."
(when-let* ((format (car-safe mode-line-position-column-line-format)))
(string-trim format)))

(defun wls--position--doc-view ()
"Get the position in a document."
(format "%d/%d" (image-mode-window-get 'page) (doc-view-last-page-number)))
(defun wls--position--default ()
"Format the default `mode-line-position' construct."
(string-trim
(string-replace
"%" "%%"
(format-mode-line mode-line-position))))

(whale-line-create-stateless-segment position
:var wls--position
Expand Down

0 comments on commit af7fc3f

Please sign in to comment.