[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/visual-fill-column 4b903a0adb 002/137: Implement visual-fi
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/visual-fill-column 4b903a0adb 002/137: Implement visual-fill-column |
Date: |
Sun, 2 Jan 2022 22:59:07 -0500 (EST) |
branch: elpa/visual-fill-column
commit 4b903a0adb6479f82b8c4f9cb6e9335d229570d2
Author: Joost Kremers <joostkremers@fastmail.fm>
Commit: Joost Kremers <joostkremers@fastmail.fm>
Implement visual-fill-column
---
visual-fill-column.el | 141 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 141 insertions(+)
diff --git a/visual-fill-column.el b/visual-fill-column.el
new file mode 100644
index 0000000000..e66e887971
--- /dev/null
+++ b/visual-fill-column.el
@@ -0,0 +1,141 @@
+;;; visual-fill-column.el --- fill-column for visual-line-mode -*-
lexical-binding: t -*-
+
+;; Copyright (C) 2015 Joost Kremers
+;; All rights reserved.
+
+;; Author: Joost Kremers <joostkremers@fastmail.fm>
+;; Maintainer: Joost Kremers <joostkremers@fastmail.fm>
+;; Created: 2015
+;; Version: 1.0
+;; Package-Requires: ((emacs "24.3"))
+
+;; This file is NOT part of GNU Emacs.
+
+;; visual-fill-coulmn is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; visual-fill-coulmn is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;;
+
+;;; Code:
+
+(defgroup visual-fill-column nil "Wrap lines according to `fill-column' in
`visual-line-mode'."
+ :group 'wp
+ :prefix "visual-fill-column-")
+
+(defcustom visual-fill-column-width nil
+ "Width of the text area.
+By default, the global value of `fill-column' is used.
+Alternatively, the value can be specified relative to the window
+width. In this case, it must be a value between 0 and 1."
+ :group 'visual-fill-column
+ :type '(choice (const :tag "Use `fill-column'" nil)
+ (float :tag "Relative width:" :value 0.5)))
+(make-variable-buffer-local 'visual-fill-column-width)
+(put 'visual-fill-column-width 'safe-local-variable 'floatp)
+
+(defcustom visual-fill-column-disable-fringe t
+ "Disable the fringe when `visual-fill-column-mode' is active."
+ :group 'visual-fill-column
+ :type '(choice (const :tag "Do not disable the fringes" nil)
+ (const :tag "Disable the fringes' t")))
+(make-variable-buffer-local 'visual-fill-column-disable-fringe)
+(put 'visual-fill-column-disable-fringe 'safe-local-variable 'symbolp)
+
+(defcustom visual-fill-column-center-text nil
+ "If set, center the text area in the window."
+ :group 'visual-fill-column
+ :type '(choice (const :tag "Display text area at window margin" nil)
+ (const :tag "Center text area" t)))
+(make-variable-buffer-local 'visual-fill-column-center-text)
+(put 'visual-fill-column-center-text 'safe-local-variable 'symbolp)
+
+;;;###autoload
+(define-minor-mode visual-fill-column-mode
+ "Wrap lines according to `fill-column' in `visual-line-mode'."
+ :init-value nil :lighter nil :global nil
+ (if visual-fill-column-mode
+ (visual-fill-column-mode--enable)
+ (visual-fill-column-mode--disable)))
+
+;;;###autoload
+(define-globalized-minor-mode global-visual-fill-column-mode
visual-fill-column-mode turn-on-visual-fill-column-mode
+ :require 'visual-fill-column-mode
+ :group 'visual-fill-column)
+
+(defun turn-on-visual-fill-column-mode ()
+ "Turn on `visual-fill-column-mode'.
+Note that `visual-fill-column-mode' is only turned on in buffers
+in which `visual-line-mode' is active as well."
+ (when visual-line-mode
+ (visual-fill-column-mode 1)))
+
+(defun visual-fill-column-mode--enable ()
+ "Set up `visual-fill-column-mode' for the current buffer."
+ (add-hook 'window-configuration-change-hook
#'visual-fill-column--adjust-window nil t)
+ (visual-fill-column--adjust-window))
+
+(defun visual-fill-column-mode--disable ()
+ "Disable `visual-fill-column-mode' for the current buffer."
+ (remove-hook 'window-configuration-change-hook
#'visual-fill-column--adjust-window t)
+ (set-window-margins (selected-window) 0 0)
+ (when visual-fill-column-disable-fringe
+ (set-window-fringes (selected-window) nil nil)))
+
+(defun visual-fill-column--adjust-window ()
+ "Adjust the window margins and fringes."
+ (visual-fill-column--set-fringes)
+ (visual-fill-column--set-margins))
+
+(defun visual-fill-column--set-fringes ()
+ "Set the fringes for the current window."
+ (when visual-fill-column-disable-fringe
+ ;; the left fringe is only disabled if the text is centered
+ (let ((left (if visual-fill-column-center-text 0 nil))
+ (right 0))
+ ;; swap left & right fringes in explicitly R2L buffers
+ (when (eq bidi-paragraph-direction 'right-to-left)
+ (setq right left)
+ (setq left 0))
+ (set-window-fringes (selected-window) left right))))
+
+(defun visual-fill-column--set-margins ()
+ "Set window margins for the current window."
+ ;; calculate left & right margins
+ (let* ((window (selected-window))
+ (current-width (window-total-width window))
+ (margins (cond
+ ((and (floatp visual-fill-column-width)
+ (< 0 visual-fill-column-width 1))
+ (- current-width (truncate (* current-width
visual-fill-column-width))))
+ (t (if (< (- current-width fill-column) 0) ; margins must
be >= 0
+ 0
+ (- current-width fill-column)))))
+ (left (if visual-fill-column-center-text
+ (/ margins 2)
+ 0))
+ (right (if visual-fill-column-center-text
+ (/ margins 2)
+ margins)))
+ ;; 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))
+ ;; check values and set the margins
+ (set-window-margins window left right)))
+
+(provide 'visual-fill-column)
+
+;;; visual-fill-column.el ends here
- [nongnu] elpa/visual-fill-column 9863702b53 015/137: Use `fringes-outside-margins` instead of disabling the fringes., (continued)
- [nongnu] elpa/visual-fill-column 9863702b53 015/137: Use `fringes-outside-margins` instead of disabling the fringes., ELPA Syncer, 2022/01/02
- [nongnu] elpa/visual-fill-column db1ca8f337 016/137: Use set-window-fringes to set fringes outside the margins, ELPA Syncer, 2022/01/02
- [nongnu] elpa/visual-fill-column 60d8a031d5 017/137: Do not use `window-total-width'., ELPA Syncer, 2022/01/02
- [nongnu] elpa/visual-fill-column 8b98476819 018/137: Update README.md, ELPA Syncer, 2022/01/02
- [nongnu] elpa/visual-fill-column 5908ad2422 019/137: Use package name in installation instructions, ELPA Syncer, 2022/01/02
- [nongnu] elpa/visual-fill-column 7ec32c974a 027/137: Some optical code improvements., ELPA Syncer, 2022/01/02
- [nongnu] elpa/visual-fill-column 6e6b71177d 025/137: Make calls to `add-hook' a bit more self-documenting., ELPA Syncer, 2022/01/02
- [nongnu] elpa/visual-fill-column 4223f9b6f9 034/137: Add PIXELWISE argument to visual-fill-column-split-window, ELPA Syncer, 2022/01/02
- [nongnu] elpa/visual-fill-column 62ecc38450 036/137: Make arguments of `visual-fill-column--split-window' optional., ELPA Syncer, 2022/01/02
- [nongnu] elpa/visual-fill-column 54b941caa6 057/137: Fix code quote in README., ELPA Syncer, 2022/01/02
- [nongnu] elpa/visual-fill-column 4b903a0adb 002/137: Implement visual-fill-column,
ELPA Syncer <=
- [nongnu] elpa/visual-fill-column 15b5cd1410 007/137: Remove option to use a fraction for `visual-fill-column-width'., ELPA Syncer, 2022/01/02
- [nongnu] elpa/visual-fill-column a017cb2a1e 013/137: Update version number to 1.2, ELPA Syncer, 2022/01/02
- [nongnu] elpa/visual-fill-column ccecfac6ca 029/137: Handle window splitting., ELPA Syncer, 2022/01/02
- [nongnu] elpa/visual-fill-column 5e698470b6 038/137: Set window parameter properly in vfc-adjust-window, ELPA Syncer, 2022/01/02
- [nongnu] elpa/visual-fill-column 865c9b32ea 043/137: Merge pull request #16 from wbolster/patch-1, ELPA Syncer, 2022/01/02
- [nongnu] elpa/visual-fill-column 6c6074114d 068/137: Make visual-fill-column--adjust-frame global in `window-size-change-functions'., ELPA Syncer, 2022/01/02
- [nongnu] elpa/visual-fill-column c8d61f0287 070/137: Take line number width into account., ELPA Syncer, 2022/01/02
- [nongnu] elpa/visual-fill-column b3b953116b 046/137: Make `visual-fill-column-adjust-window' a public function., ELPA Syncer, 2022/01/02
- [nongnu] elpa/visual-fill-column 9a3a2ef3c7 074/137: Add Cask & ert-runner, ELPA Syncer, 2022/01/02
- [nongnu] elpa/visual-fill-column da5a8d688a 066/137: Merge pull request #35 from yuhan0/patch-1, ELPA Syncer, 2022/01/02