Skip to content

Commit

Permalink
Better method for calculating line width, requiring Emacs 25.1+
Browse files Browse the repository at this point in the history
In Emacs 29, where `string-pixel-width` exists, the result should be
better still.
  • Loading branch information
purcell committed Jan 17, 2024
1 parent f4568cc commit e8bfd1a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ jobs:
strategy:
matrix:
emacs_version:
- 24.1
- 24.5
- 25.1
- 25.3
- 26.1
Expand Down
18 changes: 6 additions & 12 deletions page-break-lines.el
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
;; Author: Steve Purcell <[email protected]>
;; URL: https://github.com/purcell/page-break-lines
;; Package-Version: 0.15
;; Package-Requires: ((emacs "24.4"))
;; Package-Requires: ((emacs "25.1"))
;; Keywords: convenience, faces

;; This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -125,17 +125,11 @@ its display table will be modified as necessary."
(setq buffer-display-table (make-display-table)))
(let ((default-height (face-attribute 'default :height nil 'default)))
(set-face-attribute 'page-break-lines nil :height default-height)
(let* ((cwidth (char-width page-break-lines-char))
(wwidth-pix (- (window-width nil t)
(if (and (bound-and-true-p display-line-numbers)
(fboundp 'line-number-display-width))
(line-number-display-width t)
0)))
(width (- (/ wwidth-pix (frame-char-width) cwidth)
(if (display-graphic-p) 0 1)))
(width (if page-break-lines-max-width
(min width page-break-lines-max-width)
width))
(let* ((char-relative-width (if (fboundp 'string-pixel-width)
(/ (string-pixel-width (make-string 100 page-break-lines-char))
(string-pixel-width (make-string 100 ?a)))
(char-width page-break-lines-char)))
(width (floor (window-max-chars-per-line) char-relative-width))
(glyph (make-glyph-code page-break-lines-char 'page-break-lines))
(new-display-entry (vconcat (make-list width glyph))))
(unless (equal new-display-entry (elt buffer-display-table ?\^L))
Expand Down

0 comments on commit e8bfd1a

Please sign in to comment.