Guest User

Untitled

a guest
Apr 25th, 2024
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 4.09 KB | None | 0 0
  1. (load-module "scratchpad")
  2. ;;; Emacs integration
  3. ;;
  4. (defcommand emacs () ()                 ; override default emacs command
  5.   "Start emacs if emacsclient is not running and focus emacs if it is
  6. running in the current group"
  7.   (run-or-raise "emacsclient -c -a 'emacs'" '(:class "Emacs")))
  8. (defcommand emacs-run-launcher () ()
  9.   "Launch programs from a an Emacs floating child frame"
  10.   (scratchpad:toggle-floating-scratchpad "run-shell-command" "emacsclient -e '(emacs-run-launcher)'"
  11.                                          :initial-gravity :center
  12.                                          :initial-width 900
  13.                                          :initial-height 400))
  14. (defcommand emacs-pass () ()                 ; override default emacs command
  15.   "Run pass in a floating child frame"
  16.   (scratchpad:toggle-floating-scratchpad "run-shell-command" "emacsclient -e '(emacs-pass)'"
  17.                                          :initial-gravity :center
  18.                                          :initial-width 900
  19.                                          :initial-height 400))
  20. ;; *Helpers
  21. ;; Treat emacs splits like Xorg windows
  22. (defun is-emacs-p (win)
  23.   "nil if the WIN"
  24.   (when win
  25.     (string-equal (window-class win) "Emacs")))
  26. ;;
  27. (defun eval-string-as-el (elisp &optional collect-output-p)
  28.   "evaluate a string as emacs lisp"
  29.   (let ((result (run-shell-command
  30.                  (format nil "timeout --signal=9 1m emacsclient --eval \"~a\""
  31.                          elisp)
  32.                  collect-output-p)))
  33.     (handler-case (read-from-string result)
  34.       ;; Pass back a string when we can't read from the string
  35.       (error () result))))
  36. ;; *Directional
  37. ;;; Runs stump if not emacs or emacs no more in that direction
  38. (defun stump-or-emacs-directional (direction stump emacs)
  39.   (declare (type (member :up :down :left :right) direction)
  40.            (type string stump)
  41.            (type string emacs))
  42.   "Similar to move-focus but also treats emacs windows as Xorg windows"
  43.   (flet ((sore-directional ()
  44.            (eval-command (concat stump " " (string direction)))))
  45.     (if (is-emacs-p (current-window))
  46.         (when ;; There is not emacs window in that direction
  47.             (length= (eval-string-as-el (concat "(" emacs (string-downcase (string direction)) ")") t)
  48.                      1)
  49.           (sore-directional))
  50.         (sore-directional))))
  51. ;; **Final Commands
  52. ;; Move window
  53. (defcommand stump-or-emacs-move-window (direction) ((:direction "Enter direction: "))
  54.   (when direction (stump-or-emacs-directional direction "move-window" "windmove-swap-states-")))
  55. ;; Move focus
  56. (defcommand stump-or-emacs-move-focus (direction) ((:direction "Enter direction: "))
  57.   (when direction (stump-or-emacs-directional direction "move-focus" "windmove-")))
  58. ;; *Positional
  59. (defun stump-or-emacs (stump emacs)
  60.   (declare (type string stump)
  61.            (type string emacs))
  62.   (if (is-emacs-p (current-window))
  63.       (eval-string-as-el (concat "(" emacs ")") nil)
  64.       (eval-command stump)))
  65. ;; Move window
  66. (defcommand stump-or-emacs-close-window () ()
  67.   (stump-or-emacs "remove-split" "+workspace/close-window-or-workspace"))
  68. ;; Gentle kill window/buffer
  69. (defcommand stump-or-emacs-delete-kill-buffer () ()
  70.   (stump-or-emacs "delete" (concat "kill-buffer \\\""
  71.                              (window-title(current-window))
  72.                              "\\\"")))
  73. ;; Splits
  74. (defcommand hsplit-and-focus () ()
  75.   "create a new frame on the right and focus it."
  76.   (hsplit)
  77.   (move-focus :right))
  78. (defcommand vsplit-and-focus () ()
  79.   "create a new frame below and focus it."
  80.   (vsplit)
  81.   (move-focus :down))
  82. ;; (loop :for i :in '("hsplit-and-focus"
  83. ;;                  "vsplit-and-focus")
  84. ;;       :do (dyn-blacklist-command i))
  85. (defcommand stump-or-emacs-vsplit () ()
  86.   (stump-or-emacs "hsplit-and-focus" "+evil/window-vsplit-and-follow"))
  87. (defcommand stump-or-emacs-hsplit () ()
  88.   (stump-or-emacs "vsplit-and-focus" "+evil/window-split-and-follow"))
  89. ;; Fullscreen buffer/window
  90. (defcommand stump-or-emacs-fullscreen () ()
  91.   (stump-or-emacs "fullscreen"
  92.                   "toggle-buffer-fullscreen"))
  93.  
Add Comment
Please, Sign In to add comment