From f0294f7fb4de3fed7e3f14969ebaa1531193361e Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Thu, 6 Jan 2022 22:55:26 -0600 Subject: Lots of other changes --- lisp/acdw.el | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'lisp') diff --git a/lisp/acdw.el b/lisp/acdw.el index 8b9c7b9..9361cdf 100644 --- a/lisp/acdw.el +++ b/lisp/acdw.el @@ -185,5 +185,55 @@ three blank lines, then place the point on the second one." (newline 2) (previous-line))) +(defun +split-window-then (&optional where arg) + "Split the window into a new buffer. +With non-nil ARG (\\[universal-argument] interactively), don't +prompt for a buffer to switch to. This function will split the +window using `split-window-sensibly', or open the new window in +the direction specified by WHERE. WHERE is ignored when called +interactively; if you want specific splitting, use +`+split-window-right-then' or `+split-window-below-then'." + (interactive "i\nP") + ;; TODO: Canceling at the switching phase leaves the point in the other + ;; window. Ideally, the user would see this as one action, meaning a cancel + ;; would return to the original window. + (pcase where + ;; These directions are 'backward' to the OG Emacs split-window commands, + ;; because by default Emacs leaves the cursor in the original window. Most + ;; users probably expect a switch to the new window, at least I do. + ((or 'right :right) (split-window-right) (other-window 1)) + ((or 'left :left) (split-window-right)) + ((or 'below :below) (split-window-below) (other-window 1)) + ((or 'above :above) (split-window-below)) + ((pred null) + (or (split-window-sensibly) + (if (< (window-height) (window-width)) + (split-window-below) + (split-window-right))) + (other-window 1)) + (_ (user-error "Unknown WHERE paramater: %s" where))) + (unless arg + (condition-case nil + (call-interactively + (pcase (read-char "(B)uffer or (F)ile?") + (?b (if (fboundp #'consult-buffer) + #'consult-buffer + #'switch-to-buffer)) + (?f #'find-file) + (_ #'ignore))) + (quit (delete-window))))) + +(defun +split-window-right-then (&optional arg) + "Split window right, then prompt for a new buffer. +With optional ARG (\\[universal-argument]), just split." + (interactive "P") + (+split-window-then :right arg)) + +(defun +split-window-below-then (&optional arg) + "Split window below, then prompt for a new buffer. +With optional ARG (\\[universal-argument]), just split." + (interactive "P") + (+split-window-then :below arg)) + (provide 'acdw) ;;; acdw.el ends here -- cgit 1.4.1-21-gabe81