diff --git a/.emacs.d/lisp/functions.el b/.emacs.d/lisp/functions.el index 87494499..5086df8a 100644 --- a/.emacs.d/lisp/functions.el +++ b/.emacs.d/lisp/functions.el @@ -147,38 +147,6 @@ Require `ambrevar/tabify-leading'." (setq key (pop bindings) def (pop bindings)))) -(defun ambrevar/move-border-left (arg) - "Move window border in a natural manner. -If this is a window with its right edge being the edge of the -screen, enlarge the window horizontally. If this is a window with -its left edge being the edge of the screen, shrink the window -horizontally. Otherwise, default to enlarging horizontally.\n -Enlarge/Shrink by ARG columns, or 5 if ARG is nil." - (interactive "P") - (if (= (count-windows) 2) - (ambrevar/move-border-left-or-right arg t))) -(global-set-key (kbd "M-(") 'ambrevar/move-border-left) - -(defun ambrevar/move-border-left-or-right (arg dir-left) - "Wrapper around ‘move-border-left’ and ‘move-border-right’. -ARG is the number of columns to move. -If DIR-LEFT is t, then move left, otherwise move right." - (interactive) - (unless arg (setq arg 5)) - (let ((left-edge (= (car (window-edges)) 0))) - (if (or - (and left-edge dir-left) - (and (not left-edge) (not dir-left))) - (shrink-window arg t) - (enlarge-window arg t)))) - -(defun ambrevar/move-border-right (arg) - "See `move-border-left'." - (interactive "P") - (if (= (count-windows) 2) - (ambrevar/move-border-left-or-right arg nil))) -(global-set-key (kbd "M-)") 'ambrevar/move-border-right) - (defun ambrevar/reset-fill-column () "Reset `fill-column' to its default value." (interactive) @@ -195,57 +163,6 @@ Do not fold case with \\[universal-argument] or non-nil ARG." (delete-duplicate-lines start end) (sort-lines nil start end)))) -(defun ambrevar/swap-windows (&optional w1 w2) - "If 2 windows are up, swap them. -Else if W1 is a window, swap it with current window. -If W2 is a window too, swap both." - (interactive) - (unless (or (= 2 (count-windows)) - (windowp w1) - (windowp w2)) - (error "Ambiguous window selection")) - (let* ((w1 (or w1 (car (window-list)))) - (w2 (or w2 - (if (eq w1 (car (window-list))) - (nth 1 (window-list)) - (car (window-list))))) - (b1 (window-buffer w1)) - (b2 (window-buffer w2)) - (s1 (window-start w1)) - (s2 (window-start w2))) - (with-temp-buffer - ;; Some buffers like EXWM buffers can only be in one live buffer at once. - ;; Switch to a dummy buffer in w2 so that we don't display any buffer twice. - (set-window-buffer w2 (current-buffer)) - (set-window-buffer w1 b2) - (set-window-buffer w2 b1)) - (set-window-start w1 s2) - (set-window-start w2 s1)) - (select-window w1)) -(global-set-key (kbd "C-x \\") 'swap-windows) - -(defun ambrevar/swap-windows-left () - "Swap current window with the window to the left." - (interactive) - (ambrevar/swap-windows (window-in-direction 'left))) -(defun ambrevar/swap-windows-below () - "Swap current window with the window below." - (interactive) - (ambrevar/swap-windows (window-in-direction 'below))) -(defun ambrevar/swap-windows-above () - "Swap current window with the window above." - (interactive) - (ambrevar/swap-windows (window-in-direction 'above))) -(defun ambrevar/swap-windows-right () - "Swap current window with the window to the right." - (interactive) - (ambrevar/swap-windows (window-in-direction 'right))) - -(defun ambrevar/switch-to-last-buffer () - "Switch to last open buffer in current window." - (interactive) - (switch-to-buffer (other-buffer (current-buffer) 1))) - (defun ambrevar/tabify-leading () "Call `tabify' on leading spaces only. Works on whole buffer if region is unactive." @@ -293,49 +210,6 @@ Works on whole buffer if region is unactive." nil)))) (add-hook 'kill-emacs-query-functions 'ambrevar/test-emacs) -;;; TODO: Store window configurations in a buffer-name-indexed alist? Not -;;; sure that would ever be useful. -(defvar single-window--last-configuration nil "Last window configuration before calling `delete-other-windows'.") -(defun ambrevar/toggle-single-window () - "Un-maximize current window. -If multiple windows are active, save window configuration and -delete other windows. If only one window is active and a window -configuration was previously save, restore that configuration." - (interactive) - (if (= (count-windows) 1) - (when single-window--last-configuration - (set-window-configuration single-window--last-configuration)) - (setq single-window--last-configuration (current-window-configuration)) - (delete-other-windows))) - -(defun ambrevar/toggle-window-split () - "Switch between vertical and horizontal split. -It only works for frames with exactly two windows." - (interactive) - (if (= (count-windows) 2) - (let* ((this-win-buffer (window-buffer)) - (next-win-buffer (window-buffer (next-window))) - (this-win-edges (window-edges (selected-window))) - (next-win-edges (window-edges (next-window))) - (this-win-2nd (not (and (<= (car this-win-edges) - (car next-win-edges)) - (<= (cadr this-win-edges) - (cadr next-win-edges))))) - (splitter - (if (= (car this-win-edges) - (car (window-edges (next-window)))) - 'split-window-horizontally - 'split-window-vertically))) - (delete-other-windows) - (let ((first-win (selected-window))) - (funcall splitter) - (if this-win-2nd (other-window 1)) - (set-window-buffer (selected-window) this-win-buffer) - (set-window-buffer (next-window) next-win-buffer) - (select-window first-win) - (if this-win-2nd (other-window 1)))))) -(global-set-key (kbd "C-x C-\\") 'toggle-window-split) - (defun ambrevar/toggle-word-delim () "Make underscore part of the word syntax or not. This does not interfere with `subword-mode'."