UP | HOME

Emacs Tipps & Tricks

Emacs is the Program I live in.

I don’t use Emacs for everything, because it is not best for everything, but any tool that cannot be integrated with Emacs requires considerably more context switches than if it can be integrated.

Also see the org-mode tipps. Org-mode is what binds Emacs together for me.

Other larger topics have their own articles:


PDF (drucken)

Simple EXWM setup

EXWM is a window manager running in Emacs. It’s actually awesome to work in it, though it still has some rough edges. I started using it when Gnome Shell killed my keyboard layout once too often when switching users and Chromium corrupted its shortcuts when I set my keyboard layout again.

I’m typing this from my Emacs running exwm.

Setup:

(use-package exwm :ensure t)
;; show the time in the modeline (also see the customization in the variables)
(display-time-mode)
;; Make buffer name more meaningful
(add-hook 'exwm-update-class-hook
          (lambda ()
          (exwm-workspace-rename-buffer exwm-class-name)))
(use-package pinentry
  :ensure t
  :config
  (pinentry-start))
(setq ediff-window-setup-function 'ediff-setup-windows-plain)

I currently start my session as normal in Gnome Shell (to get all the monitor setup and tweaks), then start Emacs and just run

M-x exwm-init

(answer yes: replace existing window manager)

Controlling pulseaudio from EXWM

I need mouse-controlled volume. The desktop-environment package provides it, but out of the box only for amixer. I adjusted it for pulseaudio.

Also I added the volume to the modline, with scrollwheel control: Scroll up or down to increase or decrease volume.

(use-package desktop-environment :ensure t
  :custom
  (desktop-environment-screenshot-directory "~/Bilder")
  (desktop-environment-volume-normal-decrement "-5%")
  (desktop-environment-volume-normal-increment "+5%")
  (desktop-environment-volume-get-command
   "LC_ALL=C pacmd list-sinks|grep -A 15 '* index'| awk '/volume: front/{ print $5 }' | sed 's/,//g'")
  (desktop-environment-volume-set-command "pactl set-sink-volume 1 %s")
  (desktop-environment-volume-small-decrement "-1%")
  (desktop-environment-volume-small-increment "+1%")
  :config
  (desktop-environment-mode)
  (global-set-key (kbd "M-σ") 'desktop-environment-volume-decrement-slowly)
  (global-set-key (kbd "M-π") 'desktop-environment-volume-increment-slowly)
  (global-set-key (kbd "M--") 'desktop-environment-volume-decrement)
  (global-set-key (kbd "M-+") 'desktop-environment-volume-increment))


(define-minor-mode display-volume-mode
  "Toggle display of volume in mode lines.

Depends on desktop-environment.

When Display Time mode is enabled, it queries the volume from
your system on every displaying using
desktop-environment-volume-get (which you can customize)."
  :global t :group 'desktop-environment
  (or global-mode-string (setq global-mode-string '("")))
  (setq display-volume-keymap (make-sparse-keymap))
  (define-key display-volume-keymap (kbd "<mode-line> <mouse-4>") 'desktop-environment-volume-increment-slowly)
  (define-key display-volume-keymap (kbd "<mode-line> <mouse-5>") 'desktop-environment-volume-decrement-slowly)
  (setq display-volume-modeline-entry
        '(:eval (propertize (format " V:%s%% "(desktop-environment-volume-get))
                            'keymap display-volume-keymap)))
  (if display-volume-mode
      (progn
        (or (memq display-volume-modeline-entry global-mode-string)
            (setq global-mode-string
                  (append global-mode-string (list display-volume-modeline-entry)))))))

(display-volume-mode)

elfeed and emms: listen to podcast with convenience

Elfeed enables the nicest podcast integration I know: Treat podcast entries as regular RSS entries, but hit A to enqueue them in emms.

Usage:

  • Prepare emms with M-x emms-playlist-mode-go
  • Update your feeds with M-x elfeed-update
  • Read your feeds with M-x elfeed; hit enter to open an entry, then n and p to switch between them quickly (that’s the speed I wish to have everywhere).
  • Hit A to enqueue the file in emms.
  • Start listening to media with M-x emms-start.
  • Keep queueing up further interesting entries from elfeed.
  • Do something else while listening :-)
  • Pause emms with M-x emms-pause when needed.

Save the window configuration to a register

With C-x r w LETTER (window-configuration-to-register) and C-x r j LETTER (jump-to-register) you can store and restore the the exact layout of buffers in Emacs. When you use exwm that’s almost a super-power, because you can prepare several exact window setups for different tasks, but it is also very useful in regular emacs usage

This is similar to switching between perspectives in Eclipse, but if you use exwm, this encompasses all programs.

Use the regular window splitting in Emacs (C-x 2 for each vertical split, C-x 3 for each horizontal split), then hit C-x r w LETTER to store the exact setup in the letter LETTER. Then hack away, move around, split and unify buffers, whatever you need. Then hit C-x r j LETTER to restore the saved setup, down to the positions of the cursors in all the files.

I have not used more than 3 side-by-side yet, but even like that this has already been a huge asset. You can also use the registers to store content, position in the file, and even the position of all Emacs windows. For details see https://www.emacswiki.org/emacs/Registers

[2022-06-18 Sa]

ArneBab 2022-01-06 Do 00:00 - Impressum - GPLv3 or later (code), cc by-sa (rest)