emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/visual-fill-column ff329c5ffd 105/137: Merge branch 'devel


From: ELPA Syncer
Subject: [nongnu] elpa/visual-fill-column ff329c5ffd 105/137: Merge branch 'devel'
Date: Sun, 2 Jan 2022 22:59:17 -0500 (EST)

branch: elpa/visual-fill-column
commit ff329c5ffd65db74980742ebc2ec3b8173128f4c
Merge: 598bc992f0 e73f99e09f
Author: Joost Kremers <joostkremers@fastmail.fm>
Commit: Joost Kremers <joostkremers@fastmail.fm>

    Merge branch 'devel'
---
 README.md             |  12 +++--
 visual-fill-column.el | 125 ++++++++++++++++++++++++++++++++++----------------
 2 files changed, 94 insertions(+), 43 deletions(-)

diff --git a/README.md b/README.md
index a4b44bf58a..911b284fc6 100644
--- a/README.md
+++ b/README.md
@@ -39,9 +39,11 @@ Widening the margin normally causes the fringes to be pushed 
inward. Since this
 
 ## Splitting a Window ##
 
-Emacs won’t vertically split a window (i.e., into two side-by-side windows) 
that has wide margins. As a result, displaying buffers such as `*Help*` 
buffers, `*Completion*` buffers, etc., won’t split a window vertically, even if 
there appears to be enough space for a vertical split. This is technically not 
problematic, but it may be undesirable from a user's point of view. To remedy 
this, you can set the option `split-window-preferred-function` to 
`visual-fill-column-split-window-sensibly [...]
+Emacs won’t vertically split a window (i.e., into two side-by-side windows) 
that has wide margins. As a result, displaying buffers such as `*Help*` 
buffers, `*Completion*` buffers, etc., won’t split a window vertically, even if 
there appears to be enough space for a vertical split. This is technically not 
problematic, but it may be undesirable from a user's point of view. To remedy 
this, `visual-fill-column-mode` sets the option 
`split-window-preferred-function` to `visual-fill-column-sp [...]
 
-    (setq-default split-window-preferred-function 
'visual-fill-column-split-window-sensibly)
+You can set the option `visual-fill-column-inhibit-sensible-window-split` to 
inhibit this and use the default function `split-window-sensibly' or another 
custom function.
+
+Note that this option does not affect the ability to split windows manually. 
Even if you set `visual-fill-column-inhibit-sensible-window-split`, you can 
still split a window into two side-by-side windows by invoking e.g., 
`split-window-right` (`C-x 3`).
 
 
 ## Adjusting Text Size ##
@@ -55,7 +57,7 @@ Alternatively, you can advise the function `text-size-adjust` 
with the function
 
 ## Customisation ##
 
-The customisation group `visual-fill-column` has three options (beside 
`global-visual-fill-column-mode`) that can be used to customise 
`visual-fill-column`:
+The customisation group `visual-fill-column` has four options (beside 
`global-visual-fill-column-mode`) that can be used to customise 
`visual-fill-column`:
 
 `visual-fill-column-width`: column at which to wrap lines. If set to `nil` 
(the default), use the value of `fill-column` instead.
 
@@ -63,6 +65,8 @@ The customisation group `visual-fill-column` has three 
options (beside `global-v
 
 `visual-fill-column-fringes-outside-margins`: if set to `t`, put the fringes 
outside the margins.
 
-All 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.
+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.
+
+The fourth option, `visual-fill-column-inhibit-sensible-window-split` can be 
set to keep `visual-fill-column-mode` from setting 
`split-window-preferred-function`.
 
 `visual-fill-column-mode` also binds several mouse events for the left and 
right margins, so that scrolling or clicking on the margins does what you'd 
expect (rather than cause an "event not bound" error). If you wish to adjust 
these bindings, you should do so in `visual-fill-column-mode-map`.
diff --git a/visual-fill-column.el b/visual-fill-column.el
index 3fc2d948b4..6ef64d135f 100644
--- a/visual-fill-column.el
+++ b/visual-fill-column.el
@@ -1,6 +1,6 @@
 ;;; visual-fill-column.el --- fill-column for visual-line-mode  -*- 
lexical-binding: t -*-
 
-;; Copyright (C) 2015-2019 Joost Kremers
+;; Copyright (C) 2015-2020 Joost Kremers
 ;; Copyright (C) 2016 Martin Rudalics
 ;; All rights reserved.
 
@@ -8,7 +8,7 @@
 ;; Maintainer: Joost Kremers <joostkremers@fastmail.fm>
 ;; URL: https://github.com/joostkremers/visual-fill-column
 ;; Created: 2015
-;; Version: 1.11
+;; Version: 2.0
 ;; Package-Requires: ((emacs "25.1"))
 
 ;; This file is NOT part of GNU Emacs.
@@ -66,6 +66,24 @@ 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-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
+`visual-fill-column-split-window-sensibly', in order to allow
+`display-buffer' to split windows in two side-by-side windows.
+Unset this option if you wish to use your custom function for
+`split-window-sensibly'."
+  :group 'visual-fill-column
+  :type '(choice (const :tag "Allow vertical window split" nil)
+                 (const :tag "Use standard window split" t)))
+
+(defvar visual-fill-column--use-split-window-parameter nil "If set, the window 
parameter `split-window' is used.")
+
+(defvar visual-fill-column--min-margins nil "Width of the margins before 
invoking `visual-fill-column-mode'.")
+(make-variable-buffer-local 'visual-fill-column--min-margins)
+
+(defvar visual-fill-column--original-split-window-function nil "The value of 
`split-window-preferred-function'.")
+
 (defvar visual-fill-column-mode-map
   (let ((map (make-sparse-keymap)))
     (define-key map [right-margin mouse-1] (global-key-binding [mouse-1])) ; 
#'mouse-set-point
@@ -122,21 +140,40 @@ that actually visit a file."
 
 (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 'append 'local)
-  (if (>= emacs-major-version 26)
-      (add-hook 'window-size-change-functions 
#'visual-fill-column--adjust-frame 'append))
-  (visual-fill-column--adjust-window))
+  (add-hook 'window-configuration-change-hook 
#'visual-fill-column--adjust-all-windows 'append 'local)
+  (add-hook 'window-size-change-functions #'visual-fill-column--adjust-window 
'append 'local)
+
+  (when (not visual-fill-column-inhibit-sensible-window-split)
+    (setq visual-fill-column--original-split-window-function 
split-window-preferred-function)
+    (setq-default split-window-preferred-function 
#'visual-fill-column-split-window-sensibly))
+
+  (when (version<= emacs-version "27.1")
+    (setq visual-fill-column--use-split-window-parameter t))
+
+  (when (version< "27.1" emacs-version)
+    (let ((margins (window-margins (selected-window))))
+      (setq visual-fill-column--min-margins (cons (or (car margins) 0)
+                                                  (or (cdr margins) 0)))))
+
+  (visual-fill-column--adjust-window (selected-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 'local)
-  (set-window-fringes (get-buffer-window (current-buffer)) nil)
-  (set-window-margins (get-buffer-window (current-buffer)) nil))
+  (if (<= emacs-major-version 26)
+      (remove-hook 'window-configuration-change-hook 
#'visual-fill-column--adjust-window 'local))
+  (remove-hook 'window-size-change-functions 
#'visual-fill-column--adjust-window 'local)
+  (let ((window (get-buffer-window (current-buffer))))
+    (set-window-margins window (car visual-fill-column--min-margins) (cdr 
visual-fill-column--min-margins))
+    (set-window-fringes window nil)
+    (set-window-parameter window 'min-margins nil)
+    (kill-local-variable 'visual-fill-column--min-margins)))
 
-(defun visual-fill-column-split-window (&optional window size side pixelwise)
+(defun visual-fill-column-split-window (&optional window size side)
   "Split WINDOW, unsetting its margins first.
-SIZE, SIDE, and PIXELWISE are passed on to `split-window'.  This
-function is for use in the window parameter `split-window'."
+SIZE, and SIDE are passed on to `split-window'.  This function is
+for use in the window parameter `split-window'."
+  ;; Note: `split-window' has another optional argument, `pixelwise', but this
+  ;; is not passed to the function in the `split-window' window parameter.
   (let ((horizontal (memq side '(t left right)))
        margins new)
     (when horizontal
@@ -146,7 +183,7 @@ function is for use in the window parameter `split-window'."
     ;; Now try to split the window.
     (set-window-parameter window 'split-window nil)
     (unwind-protect
-       (setq new (split-window window size side pixelwise))
+       (setq new (split-window window size side))
       (set-window-parameter window 'split-window 
#'visual-fill-column-split-window)
       ;; Restore old margins if we failed.
       (when (and horizontal (not new))
@@ -158,11 +195,11 @@ function is for use in the window parameter 
`split-window'."
 This function unsets the window margins and calls
 `split-window-sensibly'.
 
-By default, `split-window-sensibly' does not split a window
-vertically if it has wide margins, even if there is enough space
-for a vertical split.  This function can be used as the value of
-`split-window-preferred-function' to enable vertically splitting
-windows with wide margins."
+By default, `split-window-sensibly' does not split a window in
+two side-by-side windows if it has wide margins, even if there is
+enough space for a vertical split.  This function is used as the
+value of `split-window-preferred-function' to allow
+`display-buffer' to split such windows."
   (let ((margins (window-margins window))
         new)
     ;; unset the margins and try to split the window
@@ -173,21 +210,32 @@ windows with wide margins."
       (when (not new)
         (set-window-margins window (car margins) (cdr margins))))))
 
-(defun visual-fill-column--adjust-window ()
-  "Adjust the window margins and fringes."
-  ;; Only run when we're really looking at a buffer that has v-f-c-mode 
enabled. See #22.
-  (when (buffer-local-value 'visual-fill-column-mode (window-buffer 
(selected-window)))
-    (set-window-fringes (get-buffer-window (current-buffer)) nil nil 
visual-fill-column-fringes-outside-margins)
-    (if (>= emacs-major-version 25)
-        (set-window-parameter (get-buffer-window (current-buffer)) 
'split-window #'visual-fill-column-split-window))
-    (visual-fill-column--set-margins)))
-
-(defun visual-fill-column--adjust-frame (frame)
-  "Adjust the windows of FRAME."
-  (mapc (lambda (w)
-          (with-selected-window w
-            (visual-fill-column--adjust-window)))
-        (window-list frame :never)))
+(defun visual-fill-column--reset-window (window)
+  "Reset the parameters and margins of WINDOW."
+  (set-window-parameter window 'split-window nil)
+  (set-window-parameter window 'min-margins nil)
+  (set-window-margins window nil))
+
+(defun visual-fill-column--adjust-window (&optional window)
+  "Adjust the margins and fringes of WINDOW.
+WINDOW defaults to the selected window.  This function only
+adjusts the margins and fringes if the buffer displayed in the
+selected window has `visual-fill-column-mode' enabled."
+  (or window (setq window (selected-window)))
+  (with-selected-window window
+    (visual-fill-column--reset-window window)
+    (when visual-fill-column-mode
+      (set-window-fringes window nil nil 
visual-fill-column-fringes-outside-margins)
+      (if visual-fill-column--use-split-window-parameter
+          (set-window-parameter window 'split-window 
#'visual-fill-column-split-window))
+      (if visual-fill-column--min-margins  ; This is non-nil if the window 
parameter `min-margins' is used (Emacs 27.2).
+          (set-window-parameter window 'min-margins 
visual-fill-column--min-margins))
+      (visual-fill-column--set-margins window))))
+
+(defun visual-fill-column--adjust-all-windows ()
+  "Adjust margins of all windows displaying the current buffer."
+  (mapc #'visual-fill-column--adjust-window
+        (get-buffer-window-list (current-buffer) 'no-minibuffer 'visible)))
 
 (defun visual-fill-column-adjust (&optional _inc)
   "Adjust the window margins and fringes.
@@ -195,7 +243,7 @@ This function is for use as advice to `text-scale-adjust'.  
It
 calls `visual-fill-column--adjust-window', but only if
 `visual-fill-column' is active."
   (if visual-fill-column-mode
-      (visual-fill-column--adjust-window)))
+      (visual-fill-column--adjust-window (selected-window))))
 
 (defun visual-fill-column--window-max-text-width (&optional window)
   "Return the maximum possible text width of WINDOW.
@@ -204,7 +252,7 @@ area plus the margins, but excluding the fringes, scroll 
bar and
 right divider.  WINDOW defaults to the selected window.  The
 return value is scaled to account for `text-scale-mode-amount'
 and `text-scale-mode-step'."
-  (or window (setq window (get-buffer-window (current-buffer))))
+  (or window (setq window (selected-window)))
   (let* ((margins (window-margins window))
          (buffer (window-buffer window))
          (scale (if (and (boundp 'text-scale-mode-step)
@@ -222,11 +270,10 @@ and `text-scale-mode-step'."
                         0))
                  (float scale)))))
 
-(defun visual-fill-column--set-margins ()
-  "Set window margins for the current window."
+(defun visual-fill-column--set-margins (window)
+  "Set window margins for WINDOW."
   ;; calculate left & right margins
-  (let* ((window (get-buffer-window (current-buffer)))
-         (total-width (visual-fill-column--window-max-text-width window))
+  (let* ((total-width (visual-fill-column--window-max-text-width window))
          (width (or visual-fill-column-width
                     fill-column))
          (margins (if (< (- total-width width) 0) ; margins must be >= 0



reply via email to

[Prev in Thread] Current Thread [Next in Thread]