[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/page-break-lines a74fba388e 04/80: Convert to separate min
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/page-break-lines a74fba388e 04/80: Convert to separate minor-mode and global-minor-mode variants. |
Date: |
Tue, 5 Sep 2023 04:03:03 -0400 (EDT) |
branch: elpa/page-break-lines
commit a74fba388e782cc3b1a4db2e50570ce46788708a
Author: Steve Purcell <steve@sanityinc.com>
Commit: Steve Purcell <steve@sanityinc.com>
Convert to separate minor-mode and global-minor-mode variants.
---
README.md | 5 +++-
page-break-lines.el | 74 ++++++++++++++++++++++++++++++++++++-----------------
2 files changed, 55 insertions(+), 24 deletions(-)
diff --git a/README.md b/README.md
index a666237ba1..d4bb4b8032 100644
--- a/README.md
+++ b/README.md
@@ -15,10 +15,13 @@ then `(require 'page-break-lines)`.
Usage
=====
-Enable `page-break-lines-mode` globally like this:
+Enable `page-break-lines-mode` in an individual buffer like this:
(turn-on-page-break-lines-mode)
+Alternatively, customize `page-break-lines-modes` and enable the mode globally
with
+`global-page-break-lines-mode`.
+
[marmalade]: http://marmalade-repo.org
[melpa]: http://melpa.milkbox.net
diff --git a/page-break-lines.el b/page-break-lines.el
index fec2447722..27cbc704ad 100644
--- a/page-break-lines.el
+++ b/page-break-lines.el
@@ -25,10 +25,14 @@
;; This library provides a global mode which displays form feed
;; characters as horizontal rules.
-;; Adapted from http://www.emacswiki.org/emacs/PageBreaks
+;; Install from Melpa or Marmalade, or add to `load-path' and use
+;; (require 'page-break-lines).
+
+;; Use `page-break-lines-mode' to enable the mode in specific buffers,
+;; or customize `page-break-lines-modes' and enable the mode globally with
+;; `global-page-break-lines-mode'.
-;; TODO:
-;; * Allow selective enabling/disabling in certain modes
+;; Adapted from http://www.emacswiki.org/emacs/PageBreaks
;; Known issues:
;; * fill-column-indicator.el does not work properly when page-break-lines-mode
@@ -43,6 +47,12 @@
(defcustom page-break-lines-char ?─
"Character used to render page break lines."
+ :type 'character
+ :group 'page-break-lines)
+
+(defcustom page-break-lines-modes '(emacs-lisp-mode compilation-mode)
+ "Modes in which to enable `page-break-lines-mode'."
+ :type '(repeat symbol)
:group 'page-break-lines)
(defface page-break-lines-face
@@ -53,22 +63,24 @@ is available in that variant of your font, otherwise it may
be
displayed as a junk character."
:group 'page-break-lines)
-(defun page-break-lines--make-display-table-entry (window)
- "Make an appropriate display table entry for form feeds."
- (when page-break-lines-mode
- (vconcat (mapcar (lambda (c)
+
+
+(defun page-break-lines--update-display-table (window)
+ "Modify a display-table that displays page-breaks prettily.
+If the buffer inside WINDOW has `page-break-lines-mode' enabled,
+its display table will be modified as necessary."
+ (with-current-buffer (window-buffer window)
+ (if page-break-lines-mode
+ (progn
+ (unless buffer-display-table
+ (setq buffer-display-table (make-display-table)))
+ (aset buffer-display-table ?\^L
+ (vconcat (mapcar (lambda (c)
(make-glyph-code c 'page-break-lines-face))
(make-list (1- (window-width window))
page-break-lines-char)))))
-
-(defun page-break-lines--update-display-table (window)
- "Create a display-table that displays page-breaks prettily."
- (set-window-display-table
- window
- (let ((table (or (copy-sequence (window-display-table window))
- (make-display-table))))
- (aset table ?\^L (page-break-lines--make-display-table-entry window))
- table)))
+ (when buffer-display-table
+ (aset buffer-display-table ?\^L nil)))))
(defun page-break-lines--update-display-tables ()
"Function called for updating display table."
@@ -82,24 +94,40 @@ displayed as a junk character."
In Page Break mode, page breaks (^L characters) are displayed as a
horizontal line of `page-break-string-char' characters."
- :global t
:lighter " PgLn"
- (page-break-lines--update-display-tables)
- (if page-break-lines-mode
- (add-hook 'window-configuration-change-hook
- 'page-break-lines--update-display-tables)
- (remove-hook 'window-configuration-change-hook
- 'page-break-lines--update-display-tables)))
+ :group 'page-break-lines
+ (page-break-lines--update-display-tables))
;;;###autoload
(defun turn-on-page-break-lines-mode ()
+ "Enable `page-break-lines-mode' in this buffer."
(page-break-lines-mode 1))
;;;###autoload
(defun turn-off-page-break-lines-mode ()
+ "Disable `page-break-lines-mode' in this buffer."
(page-break-lines-mode -1))
+(add-hook 'window-configuration-change-hook
+ 'page-break-lines--update-display-tables)
+
+
+
+;;;###autoload
+(defun page-break-lines-mode-maybe ()
+ "Enable `page-break-lines-mode' in the current buffer if desired.
+When `major-mode' is listed in `page-break-lines-modes', then
+`page-break-lines-mode' will be enabled."
+ (if (and (not (minibufferp (current-buffer)))
+ (memq major-mode page-break-lines-modes))
+ (page-break-lines-mode 1)))
+
+(define-global-minor-mode global-page-break-lines-mode
+ page-break-lines-mode page-break-lines-mode-maybe
+ :group 'page-break-lines)
+
+
(provide 'page-break-lines)
;; Local Variables:
- [nongnu] elpa/page-break-lines 34cd91d841 73/80: Fix other link, (continued)
- [nongnu] elpa/page-break-lines 34cd91d841 73/80: Fix other link, ELPA Syncer, 2023/09/05
- [nongnu] elpa/page-break-lines e9fe243810 32/80: Prefer Package-Version header to Version, ELPA Syncer, 2023/09/05
- [nongnu] elpa/page-break-lines 2b8b800e1d 36/80: Merge pull request #8 from peniblec/mode-line-indicator, ELPA Syncer, 2023/09/05
- [nongnu] elpa/page-break-lines a550e8d534 65/80: Add CI, ELPA Syncer, 2023/09/05
- [nongnu] elpa/page-break-lines 29f9314f8e 47/80: Handle the new native display-line-number functionality, ELPA Syncer, 2023/09/05
- [nongnu] elpa/page-break-lines 4e5034de4b 43/80: Adjust the length according to the width of page-break-lines-char, ELPA Syncer, 2023/09/05
- [nongnu] elpa/page-break-lines 6f19d894bd 59/80: Merge pull request #22 from camdez/max-width, ELPA Syncer, 2023/09/05
- [nongnu] elpa/page-break-lines 28783cd6b8 76/80: Replace deprecated function name in README, ELPA Syncer, 2023/09/05
- [nongnu] elpa/page-break-lines f8c4cd7fc6 68/80: Add Emacs 27.1 to CI, ELPA Syncer, 2023/09/05
- [nongnu] elpa/page-break-lines cff419b126 01/80: Initial commit, ELPA Syncer, 2023/09/05
- [nongnu] elpa/page-break-lines a74fba388e 04/80: Convert to separate minor-mode and global-minor-mode variants.,
ELPA Syncer <=
- [nongnu] elpa/page-break-lines 24fee30edf 70/80: Merge pull request #32 from MicahElliott/master, ELPA Syncer, 2023/09/05
- [nongnu] elpa/page-break-lines d310e75652 05/80: Rename face from page-break-lines-face to page-break-lines, ELPA Syncer, 2023/09/05
- [nongnu] elpa/page-break-lines 58c0dd0ace 10/80: Add blog/twitter links, ELPA Syncer, 2023/09/05
- [nongnu] elpa/page-break-lines 908581b869 23/80: Shorten rule width slightly when word-wrap is on (see #5), ELPA Syncer, 2023/09/05
- [nongnu] elpa/page-break-lines 55d36c6af4 12/80: Merge pull request #1 from lunaryorn/patch-1, ELPA Syncer, 2023/09/05
- [nongnu] elpa/page-break-lines 87e801efb8 55/80: Merge pull request #20 from peniblec/master, ELPA Syncer, 2023/09/05
- [nongnu] elpa/page-break-lines 82f9100312 46/80: Merge pull request #15 from xiongtx/autoload-defcustom, ELPA Syncer, 2023/09/05
- [nongnu] elpa/page-break-lines 2e1d274e11 60/80: Prefer "elisp" for code blocks, ELPA Syncer, 2023/09/05
- [nongnu] elpa/page-break-lines 31f1fbe0e3 62/80: Prefer set-display-table-slot to raw aset, ELPA Syncer, 2023/09/05
- [nongnu] elpa/page-break-lines c82759f267 50/80: Add Patreon badge, ELPA Syncer, 2023/09/05