Paste number 345463: exwm config

Paste number 345463: exwm config
Pasted by: snape
When:4 years, 7 months ago
Share:Tweet this! | http://paste.lisp.org/+7EK7
Channel:None
Paste contents:
Raw Source | XML | Display As
;; https://github.com/ch11ng/exwm/wiki

(require 'exwm)
(require 'exwm-config)

(defmacro int (&rest body)
  `(lambda () (interactive) ,@body))

(defmacro my-key (key cmd)
  `(exwm-input-set-key (kbd ,key)
                       (lambda ()
                         (interactive)
                         (start-process-shell-command ,cmd nil ,cmd))))

(exwm-input-set-key (kbd "s-r") #'exwm-reset)
(exwm-input-set-key (kbd "s-w") #'exwm-workspace-switch)
(my-key "s-q" "pkill emacs")
(my-key "s-f" "firefox")
(my-key "s-x" "xterm")
(exwm-input-set-key (kbd "s-d") (int (shell-command "date")))
(my-key "<f5>" "setxkbmap us && xmodmap ~/.clem/dotfiles/Xmodmap")
(my-key "<f6>" "setxkbmap us -variant intl && xmodmap ~/.clem/dotfiles/Xmodmap")
(my-key "<f7>" "setxkbmap fr")
(my-key "<f9>" "amixer set Master toggle")
(my-key "<f10>" "amixer set Master 3%-")
(my-key "<f11>" "amixer set Master 3%+")
(my-key "<f12>" "~/.clem/misc/away")

(setq exwm-workspace-show-all-buffers t
      exwm-layout-show-all-buffers t)

(dotimes (i 10)
  (exwm-input-set-key (kbd (format "s-%d" i))
                      `(lambda ()
                         (interactive)
                         (exwm-workspace-switch-create ,i))))

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

;; Make class name the buffer name
(add-hook 'exwm-update-class-hook
          (lambda ()
            (exwm-workspace-rename-buffer exwm-class-name)))

(exwm-config-ido)
(exwm-enable)

;; compliance with evil-leader
(push ?\C-\  exwm-input-prefix-keys)

;; compliance with window-numbering-mode
(exwm-input-set-key (kbd "M-0") 'select-window-0)
(exwm-input-set-key (kbd "M-1") 'select-window-1)
(exwm-input-set-key (kbd "M-2") 'select-window-2)
(exwm-input-set-key (kbd "M-3") 'select-window-3)
(exwm-input-set-key (kbd "M-4") 'select-window-4)
(exwm-input-set-key (kbd "M-5") 'select-window-5)
(exwm-input-set-key (kbd "M-6") 'select-window-6)
(exwm-input-set-key (kbd "M-7") 'select-window-7)
(exwm-input-set-key (kbd "M-8") 'select-window-8)
(exwm-input-set-key (kbd "M-9") 'select-window-9)

;; compliance with smex
(exwm-input-set-key (kbd "M-x") 'smex)
(exwm-input-set-key (kbd "M-X") 'smex-major-mode-commands)


;; ido part: the goal is to exit ido with xterm


;; xterm
(defun spawn-xterm ()
  (interactive)
  (setq ido-default-directory default-directory)
  (start-process-shell-command "xterm" nil "xterm"))

(add-hook 'exwm-manage-finish-hook
          (lambda ()
            (when (and exwm-class-name
                       (string= exwm-class-name "XTerm"))
              ;; if called from ido, make sure xterm has ido default-directory
              (when (bound-and-true-p ido-default-directory)
                (setq default-directory ido-default-directory)
                (setq ido-default-directory nil)))))

(defun ido-exit-with-xterm ()
  (interactive)
  (with-no-warnings
    (setq ido-exit 'fallback fallback 'spawn-xterm))
  (exit-minibuffer))

(define-key ido-common-completion-map
  (kbd "C-x x") 'ido-exit-with-xterm)



;; this is in my .bashrc

# Send $PWD to emacs, as default-directory. This works because with EXWM, while
# being in xterm, current emacs buffer is (window-buffer (selected-window)).
# But without EXWM, (window-buffer (selected-window)) could be anything else.
cd() {
    builtin cd "$@" || return
    emacsclient --eval "\
(with-current-buffer\
  (window-buffer (selected-window))\
  (setq default-directory \"$PWD\"))" > /dev/null
}

This paste has no annotations.

Colorize as:
Show Line Numbers

Lisppaste pastes can be made by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively.