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

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

[nongnu] elpa/visual-fill-column ccecfac6ca 029/137: Handle window split


From: ELPA Syncer
Subject: [nongnu] elpa/visual-fill-column ccecfac6ca 029/137: Handle window splitting.
Date: Sun, 2 Jan 2022 22:59:09 -0500 (EST)

branch: elpa/visual-fill-column
commit ccecfac6cafec73285c1b047f36ecf0693f3a553
Author: Joost Kremers <joostkremers@fastmail.fm>
Commit: Joost Kremers <joostkremers@fastmail.fm>

    Handle window splitting.
    
    (visual-fill-column--split-window): new function, for use in
    `split-window' window parameter. Unsets the window margins before trying
    to split a window. Code kindly provided by Martin Rudalics, see
    <https://lists.gnu.org/archive/html/emacs-devel/2016-01/msg01158.html>.
---
 visual-fill-column.el | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/visual-fill-column.el b/visual-fill-column.el
index f14f4a8d67..e5ef650f63 100644
--- a/visual-fill-column.el
+++ b/visual-fill-column.el
@@ -1,6 +1,7 @@
 ;;; visual-fill-column.el --- fill-column for visual-line-mode  -*- 
lexical-binding: t -*-
 
 ;; Copyright (C) 2015-2016 Joost Kremers
+;; Copyright (C) 2016 Martin Rudalics
 ;; All rights reserved.
 
 ;; Author: Joost Kremers <joostkremers@fastmail.fm>
@@ -95,9 +96,29 @@ in which `visual-line-mode' is active as well."
   (set-window-fringes (selected-window) nil)
   (set-window-margins (selected-window) 0 0))
 
+(defun visual-fill-column--split-window (window size side)
+  "Split WINDOW, unsetting its margins first.
+SIZE and SIDE are passed on to `split-window'.  This function is
+for use in the window parameter `split-window'."
+  (let ((horizontal (memq side '(t left right)))
+       margins new)
+    (when horizontal
+      ;; Reset margins.
+      (setq margins (window-margins window))
+      (set-window-margins window nil nil))
+    ;; Now try to split the window.
+    (set-window-parameter window 'split-window nil)
+    (unwind-protect
+       (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))
+       (set-window-margins window (car margins) (cdr margins))))))
+
 (defun visual-fill-column--adjust-window ()
   "Adjust the window margins and fringes."
   (set-window-fringes (selected-window) nil nil 
visual-fill-column-fringes-outside-margins)
+  (set-window-parameter nil 'split-window #'visual-fill-column--split-window)
   (visual-fill-column--set-margins))
 
 (defun visual-fill-column--window-max-text-width (&optional window)



reply via email to

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