Codebase list page-break-lines-el / 9cb8ade
import upstream version 0.14 Martin 2 years ago
7 changed file(s) with 315 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 patreon: sanityinc
0 name: CI
1
2 on:
3 pull_request:
4 push:
5 paths-ignore:
6 - '**.md'
7
8 jobs:
9 build:
10 runs-on: ubuntu-latest
11 strategy:
12 matrix:
13 emacs_version:
14 - 24.1
15 - 24.2
16 - 24.3
17 - 24.4
18 - 24.5
19 - 25.1
20 - 25.2
21 - 25.3
22 - 26.1
23 - 26.2
24 - 26.3
25 - 27.1
26 - snapshot
27 steps:
28 - uses: purcell/setup-emacs@master
29 with:
30 version: ${{ matrix.emacs_version }}
31
32 - uses: actions/checkout@v1
33 - name: Run tests
34 run: make
0 /page-break-lines.elc
0 EMACS ?= emacs
1
2 # A space-separated list of required package names
3 NEEDED_PACKAGES = package-lint
4
5 INIT_PACKAGES="(progn \
6 (require 'package) \
7 (push '(\"melpa\" . \"https://melpa.org/packages/\") package-archives) \
8 (package-initialize) \
9 (dolist (pkg '(${NEEDED_PACKAGES})) \
10 (unless (package-installed-p pkg) \
11 (unless (assoc pkg package-archive-contents) \
12 (package-refresh-contents)) \
13 (package-install pkg))) \
14 )"
15
16 all: compile package-lint clean-elc
17
18 package-lint:
19 ${EMACS} -Q --eval ${INIT_PACKAGES} -batch -f package-lint-batch-and-exit page-break-lines.el
20
21 compile: clean-elc
22 ${EMACS} -Q --eval ${INIT_PACKAGES} -L . -batch -f batch-byte-compile *.el
23
24 clean-elc:
25 rm -f f.elc
26
27 .PHONY: all compile clean-elc package-lint
0 [![Melpa Status](https://melpa.org/packages/page-break-lines-badge.svg)](https://melpa.org/#/page-break-lines)
1 [![Melpa Stable Status](https://stable.melpa.org/packages/page-break-lines-badge.svg)](https://stable.melpa.org/#/page-break-lines)
2 [![Build Status](https://github.com/purcell/page-break-lines/workflows/CI/badge.svg)](https://github.com/purcell/page-break-lines/actions)
3 <a href="https://www.patreon.com/sanityinc"><img alt="Support me" src="https://img.shields.io/badge/Support%20Me-%F0%9F%92%97-ff69b4.svg"></a>
4
5 page-break-lines.el
6 ===================
7
8 This Emacs library provides a global mode which displays ugly form feed
9 characters as tidy horizontal rules.
10
11 Screenshot
12 ==========
13
14 ![page-break-lines screenshot](screenshot.png)
15
16 Installation
17 =============
18
19 If you choose not to use one of the convenient
20 packages in [MELPA](https://melpa.org), you'll need to
21 add the directory containing `page-break-lines.el` to your `load-path`, and
22 then `(require 'page-break-lines)`.
23
24 Usage
25 =====
26
27 Enable `page-break-lines-mode` in an individual buffer like this:
28
29 ```elisp
30 (turn-on-page-break-lines-mode)
31 ```
32
33 Alternatively, customize `page-break-lines-modes` and enable the mode globally with
34 `global-page-break-lines-mode`.
35
36 Note that Emacs already supports [β€œPages”](https://www.gnu.org/software/emacs/manual/html_node/emacs/Pages.html)
37 and jumping around between page breaks with `C-x [` (`backward-page`)
38 and `C-x ]` (`forward-page`).
39
40 Issues and limitations
41 ======================
42
43 If `page-break-lines-char` is displayed at a different width to
44 regular characters, the rule may be either too short or too long:
45 rules may then wrap if `truncate-lines` is nil. On some systems,
46 Emacs may erroneously choose a different font for the page break
47 symbol, which choice can be overridden using code such as:
48
49 ```elisp
50 (set-fontset-font "fontset-default"
51 (cons page-break-lines-char page-break-lines-char)
52 (face-attribute 'default :family))
53 ```
54
55 Use `describe-char` on a page break char to determine whether this
56 is the case.
57
58 Also see Vasilij Schneidermann's
59 [form-feed package](https://github.com/wasamasa/form-feed), which
60 works using font-lock instead of glyph composition, and therefore has
61 different display trade-offs.
62
63
64 <hr>
65
66 [πŸ’ Support this project and my other Open Source work](https://www.patreon.com/sanityinc)
67
68 [πŸ’Ό LinkedIn profile](https://uk.linkedin.com/in/stevepurcell)
69
70 [✍ sanityinc.com](http://www.sanityinc.com/)
71
72 [🐦 @sanityinc](https://twitter.com/sanityinc)
0 ;;; page-break-lines.el --- Display ^L page breaks as tidy horizontal lines -*- lexical-binding: t -*-
1
2 ;; Copyright (C) 2012-2015 Steve Purcell
3
4 ;; Author: Steve Purcell <steve@sanityinc.com>
5 ;; URL: https://github.com/purcell/page-break-lines
6 ;; Package-Version: 0
7 ;; Package-Requires: ((emacs "24.4"))
8 ;; Keywords: convenience, faces
9
10 ;; This program is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
14
15 ;; This program is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
22
23 ;;; Commentary:
24
25 ;; This library provides a global mode which displays form feed
26 ;; characters as horizontal rules.
27
28 ;; Install from Melpa or Marmalade, or add to `load-path' and use
29 ;; (require 'page-break-lines).
30
31 ;; Use `page-break-lines-mode' to enable the mode in specific buffers,
32 ;; or customize `page-break-lines-modes' and enable the mode globally with
33 ;; `global-page-break-lines-mode'.
34
35 ;; Issues and limitations:
36
37 ;; If `page-break-lines-char' is displayed at a different width to
38 ;; regular characters, the rule may be either too short or too long:
39 ;; rules may then wrap if `truncate-lines' is nil. On some systems,
40 ;; Emacs may erroneously choose a different font for the page break
41 ;; symbol, which choice can be overridden using code such as:
42
43 ;; (set-fontset-font "fontset-default"
44 ;; (cons page-break-lines-char page-break-lines-char)
45 ;; (face-attribute 'default :family))
46
47 ;; Use `describe-char' on a page break char to determine whether this
48 ;; is the case.
49
50 ;; Additionally, the use of `text-scale-increase' or
51 ;; `text-scale-decrease' will cause the rule width to be incorrect,
52 ;; because the reported window width (in characters) will continue to
53 ;; be the width in the frame's default font, not the scaled font used to
54 ;; display the rule.
55
56 ;; Adapted from code http://www.emacswiki.org/emacs/PageBreaks
57
58 ;;; Code:
59
60 (defgroup page-break-lines nil
61 "Display ugly ^L page breaks as tidy horizontal lines."
62 :prefix "page-break-lines-"
63 :group 'faces)
64
65 (defcustom page-break-lines-char ?─
66 "Character used to render page break lines."
67 :type 'character
68 :group 'page-break-lines)
69
70 (defcustom page-break-lines-lighter " PgLn"
71 "Mode-line indicator for `page-break-lines-mode'."
72 :type '(choice (const :tag "No lighter" "") string)
73 :group 'page-break-lines)
74
75 (defcustom page-break-lines-max-width nil
76 "If non-nil, maximum width (in characters) of page break indicator.
77 If nil, indicator will span the width of the frame."
78 :type '(choice integer (const :tag "Full width" nil))
79 :group 'page-break-lines)
80
81 (defcustom page-break-lines-modes
82 '(emacs-lisp-mode lisp-mode scheme-mode compilation-mode outline-mode help-mode)
83 "Modes in which to enable `page-break-lines-mode'."
84 :type '(repeat symbol)
85 :group 'page-break-lines)
86
87 (defface page-break-lines
88 '((t :inherit font-lock-comment-face :bold nil :italic nil))
89 "Face used to colorize page break lines.
90 If using :bold or :italic, please ensure `page-break-lines-char'
91 is available in that variant of your font, otherwise it may be
92 displayed as a junk character."
93 :group 'page-break-lines)
94
95
96
97 ;;;###autoload
98 (define-minor-mode page-break-lines-mode
99 "Toggle Page Break Lines mode.
100
101 In Page Break mode, page breaks (^L characters) are displayed as a
102 horizontal line of `page-break-lines-char' characters."
103 :lighter page-break-lines-lighter
104 :group 'page-break-lines
105 (page-break-lines--update-display-tables))
106
107 (dolist (hook '(window-configuration-change-hook
108 window-size-change-functions
109 after-setting-font-hook
110 display-line-numbers-mode-hook))
111 (add-hook hook 'page-break-lines--update-display-tables))
112
113
114
115 (defun page-break-lines--update-display-table (window)
116 "Modify a display-table that displays page-breaks prettily.
117 If the buffer inside WINDOW has `page-break-lines-mode' enabled,
118 its display table will be modified as necessary."
119 (with-current-buffer (window-buffer window)
120 (with-selected-window window
121 (if page-break-lines-mode
122 (progn
123 (unless buffer-display-table
124 (setq buffer-display-table (make-display-table)))
125 (let ((default-height (face-attribute 'default :height nil 'default)))
126 (set-face-attribute 'page-break-lines nil :height default-height)
127 (let* ((cwidth (char-width page-break-lines-char))
128 (wwidth-pix (- (window-width nil t)
129 (if (and (bound-and-true-p display-line-numbers)
130 (fboundp 'line-number-display-width))
131 (line-number-display-width t)
132 0)))
133 (width (- (/ wwidth-pix (frame-char-width) cwidth)
134 (if (display-graphic-p) 0 1)))
135 (width (if page-break-lines-max-width
136 (min width page-break-lines-max-width)
137 width))
138 (glyph (make-glyph-code page-break-lines-char 'page-break-lines))
139 (new-display-entry (vconcat (make-list width glyph))))
140 (unless (equal new-display-entry (elt buffer-display-table ?\^L))
141 (aset buffer-display-table ?\^L new-display-entry)))))
142 (when (and (apply 'derived-mode-p page-break-lines-modes)
143 buffer-display-table)
144 (aset buffer-display-table ?\^L nil))))))
145
146 (defun page-break-lines--update-display-tables (&optional frame)
147 "Function called for updating display table in windows of FRAME."
148 (unless (minibufferp)
149 (mapc 'page-break-lines--update-display-table (window-list frame 'no-minibuffer))))
150
151
152
153 ;;;###autoload
154 (defun page-break-lines-mode-maybe ()
155 "Enable `page-break-lines-mode' in the current buffer if desired.
156 When `major-mode' is listed in `page-break-lines-modes', then
157 `page-break-lines-mode' will be enabled."
158 (if (and (not (minibufferp))
159 (apply 'derived-mode-p page-break-lines-modes))
160 (page-break-lines-mode 1)))
161
162 ;;;###autoload
163 (define-global-minor-mode global-page-break-lines-mode
164 page-break-lines-mode page-break-lines-mode-maybe
165 :require 'page-break-lines
166 :group 'page-break-lines)
167
168
169 (provide 'page-break-lines)
170
171 ;; Local Variables:
172 ;; coding: utf-8
173 ;; checkdoc-minor-mode: t
174 ;; End:
175
176 ;;; page-break-lines.el ends here
Binary diff not shown