branch: elpa/dirvish
commit 2c6cf4b888f52f28878999fa71fe05e36de7b0c3
Author: Nivyan Lakhani <m...@nivyan.xyz>
Commit: GitHub <nore...@github.com>

    feat(side): add commands for manual width resizing (closes #332)
    
    * feat: Add commands to manually resize width.
    
    The dirvish-side window is created with a fixed width 
(\`window-size-fixed\`),
    which prevents users from adjusting its size manually using standard
    window commands. This can be inconvenient when needing a temporarily
    wider or narrower view.
    
    This commit introduces two new interactive commands:
    - \`dirvish-side-increase-width\`: Enlarges the side window.
    - \`dirvish-side-decrease-width\`: Shrinks the side window.
    
    These commands work by temporarily overriding the \`window-size-fixed\`
    property during the resize operation using \`let ((window-size-fixed 
nil))\`.
    
    * Added reference to new functions in docs
    
    * Use prefix arg for resize increment
    
    The `dirvish-side-increase-width` and `dirvish-side-decrease-width`
    commands now accept a numeric prefix argument to control the resize
    amount. If no prefix argument is given, the value of 1 is used.
    
    ---------
    
    Co-authored-by: Alex Lu <hellosimon1...@hotmail.com>
---
 docs/EXTENSIONS.org        | 16 ++++++++++------
 extensions/dirvish-side.el | 27 +++++++++++++++++++++------
 2 files changed, 31 insertions(+), 12 deletions(-)

diff --git a/docs/EXTENSIONS.org b/docs/EXTENSIONS.org
index 59ed767dd6..dbd9a9e118 100644
--- a/docs/EXTENSIONS.org
+++ b/docs/EXTENSIONS.org
@@ -181,8 +181,16 @@ To tweak the appearance of the icons, you have these 
options:
 
 * Toggle Dirvish in side window (dirvish-side.el)
 
-This extension provides the ~dirvish-side~ command. It toggles a Dirvish 
session
-as a sidebar in the frame.  These customization options are available:
+This extension provides the ~dirvish-side~ command, which toggles a Dirvish
+sidebar within the current frame.  The width is fixed to prevent the window 
from
+unexpected resizing, but you can adjust it using the 
~dirvish-side-increase-width~
+and ~dirvish-side-decrease-width~ commands.
+
+When ~dirvish-side-follow-mode~ is enabled, the visible side session will 
select
+the current buffer's filename, similar to ~treemacs-follow-mode~ in 
=treemacs=. It
+will also visits the latest ~project-root~ after switching to a new project.
+
+These customization options are available:
 
 + ~dirvish-side-attributes~: like ~dirvish-attributes~, but for side window.
 + ~dirvish-side-mode-line-format~: like ~dirvish-mode-line-format~, but for 
side window.
@@ -193,10 +201,6 @@ as a sidebar in the frame.  These customization options 
are available:
 + ~dirvish-side-open-file-action~: Action to perform before opening a file in 
a side window.
 + ~dirvish-side-auto-expand~: Whether to auto expand parent directories of 
current file.
 
-When ~dirvish-side-follow-mode~ is enabled, the visible side session will 
select
-the current buffer's filename, similar to ~treemacs-follow-mode~ in 
=treemacs=. It
-will also visits the latest ~project-root~ after switching to a new project.
-
 * Setup ls switches on the fly (dirvish-ls.el)
 
 This extension provides commands to changing the ls listing switches like a
diff --git a/extensions/dirvish-side.el b/extensions/dirvish-side.el
index 87c5eb29f8..50c621cacb 100644
--- a/extensions/dirvish-side.el
+++ b/extensions/dirvish-side.el
@@ -77,12 +77,11 @@ filename until the project root when opening a side 
session."
                buf (append '((dedicated . t)) dirvish-side-display-alist))))
     (cl-loop for (key . value) in dirvish-side-window-parameters
              do (set-window-parameter win key value))
-    (with-selected-window win
-      (let ((w (max dirvish-side-width window-min-width)) window-size-fixed)
-        (cond ((> (window-width) w)
-               (shrink-window-horizontally  (- (window-width) w)))
-              ((< (window-width) w)
-               (enlarge-window-horizontally (- w (window-width)))))))
+    (with-selected-window win ; Set window width to `dirvish-side-width'
+      (let ((w (max dirvish-side-width window-min-width))
+            window-size-fixed) ; Temporarily unfix size for initial adjustment
+        ;; Ignore errors during resizing (eg. already minimum)
+        (ignore-errors (enlarge-window-horizontally (- w (window-width))))))
     (select-window win)))
 
 (defun dirvish-side-open-file (dv find-fn file)
@@ -153,6 +152,22 @@ filename until the project root when opening a side 
session."
              (dirvish-subtree-expand-to bname))
             (t (dired-goto-file bname))))))
 
+(defun dirvish-side-increase-width (delta)
+  "Increase width of the `dirvish-side' window by DELTA columns.
+Interactively, if no argument is given, DELTA is seen as 1."
+  (interactive "^p")
+  (let ((win (dirvish-side--session-visible-p)))
+    (unless win (user-error "No visible dirvish-side window found"))
+    (with-selected-window win
+      (let ((window-size-fixed nil))
+        (ignore-errors (enlarge-window-horizontally delta))))))
+
+(defun dirvish-side-decrease-width (delta)
+  "Decrease width of the `dirvish-side' window by DELTA columns.
+Interactively, if no argument is given, DELTA is seen as 1."
+  (interactive "^p")
+  (dirvish-side-increase-width (- delta)))
+
 ;;;###autoload
 (define-minor-mode dirvish-side-follow-mode
   "Toggle `dirvish-side-follow-mode'.

Reply via email to