[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/visual-fill-column 99d78162d9 107/137: Add `visual-fill-co
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/visual-fill-column 99d78162d9 107/137: Add `visual-fill-column-offset`. |
Date: |
Sun, 2 Jan 2022 22:59:17 -0500 (EST) |
branch: elpa/visual-fill-column
commit 99d78162d9a524340607c11500ddc8cf6607d3c0
Author: Joost Kremers <joostkremers@fastmail.fm>
Commit: Joost Kremers <joostkremers@fastmail.fm>
Add `visual-fill-column-offset`.
The primary purpose of this option is to allow an offset in
`writeroom-mode`.
---
README.md | 4 +++-
test/visual-fill-column-test.el | 13 +++++++++++++
visual-fill-column.el | 42 ++++++++++++++++++++++++++++++++++++-----
3 files changed, 53 insertions(+), 6 deletions(-)
diff --git a/README.md b/README.md
index 911b284fc6..9922dabaf3 100644
--- a/README.md
+++ b/README.md
@@ -32,7 +32,7 @@ Note that while `visual-fill-column-mode` was written with
the purpose of wrappi
`visual-fill-column-mode` works by widening the right window margin. This
reduces the area that is available for text display, creating the appearance
that the text is wrapped at `fill-column`. The amount by which the right margin
is widened depends on the window width and is automatically adjusted when the
window’s width changes (e.g., when the window is split in two side-by-side
windows).
-In buffers that are explicitly right-to-left (i.e., those where
`bidi-paragraph-direction` is set to `right-to-left`), the left margin is
expanded, so that the text appears at the window’s right side.
+In buffers that are explicitly right-to-left (i.e., those where
`bidi-paragraph-direction` is set to `right-to-left`), the left margin is
expanded, so that the text appears at the window’s right side, and the meaning
of `visual-fill-column-offset` is reversed.
Widening the margin normally causes the fringes to be pushed inward. Since
this is visually less appealing, the fringes are placed outside the margins.
You can undo this by setting the variable
`visual-fill-column-fringes-outside-margins` to `nil`.
@@ -63,6 +63,8 @@ The customisation group `visual-fill-column` has four options
(beside `global-vi
`visual-fill-column-center-text`: if set to `t`, centre the text area in the
window. By default, the text is displayed at the window’s (left) edge,
mimicking the effect of `fill-column`.
+`visual-fill-column-offset`: offset the text area by a certain number of
columns. The value can be positive (offset to the left) or negative (offset to
the right). A negative value only makes sense if
`visual-fill-column-center-text` is set.
+
`visual-fill-column-fringes-outside-margins`: if set to `t`, put the fringes
outside the margins.
These three options are buffer-local, so the values you set in your init file
are default values. They can also be set in mode hooks or directory or file
local variables in order to customise particular files or file types.
diff --git a/test/visual-fill-column-test.el b/test/visual-fill-column-test.el
index 0d51b61457..bbd4071a25 100644
--- a/test/visual-fill-column-test.el
+++ b/test/visual-fill-column-test.el
@@ -1,3 +1,16 @@
;;; visual-fill-column-test.el --- Tests for visual-fill-column
+;;; Commentary:
+;; Tests for the visual-fill-column package.
+
+;;; Code:
+
+(require 'visual-fill-column)
+
+(ert-deftest visual-fill-column--calculate-margin-shift ()
+ (should (equal (visual-fill-column--calculate-margin-shift 0 80 4) '(4 .
76)))
+ (should (equal (visual-fill-column--calculate-margin-shift 10 80 -4) '(6 .
84)))
+ (should (equal (visual-fill-column--calculate-margin-shift 0 80 -4) '(0 .
80)))
+ (should (equal (visual-fill-column--calculate-margin-shift 80 0 4) '(80 .
0))))
+
;;; visual-fill-column-test.el ends here
diff --git a/visual-fill-column.el b/visual-fill-column.el
index 55742bbc3c..444cbc8560 100644
--- a/visual-fill-column.el
+++ b/visual-fill-column.el
@@ -66,6 +66,15 @@ this option is set to a value, it is used instead."
(make-variable-buffer-local 'visual-fill-column-center-text)
(put 'visual-fill-column-center-text 'safe-local-variable 'symbolp)
+(defcustom visual-fill-column-offset 0
+ "Number of columns to shift the text area.
+The text area is shifted to the right (positive value) or
+left (negative value). A negative value only makes sense if
+`visual-fill-column-center-text' is set."
+ :group 'visual-fill-column
+ :type '(integer :tag "Offset (in columns)"))
+(put 'visual-fill-column-center-text 'safe-local-variable 'integerp)
+
(defcustom visual-fill-column-inhibit-sensible-window-split nil
"Do not set `split-window-preferred-function' to allow vertical window
splits.
By default, `split-window-preferred-function' is set to
@@ -269,6 +278,24 @@ selected window. The return value is scaled to account for
0))
(float scale)))))
+(defun visual-fill-column--calculate-margin-shift (left right offset)
+ "Calculate new margins for LEFT and RIGHT based on OFFSET.
+OFFSET is added to LEFT and subtracted from RIGHT. If either
+value then becomes less than zero, it is set to zero and the
+other value is compensated for the difference.
+
+Return a cons cell of the new left and right margins."
+ (let ((shifted-left (+ left offset))
+ (shifted-right (- right offset)))
+ (cond
+ ((< shifted-left 0)
+ (setq shifted-right (+ shifted-right shifted-left))
+ (setq shifted-left 0))
+ ((< shifted-right 0)
+ (setq shifted-left (+ shifted-left shifted-right))
+ (setq shifted-right 0)))
+ (cons shifted-left shifted-right)))
+
(defun visual-fill-column--set-margins (window)
"Set window margins for WINDOW."
;; calculate left & right margins
@@ -283,11 +310,16 @@ selected window. The return value is scaled to account
for
0))
(right (- margins left)))
- ;; put an explicitly R2L buffer on the right side of the window
- (when (and (eq bidi-paragraph-direction 'right-to-left)
- (= left 0))
- (setq left right)
- (setq right 0))
+ (if (/= visual-fill-column-offset 0)
+ (let ((shift (visual-fill-column--calculate-margin-shift left right
visual-fill-column-offset)))
+ (setq left (car shift)
+ right (cdr shift))))
+
+ ;; In an explicitly R2L buffer, swap left and right margins.
+ (when (eq bidi-paragraph-direction 'right-to-left)
+ (setq left (prog1
+ right
+ (setq right left))))
(set-window-margins window left right)))
- [nongnu] elpa/visual-fill-column 96ac324638 031/137: Remove spurious empty line., (continued)
- [nongnu] elpa/visual-fill-column 96ac324638 031/137: Remove spurious empty line., ELPA Syncer, 2022/01/02
- [nongnu] elpa/visual-fill-column 4329831dd0 030/137: Add alternative function for `split-window-preferred-function'., ELPA Syncer, 2022/01/02
- [nongnu] elpa/visual-fill-column 9cae9dbfd9 041/137: Set window-parameter `split-window' only in Emacs 25 and up., ELPA Syncer, 2022/01/02
- [nongnu] elpa/visual-fill-column 98438fa2b8 048/137: Update version number., ELPA Syncer, 2022/01/02
- [nongnu] elpa/visual-fill-column 57c2a72d46 053/137: Merge pull request #26 from sten0/master, ELPA Syncer, 2022/01/02
- [nongnu] elpa/visual-fill-column 8d1326de10 090/137: Update the README., ELPA Syncer, 2022/01/02
- [nongnu] elpa/visual-fill-column 6e9f35600d 099/137: Remove spurious line from `visual-fill-column--reset-window'., ELPA Syncer, 2022/01/02
- [nongnu] elpa/visual-fill-column a5332e9625 103/137: Update the README., ELPA Syncer, 2022/01/02
- [nongnu] elpa/visual-fill-column f7c0aab5c6 102/137: Splitting windows: get things right., ELPA Syncer, 2022/01/02
- [nongnu] elpa/visual-fill-column 4c86aebd2b 097/137: Make the argument of visual-fill-column--adjust-window optional., ELPA Syncer, 2022/01/02
- [nongnu] elpa/visual-fill-column 99d78162d9 107/137: Add `visual-fill-column-offset`.,
ELPA Syncer <=
- [nongnu] elpa/visual-fill-column 39cb7ab53d 118/137: Unconditionally clear `window-configuration-change-hook`., ELPA Syncer, 2022/01/02
- [nongnu] elpa/visual-fill-column 21eda77a66 123/137: Remove `visual-fill-column--adjust-all-windows`., ELPA Syncer, 2022/01/02
- [nongnu] elpa/visual-fill-column d55e95c109 132/137: visual-fill-column.el: Update Commentary section., ELPA Syncer, 2022/01/02
- [nongnu] elpa/visual-fill-column 6b7d8780f1 119/137: Use proper hooks according to Emacs version., ELPA Syncer, 2022/01/02
- [nongnu] elpa/visual-fill-column ae4edc225a 136/137: Fix alignment in doc string of visual-fill-column--add-extra-width, ELPA Syncer, 2022/01/02
- [nongnu] elpa/visual-fill-column 10d01fbb98 033/137: Update version number, ELPA Syncer, 2022/01/02
- [nongnu] elpa/visual-fill-column 4e294ea7a4 040/137: Explicitly refer to selected window in vsf-adjust-window., ELPA Syncer, 2022/01/02
- [nongnu] elpa/visual-fill-column 64d38bc1c0 088/137: Change layout of example for advising text-scale-adjust., ELPA Syncer, 2022/01/02
- [nongnu] elpa/visual-fill-column 2026fd2b9e 085/137: Fix typo in README.md, ELPA Syncer, 2022/01/02