Skip to content

Instantly share code, notes, and snippets.

@paralin
Created October 25, 2017 01:41
Show Gist options
  • Save paralin/1a855cc9dfd0bb0a27f475be7296ba0e to your computer and use it in GitHub Desktop.
Save paralin/1a855cc9dfd0bb0a27f475be7296ba0e to your computer and use it in GitHub Desktop.
How to set up spacemacs as a desktop environment

XSession File

To add emacs to your login screen, add this file to /usr/share/xsessions/emacs.desktop:

[Desktop Entry]
Encoding=UTF-8
Exec=/usr/local/bin/startspacemacs
DesktopNames=EMacs
Name=SpaceMacs
Comment=SpaceMacsOS :)

Add this script to start emacs to /usr/local/bin/startspacemacs

#!/bin/sh

# Disable access control
xhost +SI:localuser:$USER

# Swap esc and caps lock
setxkbmap -option "caps:swapescape"

# Source profile
. $HOME/.profile

# Start Emacs
exec dbus-launch --exit-with-session emacs

And make it executable:

chmod +x /usr/local/bin/startspacemacs

SpaceMacs Configuration Changes

Edit your SpaceMacs config with SPC f e d

Add to dotspacemacs-additional-packages, adding the alert xelb and exwm lines so that it looks somewhat like this:

   dotspacemacs-additional-packages
   '(
     alert
     (xelb
      :location (recipe :fetcher github :repo "ch11ng/xelb"))
     (exwm
      :location (recipe :fetcher github :repo "ch11ng/exwm"))
   )

Add this function to your .spacemacs file just above the line defining dotspacemacs/user-config:

(defun setup-exwm ()
  (require 'exwm)
  (require 'exwm-config)
  (setq exwm-input--line-mode-passthrough t)

  ;; Pull up the buffer list
  (spacemacs/set-leader-keys "b l" 'list-buffers)

  ;; Set the initial workspace number.
  (setq exwm-workspace-number 2)
  ;; Make class name the buffer name
  (add-hook 'exwm-update-class-hook
            (lambda ()
              (setq exwm-input--line-mode-passthrough t)
              (exwm-workspace-rename-buffer exwm-class-name)
              ))

  ;; 's-w': Switch workspace
  ; (exwm-input-set-key (kbd "s-w") #'exwm-workspace-switch)
  (exwm-input-set-key (kbd "s-w") #'spacemacs/workspaces-transient-state/body)
  ;; s-h, s-j, s-k, s-l: move around
  (exwm-input-set-key (kbd "s-h") #'evil-window-left)
  (exwm-input-set-key (kbd "s-j") #'evil-window-down)
  (exwm-input-set-key (kbd "s-k") #'evil-window-up)
  (exwm-input-set-key (kbd "s-l") #'evil-window-right)
  ;; lock screen
  (exwm-input-set-key (kbd "C-M-l") #'lock-screen)
  (define-key global-map (kbd "C-M-l") #'lock-screen)
  (push ?\s-\  exwm-input-prefix-keys)

  ;; fn key bindings
  (exwm-input-set-key (kbd "<XF86AudioRaiseVolume>") #'turn-volume-up)
  (exwm-input-set-key (kbd "<XF86AudioLowerVolume>") #'turn-volume-down)
  (exwm-input-set-key (kbd "<XF86AudioMute>") #'toggle-volume-mute)
  (exwm-input-set-key (kbd "<XF86AudioPlay>") #'spotify-playpause)
  (exwm-input-set-key (kbd "<XF86AudioNext>") #'spotify-next)
  (exwm-input-set-key (kbd "<XF86AudioPrev>") #'spotify-previous)
  (exwm-input-set-key (kbd "<XF86KbdBrightnessUp>") #'kbd-brightness-up)
  (exwm-input-set-key (kbd "<XF86KbdBrightnessDown>") #'kbd-brightness-down)
  (exwm-input-set-key (kbd "<XF86LaunchA>") #'lock-screen)
  (exwm-input-set-key (kbd "<XF86LaunchB>") #'spacemacs/toggle-maximize-buffer)

  ;; 's-&': Launch application
  (exwm-input-set-key (kbd "s-&")
                     (lambda (command)
                      (interactive (list (read-shell-command "$ ")))
                     (start-process-shell-command command nil command)))

  ;; Enable EXWM
  (exwm-enable)
  ;; Configure Ido
  (exwm-config-ido)
  ;; Other configurations
  (exwm-config-misc)
)

Inside user-config at the beginning add:

  (setup-exwm)

  ;; s-h, s-j, s-k, s-l: move around
  ;; also defined below in exwm (defined both places for terminal mode compat)
  (define-key evil-motion-state-map (kbd "s-h") #'evil-window-left)
  (define-key evil-motion-state-map (kbd "s-j") #'evil-window-down)
  (define-key evil-motion-state-map (kbd "s-k") #'evil-window-up)
  (define-key evil-motion-state-map (kbd "s-l") #'evil-window-right)

  (require 'term)
  (define-key term-raw-map (kbd "s-c") (lambda () (interactive) (term-send-raw-string "\C-c")))
  (define-key term-raw-map (kbd "s-d") (lambda () (interactive) (term-send-raw-string "\C-d")))
  (define-key term-raw-map (kbd "s-r") (lambda () (interactive) (term-send-raw-string "\C-r")))

@RidaAyed
Copy link

I'm currently testing https://github.com/timor/spacemacsOS . Since its installation instruction is a bit ambigious (install here or here) and some keybindings are not working I'd be grateful if you could elaborate about your solution in comparison.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment