[exwm] create my-start-app-or-switch

This commit is contained in:
contrapunctus 2021-07-31 05:07:29 +05:30
parent 9322272b54
commit dfacd9ded4
1 changed files with 30 additions and 5 deletions

View File

@ -105,14 +105,39 @@ This needs to be before =boon=/=exwm=, or you get a "failed to define function i
(lambda ()
(exwm-workspace-rename-buffer exwm-title)))
(exwm-enable)
#+END_SRC
A less repetitive way to start processes. Also enables Boon in the process buffer, so I can easy navigate it, copy text in it, or switch away from it.
#+BEGIN_SRC emacs-lisp
(defun my-start-process (program &optional name &rest args)
"Run PROGRAM with ARGS in buffer NAME."
(interactive "P")
(let* ((name (if name name program))
(proc-buffer (generate-new-buffer-name name)))
(apply #'start-process name proc-buffer program args)
(with-current-buffer proc-buffer (boon-mode))))
#+END_SRC
#+BEGIN_SRC emacs-lisp
(defun my-start-app-or-switch (program &optional name exact-p &rest args)
"If NAME is a running application, switch to its EXWM buffer.
Otherwise, run PROGRAM with ARGS.
If EXACT-P is non-nil, the window title must match the name exactly."
(let* ((name (if name name program))
(regex (if exact-p (rx-to-string `(and bos ,name eos)) name))
(buffer (seq-find
(lambda (buffer)
(with-current-buffer buffer
(and exwm-title
(string-match-p regex exwm-title))))
(buffer-list))))
(if buffer (switch-to-buffer buffer)
(apply #'my-start-process program name args))))
#+END_SRC
Programs I want to run on startup.
#+BEGIN_SRC emacs-lisp
(my-start-process (expand-file-name "~/bin/kmonad") "kmonad"
(expand-file-name "~/kmonad.kbd"))
;; This form for xset works when I evaluate it with `eval-last-sexp', but when Emacs starts up the repeat rate is still set to something slower 🤔
@ -1418,12 +1443,12 @@ _u_: next word ^_l_: edit lines^ _s_: next whole symbol
#+BEGIN_SRC emacs-lisp
(defhydra my-external-hydra (:color red)
"What application?"
("g" (my-start-process "gajim") "Gajim")
("b"
(my-start-process "/media/data/anon/ext/tor-browser_en-US/Browser/start-tor-browser" "tor-browser")
("g" (my-start-app-or-switch "gajim" nil t) "Gajim")
("b" (my-start-app-or-switch "/media/data/anon/ext/tor-browser_en-US/Browser/start-tor-browser" "Tor Browser")
"Tor Browser")
("k" (my-start-process "keepassxc") "KeePassXC")
("t" (my-start-process "xfce4-terminal") "terminal"))
("B" (my-start-app-or-switch "/media/data/anon/ext/firefox/firefox" "firefox") "Firefox")
("k" (my-start-app-or-switch "keepassxc") "KeePassXC")
("t" (my-start-app-or-switch "xfce4-terminal" "terminal") "terminal"))
#+END_SRC
*** org
#+BEGIN_SRC emacs-lisp