Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (load-module "scratchpad")
- ;;; Emacs integration
- ;;
- (defcommand emacs () () ; override default emacs command
- "Start emacs if emacsclient is not running and focus emacs if it is
- running in the current group"
- (run-or-raise "emacsclient -c -a 'emacs'" '(:class "Emacs")))
- (defcommand emacs-run-launcher () ()
- "Launch programs from a an Emacs floating child frame"
- (scratchpad:toggle-floating-scratchpad "run-shell-command" "emacsclient -e '(emacs-run-launcher)'"
- :initial-gravity :center
- :initial-width 900
- :initial-height 400))
- (defcommand emacs-pass () () ; override default emacs command
- "Run pass in a floating child frame"
- (scratchpad:toggle-floating-scratchpad "run-shell-command" "emacsclient -e '(emacs-pass)'"
- :initial-gravity :center
- :initial-width 900
- :initial-height 400))
- ;; *Helpers
- ;; Treat emacs splits like Xorg windows
- (defun is-emacs-p (win)
- "nil if the WIN"
- (when win
- (string-equal (window-class win) "Emacs")))
- ;;
- (defun eval-string-as-el (elisp &optional collect-output-p)
- "evaluate a string as emacs lisp"
- (let ((result (run-shell-command
- (format nil "timeout --signal=9 1m emacsclient --eval \"~a\""
- elisp)
- collect-output-p)))
- (handler-case (read-from-string result)
- ;; Pass back a string when we can't read from the string
- (error () result))))
- ;; *Directional
- ;;; Runs stump if not emacs or emacs no more in that direction
- (defun stump-or-emacs-directional (direction stump emacs)
- (declare (type (member :up :down :left :right) direction)
- (type string stump)
- (type string emacs))
- "Similar to move-focus but also treats emacs windows as Xorg windows"
- (flet ((sore-directional ()
- (eval-command (concat stump " " (string direction)))))
- (if (is-emacs-p (current-window))
- (when ;; There is not emacs window in that direction
- (length= (eval-string-as-el (concat "(" emacs (string-downcase (string direction)) ")") t)
- 1)
- (sore-directional))
- (sore-directional))))
- ;; **Final Commands
- ;; Move window
- (defcommand stump-or-emacs-move-window (direction) ((:direction "Enter direction: "))
- (when direction (stump-or-emacs-directional direction "move-window" "windmove-swap-states-")))
- ;; Move focus
- (defcommand stump-or-emacs-move-focus (direction) ((:direction "Enter direction: "))
- (when direction (stump-or-emacs-directional direction "move-focus" "windmove-")))
- ;; *Positional
- (defun stump-or-emacs (stump emacs)
- (declare (type string stump)
- (type string emacs))
- (if (is-emacs-p (current-window))
- (eval-string-as-el (concat "(" emacs ")") nil)
- (eval-command stump)))
- ;; Move window
- (defcommand stump-or-emacs-close-window () ()
- (stump-or-emacs "remove-split" "+workspace/close-window-or-workspace"))
- ;; Gentle kill window/buffer
- (defcommand stump-or-emacs-delete-kill-buffer () ()
- (stump-or-emacs "delete" (concat "kill-buffer \\\""
- (window-title(current-window))
- "\\\"")))
- ;; Splits
- (defcommand hsplit-and-focus () ()
- "create a new frame on the right and focus it."
- (hsplit)
- (move-focus :right))
- (defcommand vsplit-and-focus () ()
- "create a new frame below and focus it."
- (vsplit)
- (move-focus :down))
- ;; (loop :for i :in '("hsplit-and-focus"
- ;; "vsplit-and-focus")
- ;; :do (dyn-blacklist-command i))
- (defcommand stump-or-emacs-vsplit () ()
- (stump-or-emacs "hsplit-and-focus" "+evil/window-vsplit-and-follow"))
- (defcommand stump-or-emacs-hsplit () ()
- (stump-or-emacs "vsplit-and-focus" "+evil/window-split-and-follow"))
- ;; Fullscreen buffer/window
- (defcommand stump-or-emacs-fullscreen () ()
- (stump-or-emacs "fullscreen"
- "toggle-buffer-fullscreen"))
Add Comment
Please, Sign In to add comment