emacs: revamp/rearrange exwm config
authorAmin Bandali <bandali@gnu.org>
Fri, 6 Sep 2019 16:12:48 +0000 (12:12 -0400)
committerAmin Bandali <bandali@gnu.org>
Fri, 6 Sep 2019 16:12:48 +0000 (12:12 -0400)
.emacs.d/init.el

index e88438f..847f282 100644 (file)
@@ -563,22 +563,27 @@ For disabling the behaviour for certain buffers and/or modes."
 (use-package exwm
   :demand
   :config
 (use-package exwm
   :demand
   :config
-  (require 'exwm-config)
-
-  (setq
-   exwm-workspace-number 4
-   exwm-workspace-index-map (lambda (i) (number-to-string (1+ i))))
-
-  ;; Make class name the buffer name, truncating beyond 60 characters
-  (defun exwm-rename-buffer ()
+  ;; make class name the buffer name, truncating beyond 60 characters
+  (defun b/exwm-rename-buffer ()
     (interactive)
     (exwm-workspace-rename-buffer
      (concat exwm-class-name ":"
              (if (<= (length exwm-title) 60) exwm-title
                (concat (substring exwm-title 0 59) "...")))))
     (interactive)
     (exwm-workspace-rename-buffer
      (concat exwm-class-name ":"
              (if (<= (length exwm-title) 60) exwm-title
                (concat (substring exwm-title 0 59) "...")))))
-  (add-hook 'exwm-update-class-hook 'exwm-rename-buffer)
-  (add-hook 'exwm-update-title-hook 'exwm-rename-buffer)
+  ;; Enable EXWM
+  (exwm-enable)
+  :hook ((exwm-update-class . b/exwm-rename-buffer)
+         (exwm-update-title . b/exwm-rename-buffer)))
+
+(use-feature exwm-config
+  :demand
+  :after exwm
+  :hook (exwm-init . exwm-config--fix/ido-buffer-window-other-frame))
 
 
+(use-feature exwm-input
+  :demand
+  :after exwm
+  :config
   (defun b/exwm-ws-prev-index ()
     "Return the index for the previous EXWM workspace, wrapping
 around if needed."
   (defun b/exwm-ws-prev-index ()
     "Return the index for the previous EXWM workspace, wrapping
 around if needed."
@@ -594,138 +599,90 @@ around if needed."
         0
       (1+ exwm-workspace-current-index)))
 
         0
       (1+ exwm-workspace-current-index)))
 
-  ;; 's-R': Reset
-  (exwm-input-set-key (kbd "s-R") #'exwm-reset)
-  ;; 's-\': Switch workspace
-  (exwm-input-set-key (kbd "s-\\") #'exwm-workspace-switch)
-  ;; 's-N': Switch to certain workspace
-  (dotimes (i exwm-workspace-number)
-    (exwm-input-set-key
-     (kbd (format "s-%d" i))
-     (lambda ()
-       (interactive)
-       (exwm-workspace-switch-create (1- i)))))
-  ;; 's-[': Switch to previous workspace
-  (defun b/exwm-ws-prev ()
-    "Switch to previous EXWM workspace, wrapping around if needed."
-    (interactive)
-    (exwm-workspace-switch-create (b/exwm-ws-prev-index)))
-  (exwm-input-set-key (kbd "s-[") #'b/exwm-ws-prev)
-  ;; 's-]': Switch to next workspace
-  (defun b/exwm-ws-next ()
-    "Switch to next EXWM workspace, wrapping around if needed."
-    (interactive)
-    (exwm-workspace-switch-create (b/exwm-ws-next-index)))
-  (exwm-input-set-key (kbd "s-]") #'b/exwm-ws-next)
-  ;; 's-{': Move window to previous workspace
-  (defun b/exwm-move-window-to-prev-ws ()
-    "Move window to previous EXWM workspace, wrapping around if
-needed."
-    (interactive)
-    (exwm-workspace-move-window (b/exwm-ws-prev-index)))
-  (exwm-input-set-key (kbd "s-{") #'b/exwm-move-window-to-prev-ws)
-  ;; 's-}': Move window to next workspace
-  (defun b/exwm-move-window-to-next-ws ()
-    "Move window to next EXWM workspace, wrapping around if
-needed."
-    (interactive)
-    (exwm-workspace-move-window (b/exwm-ws-next-index)))
-  (exwm-input-set-key (kbd "s-}") #'b/exwm-move-window-to-next-ws)
-  ;; 's-SPC': Launch application
-  ;; (exwm-input-set-key
-  ;;  (kbd "s-SPC")
-  ;;  (lambda (command)
-  ;;    (interactive (list (read-shell-command "➜ ")))
-  ;;    (start-process-shell-command command nil command)))
-
-  (exwm-input-set-key (kbd "M-s-SPC") #'counsel-linux-app)
-
-  (exwm-input-set-key
-   (kbd "s-<return>") (lambda ()
-                        (interactive)
-                        (b/start-process "urxvt")))
-
-  (exwm-input-set-key
-   (kbd "s-t")
-   (lambda ()
-     (interactive)
-     (exwm-floating-toggle-floating)))
-
-  (exwm-input-set-key
-   (kbd "s-f")
-   (lambda ()
-     (interactive)
-     (exwm-layout-toggle-fullscreen)))
-
-  (exwm-input-set-key
-   (kbd "s-w")
-   (lambda ()
-     (interactive)
-     (kill-buffer (current-buffer))))
-
-  (exwm-input-set-key
-   (kbd "s-q")
-   (lambda ()
-     (interactive)
-     (exwm-manage--kill-client)))
-
-  ;; (exwm-input-set-key
-  ;;  (kbd "s-SPC")  ;; rofi doesn't properly launch programs when started from emacs
-  ;;  (lambda ()
-  ;;    (interactive)
-  ;;    (start-process-shell-command "rofi-run" nil "rofi -show run -display-run '> ' -display-window ' 🗔 '")))
-
-  ;; (exwm-input-set-key
-  ;;  (kbd "s-/")
-  ;;  (lambda ()
-  ;;    (interactive)
-  ;;    (start-process-shell-command "rofi-win" nil "rofi -show window  -display-run '> ' -display-window ' 🗔 '")))
-
-  ;; (exwm-input-set-key
-  ;;  (kbd "M-SPC")
-  ;;  (lambda ()
-  ;;    (interactive)
-  ;;    (start-process "rofi-pass" nil "rofi-pass")))
-
-  (exwm-input-set-key
-   (kbd "<XF86AudioMute>")
-   (lambda ()
-     (interactive)
-     (start-process-shell-command "pamixer" nil "pamixer --toggle-mute")))
-
-  (exwm-input-set-key
-   (kbd "<XF86AudioLowerVolume>")
-   (lambda ()
-     (interactive)
-     (start-process-shell-command "pamixer" nil "pamixer --allow-boost --decrease 5")))
-
-  (exwm-input-set-key
-   (kbd "<XF86AudioRaiseVolume>")
-   (lambda ()
-     (interactive)
-     (start-process-shell-command "pamixer" nil "pamixer --allow-boost --increase 5")))
-
-  (exwm-input-set-key
-   (kbd "<XF86AudioPlay>")
-   (lambda ()
-     (interactive)
-     (start-process-shell-command "mpc" nil "mpc toggle")))
-
-  (exwm-input-set-key
-   (kbd "<XF86AudioPrev>")
-   (lambda ()
-     (interactive)
-     (start-process-shell-command "mpc" nil "mpc prev")))
-
-  (exwm-input-set-key
-   (kbd "<XF86AudioNext>")
-   (lambda ()
-     (interactive)
-     (start-process-shell-command "mpc" nil "mpc next")))
-
-  ;; Shorten 'C-c C-q' to 'C-q'
+  ;; shorten 'C-c C-q' to 'C-q'
   (define-key exwm-mode-map [?\C-q] #'exwm-input-send-next-key)
 
   (define-key exwm-mode-map [?\C-q] #'exwm-input-send-next-key)
 
+  (setq exwm-input-global-keys
+        `(([?\s-R] . exwm-reset)
+          ([?\s-\\] . exwm-workspace-switch)
+          ([?\s-\s] . (lambda (command)
+                        (interactive
+                         (list (read-shell-command "➜ ")))
+                        (start-process-shell-command
+                         command nil command)))
+          ([s-return] . (lambda ()
+                          (interactive)
+                          (start-process "" nil "urxvt")))
+          ([?\C-\s-\s] . counsel-linux-app)
+          ([?\M-\s-\s] . (lambda ()
+                           (interactive)
+                           (start-process-shell-command
+                            "rofi-pass" nil "rofi-pass")))
+          ([?\s-\[] . (lambda ()
+                        (interactive)
+                        (exwm-workspace-switch-create
+                         (b/exwm-ws-prev-index))))
+          ([?\s-\]] . (lambda ()
+                        (interactive)
+                        (exwm-workspace-switch-create
+                         (b/exwm-ws-next-index))))
+          ([?\s-{] . (lambda ()
+                       (interactive)
+                       (exwm-workspace-move-window
+                        (b/exwm-ws-prev-index))))
+          ([?\s-}] . (lambda ()
+                       (interactive)
+                       (exwm-workspace-move-window
+                        (b/exwm-ws-next-index))))
+          ,@(mapcar (lambda (i)
+                      `(,(kbd (format "s-%d" i)) .
+                        (lambda ()
+                          (interactive)
+                          (exwm-workspace-switch-create ,i))))
+                    (number-sequence 0 (1- exwm-workspace-number)))
+          ([?\s-t] . exwm-floating-toggle-floating)
+          ([?\s-f] . exwm-layout-toggle-fullscreen)
+          ([?\s-w] . (lambda ()
+                       (interactive)
+                       (kill-buffer (current-buffer))))
+          ([?\s-q] . (lambda ()
+                       (interactive)
+                       (exwm-manage--kill-client)))
+          ([?\s-\'] . (lambda ()
+                        (interactive)
+                        (start-process-shell-command
+                         "rofi-light" nil "rofi-light")))
+          ([XF86AudioMute] .
+           (lambda ()
+             (interactive)
+             (start-process "" nil "pamixer" "--toggle-mute")))
+          ([XF86AudioLowerVolume] .
+           (lambda ()
+             (interactive)
+             (start-process
+              "" nil "pamixer" "--allow-boost" "--decrease" "5")))
+          ([XF86AudioRaiseVolume] .
+           (lambda ()
+             (interactive)
+             (start-process
+              "" nil "pamixer" "--allow-boost" "--increase" "5")))
+          ([XF86AudioPlay] .
+           (lambda ()
+             (interactive)
+             (start-process "" nil "mpc" "toggle")))
+          ([XF86AudioPrev] .
+           (lambda ()
+             (interactive)
+             (start-process "" nil "mpc" "prev")))
+          ([XF86AudioNext] .
+           (lambda ()
+             (interactive)
+             (start-process "" nil "mpc" "next")))
+          ([XF86ScreenSaver] .
+           (lambda ()
+                    (interactive)
+                    (start-process "" nil "dm-tool" "lock")))))
+
   ;; Line-editing shortcuts
   (setq exwm-input-simulation-keys
     '(;; movement
   ;; Line-editing shortcuts
   (setq exwm-input-simulation-keys
     '(;; movement
@@ -741,6 +698,8 @@ needed."
       ([?\C-v] . [next])
       ([?\C-d] . [delete])
       ([?\C-k] . [S-end ?\C-x])
       ([?\C-v] . [next])
       ([?\C-d] . [delete])
       ([?\C-k] . [S-end ?\C-x])
+      ([?\M-<] . C-home)
+      ([?\M->] . C-end)
       ;; cut/copy/paste
       ([?\C-w] . [?\C-x])
       ([?\M-w] . [?\C-c])
       ;; cut/copy/paste
       ([?\C-w] . [?\C-x])
       ([?\M-w] . [?\C-c])
@@ -750,18 +709,25 @@ needed."
       ;; search
       ([?\C-s] . [?\C-f])
       ;; escape
       ;; search
       ([?\C-s] . [?\C-f])
       ;; escape
-      ([?\C-g] . [escape])))
+      ([?\C-g] . [escape]))))
 
 
-  ;; Enable EXWM
-  (exwm-enable)
-
-  (add-hook 'exwm-init-hook #'exwm-config--fix/ido-buffer-window-other-frame)
+(use-feature exwm-randr
+  :demand
+  :after exwm
+  :config
+  (exwm-randr-enable))
 
 
-  (require 'exwm-systemtray)
-  (exwm-systemtray-enable)
+(use-feature exwm-systemtray
+  :demand
+  :after exwm
+  :config
+  (exwm-systemtray-enable))
 
 
-  (require 'exwm-randr)
-  (exwm-randr-enable))
+(use-feature exwm-workspace
+  :demand
+  :after exwm
+  :custom
+  (exwm-workspace-number 4))
 
 ;; use the org-plus-contrib package to get the whole deal
 (use-package org-plus-contrib)
 
 ;; use the org-plus-contrib package to get the whole deal
 (use-package org-plus-contrib)