~thecatster/.emacs.d

ca6c46a2841f6715d4ffc86043a1bf78e2a9a13a — Daniel Rose 2 years ago 76a9de8
Add pulseaudio control and update start-exwm.sh
5 files changed, 48 insertions(+), 191 deletions(-)

M emacs.org
M exwm.org
M exwm/start-exwm.sh
M init.el
M lisp/catsters-exwm.el
M emacs.org => emacs.org +20 -6
@@ 291,6 291,7 @@ that default. Also allow me to reopen a file as root automatically.
(setq tramp-default-method "ssh")

(use-package auto-sudoedit
  :diminish auto-sudoedit-mode
  :config
  (auto-sudoedit-mode 1))
#+END_SRC


@@ 550,9 551,6 @@ and everyone seems to be using it!
#+BEGIN_SRC emacs-lisp
  (use-package doom-modeline
    :hook (after-init . doom-modeline-init)
    :custom-face
    (mode-line ((t (:height 0.85))))
    (mode-line-inactive ((t (:height 0.85))))
    :custom
    (doom-modeline-height 15)
    (doom-modeline-bar-width 6)


@@ 1503,6 1501,17 @@ wttr.in Emacs!
  (wttrin-default-cities '("Lancaster")))
#+END_SRC

** Pulseaudio Control
Why not control pulseaudio/pipewire in Emacs as well? Especially
useful when using EXWM, as always having to use pamixer is a bit
annoying.

#+BEGIN_SRC emacs-lisp
(use-package pulseaudio-control
  :init
  (pulseaudio-control-default-keybindings))
#+END_SRC

** Ytel
Ytel is an Emacs "frontend" for Invidious/YouTube, which plays using
mpv. Pretty cool!


@@ 1659,6 1668,7 @@ Makes code easier to read, and specifically on these, as I do not want rainbow t

#+BEGIN_SRC emacs-lisp
(use-package rainbow-delimiters
  :diminish rainbow-delimiters-mode
  :hook ((hy-mode python-mode rustic-mode c-mode js-mode rjsx-mode web-mode css-mode html-mode) . rainbow-delimiters-mode))
#+END_SRC



@@ 1666,6 1676,7 @@ See colors easily!

#+BEGIN_SRC emacs-lisp
(use-package rainbow-mode
  :diminish rainbow-mode
  :hook ((org-mode emacs-lisp-mode web-mode typescript-mode rjsx-mode) . rainbow-mode)
  :config
  (setq rainbow-x-colors nil))


@@ 1714,7 1725,7 @@ phenomenal, allowing for a proper debugging experience within Emacs
           scala-mode) . lsp)
         (lsp-mode . lsp-enable-which-key-integration))
  :commands (lsp)
  :config
  :init
  (setq  lsp-keymap-prefix "C-c l"
         lsp-eslint-run "onSave"
         lsp-completion-provider :capf


@@ 1725,7 1736,7 @@ phenomenal, allowing for a proper debugging experience within Emacs
(use-package lsp-ui
  :hook (lsp-mode . lsp-ui-mode)
  :commands lsp-ui-mode
  :config
  :init
  (setq lsp-ui-sideline-show-hover nil
        lsp-ui-sideline-enable t
        lsp-ui-doc-enable nil


@@ 1784,6 1795,7 @@ completely be accepted. Most of my work nowadays is done in Rust.
(use-package ron-mode)

(use-package rustic
  :after lsp-mode
  :bind (:map rustic-mode-map
              ("C-c C-c l" . flycheck-list-errors)
              ("M-?" . lsp-find-references)


@@ 1821,10 1833,12 @@ development and getting ideas down.

#+BEGIN_SRC emacs-lisp
(use-package lsp-python-ms
  :after lsp-mode
  :defer 0.3
  :custom (lsp-python-ms-auto-install-server t))

(use-package python
  :after lsp-mode
  :delight "π "
  :bind (("M-[" . python-nav-backward-block)
         ("M-]" . python-nav-forward-block))


@@ 2383,7 2397,7 @@ Although EXWM is in another file, I still need to require it in my
main config.

#+BEGIN_SRC emacs-lisp
(setq catster/use-exwm t)
(setq catster/use-exwm nil)

(when catster/use-exwm
   (require 'catsters-exwm))

M exwm.org => exwm.org +9 -107
@@ 19,7 19,7 @@ Due to *the problem,* I follow the general idea of opening another
Emacs instance for the larger programs I need to run that may
crash. Heavy programs get their own Emacs instance as well.

So what is a ``heavy'' program in my experience?
So what is a "heavy" program in my experience?
- Literate files of large size (and I mean large size)
- +Zoom+ (not true anymore, as I use Zoom in the browser)
- Literally any Electron app (I don't trust any of them, and they take


@@ 35,12 35,6 @@ another Emacs instance) I go by this rule of thumb:
- Unsure? Container it to play it safe, and then when not working on
  critical material try it without

Set this according to if you are using EXWM or not!

#+BEGIN_SRC emacs-lisp
(setq use-exwm t)
#+END_SRC

* Server
If I'm using EXWM, that means I don't have the systemd service on for Emacs. Start the server:



@@ 60,12 54,6 @@ all the programs I need to initiate at start and whatever else. This
is the same for every machine.

#+BEGIN_SRC sh :tangle exwm/start-exwm.sh :shebang #!/bin/sh
# Disable access control for the current user.
xhost +SI:localuser:$USER

# Make Java applications aware this is a non-reparenting window manager, same issues as dwm.
export _JAVA_AWT_WM_NONREPARENTING=1

## Run site init scripts. Usually not necessary.
if [ -d /etc/X11/xinit/xinitrc.d ] ; then
    for f in /etc/X11/xinit/xinitrc.d/?*.sh ; do


@@ 77,57 65,21 @@ fi
. ~/.emacs.d/exwm/exwm_screen_layout
~/.emacs.d/exwm/exwm_xrandr.bash

# Run Xmodmap for key rebindings
~/.emacs.d/exwm/set_xmodmap.sh

# Try to control screen blanking
xset s off dpms 1200 1400 1600 &

# Set default cursor, instead of the typical "x."
xsetroot -cursor_name left_ptr

# Start NetworkManager applet for easier WiFi access and preventing network-manager-config from crashing (why does that happen?)
nm-applet &

# Start Nextcloud for file syncing
nextcloud &

# Enable "Num Lock" mode, on keyboard keypad
numlockx on &

# Instead of launching multiple Emacsen, I already have a server
# running. Use that instead as the EDITOR.
export VISUAL=emacsclient
export EDITOR="$VISUAL"

# Keyring
eval $(/usr/bin/gnome-keyring-daemon --start)
export SSH_AUTH_SOCK

# Allows scrolling in GTK 3 apps
export GDK_CORE_DEVICE_EVENTS=1

source ~/.zprofile

exec emacs --eval "(dw/start-panel)" --eval "(require 'exwm)" -f exwm-enable
#+END_SRC

*** set_xmodmap.sh
Also the same. I promise there is change eventually. This actually
does the action of setting the Xmodmap.

#+BEGIN_SRC sh :tangle exwm/set_xmodmap.sh :shebang #!/bin/sh
# This script is called on startup to remap keys.
# Increase key speed via a rate change
xset r rate 300 50
# Map the caps lock key to super...
setxkbmap -option caps:super
# But when it is pressed only once, treat it as escape.
killall xcape 2>/dev/null ; xcape -e 'Super_L=Escape'
# Map the menu button to right super as well.
xmodmap -e 'keycode 135 = Super_R'
# Turn off the caps lock if on since there is no longer a key for it.
xset -q | grep "Caps Lock:\s*on" && xdotool key Caps_Lock
exec dbus-launch emacs --eval "(dw/start-panel)" --eval "(require 'exwm)" -f exwm-enable
#+END_SRC

*** exwm_screen_layout


@@ 318,10 270,10 @@ define exwm-randr-workspace-monitor-plist, and call "(exwm-randr-enable)".
exwm-randr-screen-change-hook.

#+BEGIN_SRC emacs-lisp
(when use-exwm
 (use-package exwm)
(use-package exwm)
(require 'exwm)
(require 'exwm-randr)

(defun jw/env-list (env-string)
  "Return list of strings in environment variable env-string.
nil if empty or undefined."


@@ 329,6 281,7 @@ nil if empty or undefined."
    (if env-var
        (split-string env-var)
      nil)))

(defun jw/env-str (env-string)
  "Return string in environment variable env-string.
nil if empty or undefined."


@@ 344,7 297,6 @@ nil if empty or undefined."
      (setq first (string-to-number (car (cdr rev-list))))
      (setq transformed-list (cons first (cons second transformed-list)))
      (setq rev-list (cdr (cdr rev-list))))

    transformed-list))

(defun jw/xrandr-output-list ()


@@ 523,48 475,6 @@ nil if empty or undefined."
My Polybar displays all the information I need, has a systray, and
looks decent imho!

#+BEGIN_SRC emacs-lisp
(defun dw/send-polybar-hook (name number)
  (start-process-shell-command "polybar-msg" nil (format "polybar-msg hook %s %s" name number)))

(defun dw/update-polybar-exwm (&optional path)
  (dw/send-polybar-hook "exwm" 1)
  (dw/send-polybar-hook "exwm-path" 1))

(defun dw/polybar-exwm-workspace ()
  (pcase exwm-workspace-current-index
    (0 "0")
    (1 "1")
    (2 "2")
    (3 "3")
    (4 "4")
    (5 "5")
    (6 "6")
    (7 "7")
    (8 "8")
    (9 "9")))

(defun dw/polybar-exwm-workspace-path ()
  (let ((workspace-path (frame-parameter nil 'bufler-workspace-path-formatted)))
    (if workspace-path
        (substring-no-properties workspace-path)
      "")))

(defun dw/telega-normalize-name (chat-name)
  (let* ((trimmed-name (string-trim-left (string-trim-right chat-name "}") "◀{"))
         (first-name (nth 0 (split-string trimmed-name " "))))
    first-name))

(defun dw/propertized-to-polybar (buffer-name)
  (if-let* ((text (substring-no-properties buffer-name))
            (fg-face (get-text-property 0 'face buffer-name))
            (fg-color (face-attribute fg-face :foreground)))
    (format "%%{F%s}%s%%{F-}" fg-color (dw/telega-normalize-name text))
    text))

(add-hook 'exwm-workspace-switch-hook #'dw/update-polybar-exwm)
#+END_SRC

#+BEGIN_SRC conf :tangle ~/.config/polybar/config :noweb yes
; Docs: https://github.com/polybar/polybar
;==========================================================


@@ 609,13 519,13 @@ padding-right = 1

module-margin = 1

font-0 = "JuliaMono:size=9:weight=bold;2"
font-0 = "JetBrainsMono Nerd Font:size=10:weight=bold;2"
font-1 = "Font Awesome 5 Free Regular:size=10;2"
font-2 = "Font Awesome 5 Free Solid:size=12;5"
font-3 = "Font Awesome 5 Brands:size=10;5"
font-4 = "JuliaMono:size=9;-3"

modules-left = exwm date
modules-left = date
modules-center = pulseaudio spotify
modules-right = backlight cpu memory battery



@@ 626,14 536,6 @@ tray-maxsize = 28
cursor-click = pointer
cursor-scroll = ns-resize

[module/exwm]
type = custom/ipc
hook-0 = emacsclient -e "(dw/polybar-exwm-workspace)" | sed -e 's/^"//' -e 's/"$//'
initial = 1
format-underline = ${colors.underline-1}
format-background = ${colors.background-alt}
format-padding = 1

[module/spotify]
type = custom/script
exec = ~/.config/polybar/player-status.sh


@@ 1010,7 912,7 @@ Below is my main configuration for EXWM, with 10 workspaces (0-9).
     (exwm-mff-mode 1))
  ;; This causes issues in performance for me for some strange reason,
  ;; so I disable it.
   (setq focus-follows-mouse nil)
   (setq focus-follows-mouse t)
   (setq x-wait-for-event-timeout nil)
  ;; Configure Ido
   (my-exwm-config-ido)


@@ 1067,7 969,7 @@ You can find the original one at `exwm-config-ido-buffer-window-other-frame'."
   (interactive)
   (exwm-workspace-rename-buffer (concat exwm-class-name " : " (substring exwm-title 0 (min 12 (length exwm-title))))))

 (my-exwm-config-setup)) ;; Does not start X11 or EXWM. Start should be done from commandline.
 (my-exwm-config-setup) ;; Does not start X11 or EXWM. Start should be done from commandline.

(provide 'catsters-exwm)
;;; catsters-exwm.el ends here

M exwm/start-exwm.sh => exwm/start-exwm.sh +1 -25
@@ 1,10 1,4 @@
#!/bin/sh
# Disable access control for the current user.
xhost +SI:localuser:$USER

# Make Java applications aware this is a non-reparenting window manager, same issues as dwm.
export _JAVA_AWT_WM_NONREPARENTING=1

## Run site init scripts. Usually not necessary.
if [ -d /etc/X11/xinit/xinitrc.d ] ; then
    for f in /etc/X11/xinit/xinitrc.d/?*.sh ; do


@@ 16,36 10,18 @@ fi
. ~/.emacs.d/exwm/exwm_screen_layout
~/.emacs.d/exwm/exwm_xrandr.bash

# Run Xmodmap for key rebindings
~/.emacs.d/exwm/set_xmodmap.sh

# Try to control screen blanking
xset s off dpms 1200 1400 1600 &

# Set default cursor, instead of the typical "x."
xsetroot -cursor_name left_ptr

# Start NetworkManager applet for easier WiFi access and preventing network-manager-config from crashing (why does that happen?)
nm-applet &

# Start Nextcloud for file syncing
nextcloud &

# Enable "Num Lock" mode, on keyboard keypad
numlockx on &

# Instead of launching multiple Emacsen, I already have a server
# running. Use that instead as the EDITOR.
export VISUAL=emacsclient
export EDITOR="$VISUAL"

# Keyring
eval $(/usr/bin/gnome-keyring-daemon --start)
export SSH_AUTH_SOCK

# Allows scrolling in GTK 3 apps
export GDK_CORE_DEVICE_EVENTS=1

source ~/.zprofile

exec emacs --eval "(dw/start-panel)" --eval "(require 'exwm)" -f exwm-enable
exec dbus-launch emacs --eval "(dw/start-panel)" --eval "(require 'exwm)" -f exwm-enable

M init.el => init.el +13 -6
@@ 165,6 165,7 @@
(setq tramp-default-method "ssh")

(use-package auto-sudoedit
  :diminish auto-sudoedit-mode
  :config
  (auto-sudoedit-mode 1))



@@ 294,9 295,6 @@

(use-package doom-modeline
  :hook (after-init . doom-modeline-init)
  :custom-face
  (mode-line ((t (:height 0.85))))
  (mode-line-inactive ((t (:height 0.85))))
  :custom
  (doom-modeline-height 15)
  (doom-modeline-bar-width 6)


@@ 1057,6 1055,10 @@
  :custom
  (wttrin-default-cities '("Lancaster")))

(use-package pulseaudio-control
  :init
  (pulseaudio-control-default-keybindings))

;; (use-package ytel
;;   :custom
;;   (ytel-invidious-api-url "https://invidious.exonip.de")


@@ 1132,9 1134,11 @@
  (setq parinfer-rust-preferred-mode 'paren))

(use-package rainbow-delimiters
  :diminish rainbow-delimiters-mode
  :hook ((hy-mode python-mode rustic-mode c-mode js-mode rjsx-mode web-mode css-mode html-mode) . rainbow-delimiters-mode))

(use-package rainbow-mode
  :diminish rainbow-mode
  :hook ((org-mode emacs-lisp-mode web-mode typescript-mode rjsx-mode) . rainbow-mode)
  :config
  (setq rainbow-x-colors nil))


@@ 1163,7 1167,7 @@
           scala-mode) . lsp)
         (lsp-mode . lsp-enable-which-key-integration))
  :commands (lsp)
  :config
  :init
  (setq  lsp-keymap-prefix "C-c l"
         lsp-eslint-run "onSave"
         lsp-completion-provider :capf


@@ 1174,7 1178,7 @@
(use-package lsp-ui
  :hook (lsp-mode . lsp-ui-mode)
  :commands lsp-ui-mode
  :config
  :init
  (setq lsp-ui-sideline-show-hover nil
        lsp-ui-sideline-enable t
        lsp-ui-doc-enable nil


@@ 1211,6 1215,7 @@
(use-package ron-mode)

(use-package rustic
  :after lsp-mode
  :bind (:map rustic-mode-map
              ("C-c C-c l" . flycheck-list-errors)
              ("M-?" . lsp-find-references)


@@ 1234,10 1239,12 @@
  (add-hook 'rustic-mode-hook 'cargo-minor-mode))

(use-package lsp-python-ms
  :after lsp-mode
  :defer 0.3
  :custom (lsp-python-ms-auto-install-server t))

(use-package python
  :after lsp-mode
  :delight "π "
  :bind (("M-[" . python-nav-backward-block)
         ("M-]" . python-nav-forward-block))


@@ 1670,7 1677,7 @@
      (if (and b e (< (point) e)) (setq rlt nil)))
    (setq ad-return-value rlt)))

(setq catster/use-exwm t)
(setq catster/use-exwm nil)

(when catster/use-exwm
   (require 'catsters-exwm))

M lisp/catsters-exwm.el => lisp/catsters-exwm.el +5 -47
@@ 1,13 1,11 @@
(setq use-exwm t)

(require 'server)
(unless (server-running-p)
   (server-start))

(when use-exwm
 (use-package exwm)
(use-package exwm)
(require 'exwm)
(require 'exwm-randr)

(defun jw/env-list (env-string)
  "Return list of strings in environment variable env-string.
nil if empty or undefined."


@@ 15,6 13,7 @@ nil if empty or undefined."
    (if env-var
        (split-string env-var)
      nil)))

(defun jw/env-str (env-string)
  "Return string in environment variable env-string.
nil if empty or undefined."


@@ 30,7 29,6 @@ nil if empty or undefined."
      (setq first (string-to-number (car (cdr rev-list))))
      (setq transformed-list (cons first (cons second transformed-list)))
      (setq rev-list (cdr (cdr rev-list))))

    transformed-list))

(defun jw/xrandr-output-list ()


@@ 204,46 202,6 @@ nil if empty or undefined."
(add-hook 'exwm-randr-screen-change-hook 'jw/exwm-change-screen-hook)
(exwm-randr-enable)

(defun dw/send-polybar-hook (name number)
  (start-process-shell-command "polybar-msg" nil (format "polybar-msg hook %s %s" name number)))

(defun dw/update-polybar-exwm (&optional path)
  (dw/send-polybar-hook "exwm" 1)
  (dw/send-polybar-hook "exwm-path" 1))

(defun dw/polybar-exwm-workspace ()
  (pcase exwm-workspace-current-index
    (0 "0")
    (1 "1")
    (2 "2")
    (3 "3")
    (4 "4")
    (5 "5")
    (6 "6")
    (7 "7")
    (8 "8")
    (9 "9")))

(defun dw/polybar-exwm-workspace-path ()
  (let ((workspace-path (frame-parameter nil 'bufler-workspace-path-formatted)))
    (if workspace-path
        (substring-no-properties workspace-path)
      "")))

(defun dw/telega-normalize-name (chat-name)
  (let* ((trimmed-name (string-trim-left (string-trim-right chat-name "}") "◀{"))
         (first-name (nth 0 (split-string trimmed-name " "))))
    first-name))

(defun dw/propertized-to-polybar (buffer-name)
  (if-let* ((text (substring-no-properties buffer-name))
            (fg-face (get-text-property 0 'face buffer-name))
            (fg-color (face-attribute fg-face :foreground)))
    (format "%%{F%s}%s%%{F-}" fg-color (dw/telega-normalize-name text))
    text))

(add-hook 'exwm-workspace-switch-hook #'dw/update-polybar-exwm)

(require 'ido)
(use-package windower)
(use-package app-launcher


@@ 484,7 442,7 @@ See also `process-lines'."
     (exwm-mff-mode 1))
  ;; This causes issues in performance for me for some strange reason,
  ;; so I disable it.
   (setq focus-follows-mouse nil)
   (setq focus-follows-mouse t)
   (setq x-wait-for-event-timeout nil)
  ;; Configure Ido
   (my-exwm-config-ido)


@@ 541,7 499,7 @@ You can find the original one at `exwm-config-ido-buffer-window-other-frame'."
   (interactive)
   (exwm-workspace-rename-buffer (concat exwm-class-name " : " (substring exwm-title 0 (min 12 (length exwm-title))))))

 (my-exwm-config-setup)) ;; Does not start X11 or EXWM. Start should be done from commandline.
 (my-exwm-config-setup) ;; Does not start X11 or EXWM. Start should be done from commandline.

(provide 'catsters-exwm)
;;; catsters-exwm.el ends here