#+PROPERTY: header-args :tangle yes :comments yes :results silent * Packages *** Use package Bootstrap `use-package' (from [[http://www.lunaryorn.com/2015/01/06/my-emacs-configuration-with-use-package.html][here]]) #+begin_src emacs-lisp (unless (package-installed-p 'use-package) (package-refresh-contents) (package-install 'use-package)) (require 'use-package) #+end_src *** Literate elisp and autotangle #+BEGIN_SRC emacs-lisp (use-package poly-org :ensure t) (use-package literate-elisp :ensure t) (use-package org-auto-tangle :ensure t :hook (org-mode . org-auto-tangle-mode) :diminish) #+END_SRC *** ELPA Keyring #+BEGIN_SRC emacs-lisp (use-package gnu-elpa-keyring-update :ensure t) #+END_SRC *** Loading .el newer than .elc files, and eln stuff #+begin_src emacs-lisp (setq load-prefer-newer t) (setq comp-async-report-warnings-errors nil warning-suppress-types '((comp))) #+end_src * Initialisation *** Portability macros From when we want our configurations to work on an apple tree... #+begin_src emacs-lisp (defmacro jao-syscase (clauses) (let ((cls (assoc system-type clauses))) (when cls `(progn ,@(cdr cls))))) (defmacro jao-d-l (darw linux) `(jao-syscase ((darwin ,darw) (gnu/linux ,linux)))) (defmacro jao-when-darwin (&rest body) `(jao-syscase ((darwin ,@body)))) (defmacro jao-when-linux (&rest body) `(jao-syscase ((gnu/linux ,@body)))) #+end_src *** Paths #+begin_src emacs-lisp (defvar jao-local-lisp-dir "~/lib/elisp" "Directory for external elisp libraries and repos") (defvar jao-data-dir (expand-file-name "data" jao-emacs-dir) "Directory containing static data, such as images.") (defun jao-data-file (file) (expand-file-name file jao-data-dir)) (defvar jao-org-dir (expand-file-name "~/org")) (defvar jao-sink-dir (file-name-as-directory (expand-file-name "~/doc/sink")) "Directory used for downloads and such.") (defvar jao-site-dir (expand-file-name "site" jao-emacs-dir)) (defun jao-site-el (basename &optional gpg) (expand-file-name (concat basename ".el" (when gpg ".gpg")) jao-site-dir)) (defun jao-load-site-el (basename &optional gpg) (let ((lf (jao-site-el basename gpg))) (if (file-exists-p lf) (load lf) (message "Attempted to load non existing %s" lf)))) (defun jao-load-org (file) (let ((file (format "%s.org" (file-name-sans-extension file)))) (literate-elisp-load-file (expand-file-name file jao-emacs-dir)))) (defun jao-exec-path (file) (let ((fn (expand-file-name file))) (add-to-list 'exec-path fn nil) (setenv "PATH" (concat fn ":" (getenv "PATH"))))) (defun jao-load-path (subdir) "Add to load path a subdir of `jao-local-lisp-dir'" (let ((path (expand-file-name subdir jao-local-lisp-dir))) (when (file-directory-p path) (add-to-list 'load-path path)))) #+end_src *** Load and info path initialisation #+begin_src emacs-lisp (add-to-list 'load-path jao-site-dir) (add-to-list 'load-path jao-local-lisp-dir) (let ((libd (expand-file-name "lib" jao-emacs-dir))) (add-to-list 'load-path libd) (dolist (f (directory-files libd t "^[^.]+$")) (when (file-directory-p f) (add-to-list 'load-path f)))) (defvar jao-info-dir (expand-file-name (jao-d-l "~/.emacs.d/info" "~/doc/info"))) (require 'info) (add-to-list 'Info-directory-list jao-info-dir) #+end_src *** Custom location of custom.el and co. #+begin_src emacs-lisp (setq custom-file (jao-site-el "custom")) ;; (load custom-file) (setq custom-unlispify-tag-names nil) (setq custom-buffer-done-kill t) (setq custom-raised-buttons nil) #+end_src *** Preamble (pre.el) #+begin_src emacs-lisp (jao-load-site-el "pre") #+end_src *** Session and history #+BEGIN_SRC emacs-lisp (setq backup-directory-alist (quote (("." . "~/.emacs.d/backups")))) (setq delete-old-versions t kept-new-versions 3 kept-old-versions 2) (require 'saveplace) (setq save-place-file (expand-file-name "~/.emacs.d/cache/places")) (save-place-mode 1) (setq recentf-save-file (expand-file-name "~/.emacs.d/cache/recentf") recentf-max-saved-items 2000 recentf-exclude '("/home/jao/\\.emacs\\.d/elpa.*/.*" ".*/.git/COMMIT_EDITMSG")) (require 'recentf) (recentf-mode 1) ;; Command history (setq savehist-file (expand-file-name "~/.emacs.d/cache/history")) (require 'savehist) (savehist-mode t) (setq savehist-additional-variables '(kill-ring search-ring regexp-search-ring) savehist-ignored-variables '(ido-file-history)) #+END_SRC *** yes/no, bell, startup message #+BEGIN_SRC emacs-lisp ;;; change yes/no for y/n (if (version< emacs-version "28") (fset 'yes-or-no-p 'y-or-n-p) (setq use-short-answers t)) (setq inhibit-startup-message t) (setq visible-bell t) #+END_SRC *** Server #+BEGIN_SRC emacs-lisp (setenv "EDITOR" "emacsclient") (when (not (daemonp)) (server-start)) #+END_SRC * System utilities *** Tramp #+begin_src emacs-lisp (setq tramp-mode nil) #+end_src *** Status, minibuffer #+begin_src emacs-lisp (use-package jao-minibuffer :commands (jao-minibuffer-add-variable jao-minibuffer-refresh)) ;; (setq enable-recursive-minibuffers t) #+end_src *** Sleep/awake #+begin_src emacs-lisp (use-package jao-sleep) (jao-sleep-dbus-register) #+end_src *** Process runners #+begin_src emacs-lisp (defun jao-exec-string (fmt &rest args) (string-trim (shell-command-to-string (apply 'format fmt args)))) (defun jao-exec (command) (interactive (list (read-shell-command "$ " (if current-prefix-arg (cons (concat " " (buffer-file-name)) 0) "")))) (start-process-shell-command command nil command)) (defmacro jao-def-exec (name &rest args) `(defun ,name (&rest other-args) (interactive) (start-process-shell-command ,(car args) "* jao-exec - console *" (string-join (append (list ,@args) other-args) " ")))) #+end_src *** App launcher #+begin_src emacs-lisp (jao-load-path "app-launcher") (use-package app-launcher :bind (("s-r" . app-launcher-run-app) ("H-s-r" . app-launcher-run-app))) #+end_src *** Brightness control #+begin_src emacs-lisp (jao-def-exec jao-bright-set-up "brightnessctl" "-q" "s" "5%+") (jao-def-exec jao-bright-set-down "brightnessctl" "-q" "s" "5%-") (defun jao-bright-show () (interactive) (message "%s" (thread-first (jao-exec-string "brightnessctl") (split-string "\n") (cadr) (string-trim)))) (defun jao-bright-up () (interactive) (jao-exec-string "brightnessctl -q s %%5+") (jao-bright-show)) (defun jao-bright-down () (interactive) (jao-exec-string "brightnessctl -q s %%5-") (jao-bright-show)) #+end_src *** Keyboard and hydra #+begin_src emacs-lisp (use-package repeat :config (setq repeat-echo-function #'repeat-echo-mode-line)) (when (> emacs-major-version 27) (repeat-mode)) (use-package hydra :ensure t) (use-package major-mode-hydra :ensure t :custom (major-mode-hydra-invisible-quit-key "q") :bind (("s-SPC" . major-mode-hydra) ("H-s-SPC" . major-mode-hydra) ("C-s-SPC" . major-mode-hydra))) (require 'major-mode-hydra) (defun jao-kb-toggle (&optional lyt) (interactive) (shell-command-to-string (or lyt (if (jao-kb-toggled-p) "setxkbmap us" "setxkbmap us -variant intl")))) (defun jao-kb-toggled-p () (not (string-empty-p (shell-command-to-string "setxkbmap -query|grep variant")))) (set-keyboard-coding-system 'latin-1) (set-language-environment "UTF-8") ;; must be set after current-language-environment (customize-set-variable 'default-input-method "catalan-prefix") (defun jao--set-kb-system (frame) (select-frame frame) (set-keyboard-coding-system 'latin-1) t) (add-to-list 'after-make-frame-functions 'jao--set-kb-system) #+end_src *** Battery #+begin_src emacs-lisp (use-package battery :init (setq battery-load-low 15 battery-load-critical 8 battery-mode-line-limit 40 battery-echo-area-format "%L %r %B (%p%% load, remaining time %t)" battery-mode-line-format " %b%p ")) (display-battery-mode 1) #+end_src * Crypto *** PGP, EPG, passwords #+begin_src emacs-lisp (setq epg-pinentry-mode 'loopback) (setq auth-source-debug nil) (require 'auth-source) (add-to-list 'auth-source-protocols '(local "local")) (setq auth-sources '("~/.emacs.d/authinfo.gpg" "~/.netrc")) (use-package epa-file :init (setq epa-file-cache-passphrase-for-symmetric-encryption t) :config (epa-file-enable)) (require 'epa-file) (defun jao--get-user/password (h) (let ((item (car (auth-source-search :type 'netrc :host h :max 1)))) (when item (let ((user (plist-get item :user)) (pwd (plist-get item :secret))) (list user (when pwd (funcall pwd))))))) #+end_src *** Pinentry #+begin_src emacs-lisp (use-package pinentry :ensure t) (pinentry-start) #+end_src * Fonts and colour themes *** Transparency #+begin_src emacs-lisp (defvar jao-frames-default-alpha (if (eq window-system 'pgtk) 100 90)) (defvar jao-transparent-p t) (defun jao-sway-set-transparency (level) (when jao-sway-enabled-p (let ((alpha (/ level 100.0))) (jao-swaymsg (format "[app_id=emacs] opacity %s" alpha))))) (defun jao-toggle-transparency (&optional all) (interactive "P") (setq jao-transparent-p (not jao-transparent-p)) (cond (jao-sway-enabled-p (jao-sway-set-transparency (if jao-transparent-p 90 100))) (all (let* ((trans (/= jao-frames-default-alpha 100)) (new-alpha (if trans 100 jao-frames-default-alpha)) (a `((alpha . (,new-alpha ,new-alpha))))) (modify-all-frames-parameters a))) ((/= (or (cadr (frame-parameter nil 'alpha)) 100) 100) (set-frame-parameter nil 'alpha '(100 100))) (t (set-frame-parameter nil 'alpha `(,jao-frames-default-alpha ,jao-frames-default-alpha))))) (defun jao-transparent-p () (if jao-sway-enabled-p jao-transparent-p (/= (or (cadr (frame-parameter nil 'alpha)) 100) 100))) (defun jao-set-transparency (level) (interactive "nOpacity (0-100): ") (let ((level (or level jao-frames-default-alpha))) (setq jao-transparent-p (< level 100)) (if jao-sway-enabled-p (jao-sway-set-transparency level) (set-frame-parameter nil 'alpha (list level level))))) #+end_src *** Fonts ***** Unicode fonts See [[https://emacs.stackexchange.com/questions/251/line-height-with-unicode-characters/5386#5386][fonts - Line height with unicode characters]] for a good discussion. #+begin_src emacs-lisp (defun jao--set-fontsets (frame) (set-fontset-font t 64257 "Quivira") (set-fontset-font t 'egyptian "Noto Sans Egyptian Hieroglyphs") (set-fontset-font t 'hangul "NanumGothicCoding") (set-fontset-font t 'unicode (face-attribute 'default :family)) (set-fontset-font t 'unicode-bmp (face-attribute 'default :family)) (set-fontset-font t 'symbol "Symbola-10") (set-fontset-font t 'greek "GFS Didot") (set-fontset-font t 'mathematical "FreeSerif") ;; boxes (set-fontset-font t '(9472 . 9599) "Source Code Pro") ;; variation selector-16 (set-fontset-font t 65039 "BabelStone Modern-1")) (jao--set-fontsets nil) (add-to-list 'after-make-frame-functions 'jao--set-fontsets) #+end_src ***** nobreak char display #+begin_src emacs-lisp (setq nobreak-char-display nil) #+end_src ***** list-fonts-display #+begin_src emacs-lisp (defun list-fonts-display (&optional matching) "Display a list of font-families available via font-config, in a new buffer. If the optional argument MATCHING is non-nil, only font families matching that regexp are displayed; interactively, a prefix argument will prompt for the regexp. The name of each font family is displayed using that family, as well as in the default font (to handle the case where a font cannot be used to display its own name)." (interactive (list (and current-prefix-arg (read-string "Display font families matching regexp: ")))) (let (families) (with-temp-buffer (shell-command "fc-list : family" t) (goto-char (point-min)) (while (not (eobp)) (let ((fam (buffer-substring (line-beginning-position) (line-end-position)))) (when (or (null matching) (string-match matching fam)) (push fam families))) (forward-line))) (setq families (sort families (lambda (x y) (string-lessp (downcase x) (downcase y))))) (let ((buf (get-buffer-create "*Font Families*"))) (with-current-buffer buf (erase-buffer) (dolist (family families) ;; We need to pick one of the comma-separated names to ;; actually use the font; choose the longest one because some ;; fonts have ambiguous general names as well as specific ;; ones. (let ((family-name (car (sort (split-string family ",") (lambda (x y) (> (length x) (length y)))))) (nice-family (replace-regexp-in-string "," ", " family))) (insert (concat (propertize nice-family 'face (list :family family-name)) " (" nice-family ")")) (newline))) (goto-char (point-min))) (display-buffer buf)))) #+end_src *** Themes #+begin_src emacs-lisp (defun jao-colors-scheme-dark-p () (equal "dark" (getenv "JAO_COLOR_SCHEME"))) (setq custom-theme-directory (expand-file-name "lib/themes" jao-emacs-dir)) (setq jao-frames-default-font "Hack-9") (require 'jao-themes) (defun jao-themes-setup () (let ((dark (jao-colors-scheme-dark-p))) (when window-system (load-theme (if dark 'jao-greenish 'jao-light) t)))) (when (not (eq window-system 'pgtk)) (jao-themes-setup)) (global-font-lock-mode 1) #+end_src * Help system *** Echos and suggestions #+begin_src emacs-lisp (setq suggest-key-bindings 5 echo-keystrokes 2) #+end_src *** Bookmarks #+BEGIN_SRC emacs-lisp (setq bookmark-default-file "~/.emacs.d/emacs.bmk" bookmark-fontify nil) #+END_SRC *** Helpful #+begin_src emacs-lisp :load no (use-package helpful :ensure t :custom ((helpful-max-buffers 20)) :config (setq helpful-switch-buffer-function #'pop-to-buffer-same-window) :bind (("C-h k" . helpful-key) ("C-h v" . helpful-variable) ("C-h f" . helpful-callable) ("C-h o" . helpful-symbol))) #+end_src *** Inform (links in info buffers) #+begin_src emacs-lisp (use-package inform :ensure t) #+end_src *** Man pages #+begin_src emacs-lisp (setq Man-notify-method 'aggressive) ;; pushy - same window #+end_src *** Recoll #+begin_src emacs-lisp (use-package jao-recoll) #+end_src * Window manager helpers *** exwm To start emacs in an exwm session we use the flag ~-f jao-exwm-enable~, which calls the function below enabling it. This function, in turn, loads exwm's configuration from [[./exwm.org][exwm.org]]. #+begin_src emacs-lisp (defvar jao-exwm-enabled-p nil) (defun jao-exwm-enable () (jao-load-org "exwm.org") (setq jao-exwm-enabled-p t) (display-time-mode -1) (jao-minibuffer-add-mode-line 90) (jao-ednc-setup 95) (exwm-enable) (jao-trisect t) (jao-exwm-xmobar) (jao-nm-applet) (message "Welcome to exwm")) #+end_src *** sway When starting emacs inside a sway session, we use ~-f jao-sway-enable~ and don't load any separate configuration file. #+begin_src emacs-lisp (defun jao-swaymsg (msg) (shell-command (format "swaymsg '%s' >/dev/null" msg))) (defmacro jao-def-swaymsg (name msg) `(defun ,(intern (format "jao-sway-%s" name)) () (interactive) (jao-swaymsg ,msg))) (jao-def-swaymsg firefox "[app_id=firefox] focus") (defvar jao-sway-enabled-p nil) (defun jao-sway-set-wallpaper (f) (jao-swaymsg (format "output * bg %s fill" f)) (make-symbolic-link f "~/.wallpaper.sway" t)) (defun jao-sway-run-or-focus (cmd &optional ws) (if (not (string-blank-p (shell-command-to-string (format "pidof %s" cmd)))) (jao-swaymsg (format "[app_id=%s] focus" cmd)) (jao-swaymsg (format "workspace %s" (or ws 2))) (start-process-shell-command cmd nil cmd))) (defun jao-sway-enable () (setq jao-sway-enabled-p t) (setq jao-browse-doc-use-emacs-p t) (setq jao-minibuffer-right-margin 1) (jao-toggle-inactive-mode-line t) (jao-trisect) (jao-set-transparency 92) (jao-themes-setup) (message "Welcome to sway")) #+end_src *** Wallpaper #+begin_src emacs-lisp (defvar jao-wallpaper-dir "~/.wallpapers/") (defvar jao-wallpaper-random-candidates '("wallpaper.jpg" "wallpaper2.jpg")) (defvar jao-wallpaper-random-candidates-light '("wallpaper.jpg" "wallpaper2.jpg")) (defvar jao-wallpaper-random-wake t "Set to t for getting a new wallpaper on awaking from sleep") (defun jao-set-wallpaper (&optional path) (interactive) (let ((current (format "~/.wallpaper.%s" (if (jao-colors-scheme-dark-p) "dark" "light")))) (when-let ((f (or path (read-file-name "Image: " jao-wallpaper-dir (file-symlink-p current) t)))) (make-symbolic-link (expand-file-name f) current t) (if jao-sway-enabled-p (jao-sway-set-wallpaper (expand-file-name f)) (shell-command (format "xwallpaper --zoom %s" f)))))) (defun jao-set-random-wallpaper () (interactive) (when jao-wallpaper-random-wake (let* ((ws (if (jao-colors-scheme-dark-p) jao-wallpaper-random-candidates jao-wallpaper-random-candidates-light)) (f (seq-random-elt ws))) (jao-set-wallpaper (expand-file-name f jao-wallpaper-dir)) (message "%s" f)))) (add-to-list 'jao-sleep-awake-functions #'jao-set-random-wallpaper) #+end_src *** Screensaver and lock #+begin_src emacs-lisp (defun jao-screensaver-enabled () (string= (jao-exec-string "xdg-screensaver status") "enabled")) (defun jao-screensaver-toggle () (interactive) (let ((wid (jao-exec-string "xdotool getwindowfocus"))) (if (jao-screensaver-enabled) (jao-exec-string "xdg-screensaver suspend %s" wid) (jao-exec-string "xdg-screensaver resume %s" wid)) (jao-notify (format "Using '%s'" (jao-exec-string "xdotool getwindowname %s" wid)) (format "Screensaver %s" (jao-exec-string "xdg-screensaver status"))))) (jao-def-exec jao-xlock-screen "xdg-screensaver" "activate") (jao-def-exec jao-suspend "sudo" "/usr/sbin/pm-suspend") (defun jao-lock-screen () (interactive) (if jao-sway-enabled-p (shell-command "swaylock -i ~/.lockimage") (jao-xlock-screen))) (pretty-hydra-define jao-hydra-sleep (:color blue) ("Sleep" (("l" jao-lock-screen "lock screen") ("z" jao-suspend "sleep") ("u" jao-screensaver-toggle "enable/disable screensaver") ("q" nil "cancel")))) #+end_src *** X clipboard #+BEGIN_SRC emacs-lisp (setq x-select-enable-clipboard t x-select-enable-primary nil x-selection-timeout 100) #+END_SRC * Mode line *** Time display #+BEGIN_SRC emacs-lisp (setq display-time-world-list '(("Europe/Paris" "Barcelona") ("America/Los_Angeles" "Los Angeles") ("America/New_York" "New York") ("Europe/London" "London") ("Asia/Calcutta" "Bangalore") ("Asia/Tokyo" "Tokyo"))) (defun jao-time--pdt-hour () (jao-time-at-zone "%H" "America/Los_Angeles")) (defun jao-time--chicago-hour () (jao-time-at-zone "%H" "America/Chicago")) (defun jao-time-at-zone (format zone) (set-time-zone-rule zone) (prog1 (format-time-string format) (set-time-zone-rule nil))) (defun jao-time-echo-la-time () (interactive) (message (jao-time-at-zone "LA %H:%M" "America/Los_Angeles"))) (defun jao-time-echo-times () (interactive) (let ((msg (format "%s (%s)" (format-time-string "%a, %e %B - %H:%M") (jao-time-at-zone "%H:%M" "America/Los_Angeles")))) (jao-notify msg "" (jao-data-file "clock-world-icon.png")))) (defun jao-time-to-epoch (&optional s) (interactive) (let ((s (or s (read-string "Time string: " (thing-at-point 'string))))) (message "%s = %s" s (round (* 1000 (time-to-seconds (parse-time-string s))))))) (defun jao-epoch-to-time (&optional v) (interactive) (let ((v (or v (read-number "Milliseconds: " (thing-at-point 'number))))) (message "%s = %s" v (format-time-string "%Y-%m-%d %H:%M:%S" (seconds-to-time (/ v 1000.0)))))) #+END_SRC *** Mode line format #+begin_src emacs-lisp (setq line-number-display-limit-width 250) (setq mode-line-position-column-format '(",%c") mode-line-position-line-format '(" %l,%c")) (line-number-mode 1) (column-number-mode 1) #+end_src *** Mode line time #+begin_src emacs-lisp (setq display-time-string-forms '(24-hours ":" minutes)) (display-time-mode -1) #+end_src *** Mode line toggle #+begin_src emacs-lisp (defun jao-toggle--face-height (face &optional all) (let* ((h (face-attribute face :height (window-frame))) (nh (if (eq 'unspecified h) 1 'unspecified))) (set-face-attribute face (when (not all) (window-frame)) :height nh))) (defun jao-toggle-mode-line (&optional all) (interactive "P") (jao-toggle--face-height 'mode-line all)) (defun jao-toggle-inactive-mode-line (&optional all) (interactive "P") (jao-toggle--face-height 'mode-line-inactive all)) (defun jao-echo-mode-line () (interactive) (message "%s" (format-mode-line mode-line-format))) (defun jao--hide-inactive-mode-line (frame) (set-face-attribute 'mode-line-inactive frame :height 1)) (add-to-list 'after-make-frame-functions #'jao--hide-inactive-mode-line) (global-set-key (kbd "") #'jao-toggle-inactive-mode-line) (global-set-key (kbd "") #'jao-toggle-mode-line) (global-set-key (kbd "") #'jao-echo-mode-line) #+end_src *** Diminish #+BEGIN_SRC emacs-lisp (use-package diminish :ensure t) (when (require 'use-package-diminish nil 'noerror) (eval-after-load "simple" '(diminish 'auto-fill-function " §")) (eval-after-load "eldoc" '(diminish 'eldoc-mode "")) (eval-after-load "autorevert" '(diminish 'auto-revert-mode ""))) #+END_SRC * Notifications *** alert #+BEGIN_SRC emacs-lisp (use-package alert :ensure t :init (setq alert-default-style 'message ;; 'libnotify alert-hide-all-notifications nil)) #+END_SRC *** jao-notify #+begin_src emacs-lisp (require 'jao-notify) (setq jao-notify-use-messages-p t) ;; "/usr/share/icons/Papirus/64x64/mimetypes/audio-x-generic.svg" ;; "/usr/share/icons/Tango/scalable/mimetypes/audio-x-generic.svg" (defvar jao-notify-audio-icon (jao-data-file "music-player-icon.png")) #+end_src *** tracking ***** Package #+begin_src emacs-lisp (use-package tracking :ensure t :demand t :init (setq tracking-position 'before-modes tracking-frame-behavior nil tracking-most-recent-first nil tracking-max-mode-line-entries 10 tracking-sort-faces-first t tracking-shorten-modes '()) :config (setq erc-track-enable-keybindings nil) (defun jao-tracking-next-buffer () (interactive) (tracking-next-buffer) (jao-minibuffer-refresh)) :bind (("C-c C-SPC" . jao-tracking-next-buffer))) (defun jao-shorten-modes (&rest modes) (dolist (m modes) (add-to-list 'tracking-shorten-modes m))) (defun jao-tracking-face (face) (add-to-list 'tracking-faces-priorities face)) #+end_src ***** Shorten #+begin_src emacs-lisp (require 'shorten) (defun jao-tracking--clean-slack (s) (let ((s (replace-regexp-in-string "^\\*Slack - .*? : \\(mpdm-\\)?\\([^ ]+\\)\\( \\(T\\)\\)?.*" "#\\2\\4" s))) (replace-regexp-in-string "^[^a-zA-Z#]+" "#" s))) (defun jao-tracking-shorten-aggressively (lst tail-count) (let* ((s (shorten-join-sans-tail lst tail-count))) (if (string-match-p "^#" s) (substring s 1 nil) s))) (defun jao-tracking-split-clean (s) (shorten-split (jao-tracking--clean-slack s))) (defun jao-tracking-shorten (old-func &rest args) (let ((shorten-join-function #'jao-tracking-shorten-aggressively) (shorten-split-function #'jao-tracking-split-clean)) (apply old-func args))) (advice-add #'tracking-shorten :around #'jao-tracking-shorten) #+end_src ***** Minibuffer / proplog #+begin_src emacs-lisp (defvar jao-tracking-string "") (setq jao-tracking-bkg (if (jao-colors-scheme-dark-p) "grey20" "grey93")) (defface jao-tracking-minibuffer `((t :background ,jao-tracking-bkg)) "") (defface jao-tracking-minibuffer-sep `((t :foreground ,jao-tracking-bkg :background ,jao-tracking-bkg)) "") (defun jao-tracking-set-log (v) (when (member window-system '(x)) (x-change-window-property "_EMACS_LOG" v nil nil nil nil 0))) (jao-tracking-set-log "") (defun jao-tracking--buffer-str (s) (if (listp s) `(:propertize ,(plist-get s :propertize) face (jao-tracking-minibuffer ,@(when-let ((f (plist-get s 'face))) (jao-tracking-set-log " * ") (list f)))) `(:propertize "|" face jao-tracking-minibuffer-sep))) (defun jao-tracking-build-str (new-val) (jao-tracking-set-log "") (if (listp new-val) (mapcar #'jao-tracking--buffer-str new-val) new-val)) (defun jao-tracking-echo (sym new-val op where) (setq jao-tracking-string (jao-tracking-build-str new-val)) (jao-minibuffer-refresh)) (jao-minibuffer-add-variable 'jao-tracking-string -10) (add-variable-watcher 'tracking-mode-line-buffers #'jao-tracking-echo) ;; since we're using the minibuffer, forget the mode line (advice-add #'tracking-mode :override (lambda (&optional _) (interactive))) #+end_src ***** Additional highlighting #+begin_src emacs-lisp (defvar jao-tracking-highlight-rx "$^") (defun jao-tracking-add-buffer (old-func &rest args) (let* ((buffer (car args)) (faces (if (and buffer (string-match-p jao-tracking-highlight-rx (buffer-name buffer))) (cons 'lui-highlight-face (cadr args)) (cadr args)))) (funcall old-func buffer faces))) (advice-add #'tracking-add-buffer :around #'jao-tracking-add-buffer) (jao-tracking-face 'lui-highlight-face) #+end_src *** notification server #+begin_src emacs-lisp (use-package ednc :ensure t :diminish) (use-package jao-ednc :after ednc :commands (jao-ednc-setup) :config (defhydra jao-hydra-ednc (:color blue) "Notifications" ("s" jao-ednc-show "show last") ("d" jao-ednc-dismiss "dismiss last") ("D" jao-ednc-dismiss-all "dismiss all") ("i" jao-ednc-invoke-last-action "invoke last action") ("n" jao-ednc-pop "show all")) (jao-ednc-ignore-app "Spotify") :bind (("s-n" . jao-hydra-ednc/body) ("H-s-n" . jao-hydra-ednc/body))) #+end_src * Calendar, diary, weather *** Diary #+BEGIN_SRC emacs-lisp (setq diary-file (expand-file-name "diary" jao-org-dir) diary-display-function 'diary-fancy-display diary-mail-addr "jao@localhost" diary-comment-start ";;" diary-comment-end "") (add-hook 'diary-list-entries-hook 'diary-sort-entries t) #+END_SRC *** Calendar #+BEGIN_SRC emacs-lisp (appt-activate 1) (setq calendar-latitude 55.9533 calendar-longitude -3.1883 calendar-location-name "Edinburgh, Scotland" calendar-mark-diary-entries-flag t calendar-date-echo-text '(format "ISO date: %s" (calendar-iso-date-string (list month day year)))) (setq calendar-holidays '((holiday-fixed 1 1 "New Year's Day") (holiday-fixed 4 1 "April Fools' Day") (holiday-float 5 0 2 "Mother's Day") (holiday-fixed 3 19 "Father's Day") (holiday-float 11 4 4 "Thanksgiving") (holiday-fixed 12 25 "Christmas") (holiday-chinese-new-year) (solar-equinoxes-solstices) (holiday-sexp calendar-daylight-savings-starts (format "Daylight Saving Time Begins %s" (solar-time-string (/ calendar-daylight-savings-starts-time (float 60)) calendar-standard-time-zone-name))) (holiday-sexp calendar-daylight-savings-ends (format "Daylight Saving Time Ends %s" (solar-time-string (/ calendar-daylight-savings-ends-time (float 60)) calendar-daylight-time-zone-name))))) #+END_SRC *** Weather ***** winttr #+begin_src emacs-lisp (defun jao-weather (&optional wide) (interactive "P") (if (not wide) (message "%s" (jao-exec-string "curl -s 'https://wttr.in/?format=%s'" "%l++%m++%C+%c+%t+%w++%p")) (jao-afio--goto-scratch) (if-let ((b (get-buffer "*wttr*"))) (progn (pop-to-buffer b) (vterm-send-string "clear;curl wttr.in\n")) (jao-exec-in-vterm "curl wttr.in" "*wttr*")))) (global-set-key (kbd "") #'jao-weather) #+end_src *** Timers #+BEGIN_SRC emacs-lisp (put 'list-timers 'disabled nil) #+END_SRC * Files, dired and scratch buffer *** so-long #+begin_src emacs-lisp (setq large-file-warning-threshold (* 200 1024 1024)) (use-package so-long :ensure t :diminish) (global-so-long-mode 1) #+end_src *** Persistent scratch #+BEGIN_SRC emacs-lisp (use-package persistent-scratch :ensure t :config (persistent-scratch-setup-default)) #+END_SRC *** Automatically uncompress #+BEGIN_SRC emacs-lisp (require 'jka-compr) (auto-compression-mode 1) #+END_SRC *** wgrep #+begin_src emacs-lisp (use-package wgrep :ensure t) (require 'wgrep) #+end_src *** dired - [[https://www.masteringemacs.org/article/working-multiple-files-dired][Working with multiple files in dired - Mastering Emacs]] #+begin_src emacs-lisp (require 'dired) (require 'dired-x nil t) (put 'dired-find-alternate-file 'disabled nil) (setq dired-recursive-deletes 'top) (setq dired-recursive-copies 'top) (setq dired-listing-switches "-alhF --group-directories-first") (setq dired-free-space-args "-Ph") (setq ls-lisp-dirs-first t) (setq dired-dwim-target t) (setq wdired-create-parent-directories t) (use-package find-dired :init (setq find-ls-option '("-print0 | xargs -0 ls -ld" . "-ld"))) (add-hook 'dired-mode-hook #'turn-on-gnus-dired-mode) (define-key dired-mode-map [(control meta ?m)] #'gnus-dired-attach) (define-key dired-mode-map (kbd "C-c C-r") #'wdired-change-to-wdired-mode) #+END_SRC ***** Dired packages #+BEGIN_SRC emacs-lisp (use-package dired-git-info :ensure t :bind (:map dired-mode-map (")" . dired-git-info-mode))) #+END_SRC * General editing *** Completion #+begin_src emacs-lisp (jao-load-org "completion") #+end_src *** Long lines [[https://200ok.ch/posts/2020-09-29_comprehensive_guide_on_handling_long_lines_in_emacs.html][Comprehensive guide on handling long lines in Emacs - 200ok]] #+begin_src emacs-lisp (when (version<= "27.1" emacs-version) (setq bidi-inhibit-bpa t)) #+end_src *** Spaces, tabs, kill #+begin_src emacs-lisp (setq kill-whole-line t) (setq-default indent-tabs-mode nil) (setq indent-tabs-width 4) (setq-default default-tab-width 8) (setq tab-always-indent t) (setq kill-read-only-ok t) (setq view-read-only nil) #+end_src *** Whitespace #+BEGIN_SRC emacs-lisp (add-hook 'write-file-functions 'delete-trailing-whitespace) (setq-default indicate-empty-lines nil) #+END_SRC *** Filling Some variables to control where fci mode will be or is being used #+BEGIN_SRC emacs-lisp (setq fill-column 78) (setq comment-auto-fill-only-comments nil) (add-hook 'prog-mode-hook #'display-fill-column-indicator-mode) (setq-default display-fill-column-indicator-column 80) #+END_SRC *** Visible mode #+begin_src emacs-lisp (use-package visible-mode :bind (("s-v" . visible-mode))) #+end_src *** Changes #+BEGIN_SRC emacs-lisp (use-package goto-chg :ensure t :bind (("C-." . goto-last-change) ("C-," . goto-last-change-reverse))) #+END_SRC *** Eval-and-replace #+BEGIN_SRC emacs-lisp (defun fc-eval-and-replace () "Replace the preceding sexp with its value." (interactive) (backward-kill-sexp) (condition-case nil (prin1 (eval (read (current-kill 0))) (current-buffer)) (error (message "Invalid expression") (insert (current-kill 0))))) (global-set-key "\C-ce" 'fc-eval-and-replace) #+END_SRC * Buffers *** cursor and mark #+begin_src emacs-lisp (transient-mark-mode -1) (setq cursor-in-non-selected-windows nil cursor-type '(box . 24)) ; become hollow on images of size > 24 (blink-cursor-mode -1) #+end_src *** uniquifiy #+begin_src emacs-lisp (require 'uniquify) (setq uniquify-buffer-name-style 'forward uniquify-trailing-separator-p t) #+end_src *** autosave #+BEGIN_SRC emacs-lisp (setq auto-save-list-file-prefix "~/.emacs.d/auto-save-list/.saves-" auto-save-no-message t) #+END_SRC *** autoinsert #+BEGIN_SRC emacs-lisp (use-package autoinsert :config (setq auto-insert-directory "~/.emacs.d/autoinsert/" auto-insert t auto-insert-quert t) (setf (alist-get 'html-mode auto-insert-alist nil t) nil)) (add-hook 'find-file-hooks #'auto-insert) #+END_SRC *** autorevert #+BEGIN_SRC emacs-lisp (setq auto-revert-check-vc-info nil) (setq auto-revert-verbose nil) (setq auto-revert-avoid-polling t) (setq auto-revert-mode-text "") (require 'autorevert) (global-auto-revert-mode 1) #+END_SRC *** attached buffers #+begin_src emacs-lisp (defun jao-display-buffer-below-selected (buffer alist) (delete-other-windows-vertically) (display-buffer-below-selected buffer alist)) (defun jao-attached-buffer-entry (name-rx height) `(,name-rx (display-buffer-reuse-window jao-display-buffer-below-selected) (window-height . ,(or height 25)))) (defmacro jao-with-attached-buffer (name-rx height &rest body) `(let ((display-buffer-alist '(,(jao-attached-buffer-entry name-rx height)))) ,@body)) (defun jao-define-attached-buffer (name-rx &optional height) (add-to-list 'display-buffer-alist (jao-attached-buffer-entry name-rx height))) #+end_src *** images #+begin_src emacs-lisp (setq image-use-external-converter t) (setq widget-image-enable nil) #+end_src *** same mode #+begin_src emacs-lisp (defun jao-buffer-same-mode (&optional mode pre-fn) (interactive) (let* ((mode (or mode major-mode)) (pred `(lambda (b) (let ((b (get-buffer (if (consp b) (car b) b)))) (and ;; (not (eq b ,(current-buffer))) (eq ',mode (buffer-local-value 'major-mode b)))))) (buff (read-buffer "Buffer: " nil t pred))) (when pre-fn (funcall pre-fn)) (pop-to-buffer buff))) (global-set-key (kbd "C-c C-b") #'jao-buffer-same-mode) #+end_src *** buffer quit function (the triple ESC) #+begin_src emacs-lisp (setq buffer-quit-function (lambda () t)) #+end_src * Windows *** Scrolling #+begin_src emacs-lisp (setq scroll-preserve-screen-position 'always scroll-conservatively most-positive-fixnum scroll-margin 0 scroll-step 2 redisplay-skip-fontification-on-input t) (setq line-move-visual t) (use-package iscroll :ensure t :diminish) (with-eval-after-load "gnus-art" (add-hook 'gnus-article-mode-hook #'iscroll-mode)) (with-eval-after-load "eww" (add-hook 'eww-mode-hook #'iscroll-mode)) #+end_src *** Splitting and switch #+begin_src emacs-lisp (setq split-height-threshold 80 split-width-threshold 144) (setq switch-to-buffer-preserve-window-point nil switch-to-buffer-obey-display-actions t switch-to-prev-buffer-skip 'this) ;; don't switch to a ;; buffer visible in ;; same frame (global-set-key (kbd "C-x _") #'delete-other-windows-vertically) #+end_src *** Transpose #+begin_src emacs-lisp (defun jao-transpose-windows (arg) "Transpose the buffers shown in two windows." (interactive "p") (let ((selector (if (>= arg 0) 'next-window 'previous-window))) (while (/= arg 0) (let ((this-win (window-buffer)) (next-win (window-buffer (funcall selector)))) (set-window-buffer (selected-window) next-win) (set-window-buffer (funcall selector) this-win) (select-window (funcall selector))) (setq arg (if (plusp arg) (1- arg) (1+ arg)))))) (define-key ctl-x-4-map (kbd "t") #'jao-transpose-windows) (global-set-key (kbd "M-O") #'jao-transpose-windows) #+end_src *** First window #+begin_src emacs-lisp (defvar jao-first-window--from nil) (defun jao-first-window () (interactive) (let ((cb (current-buffer))) (if (eq (get-buffer-window cb) (select-window (frame-first-window))) (when jao-first-window--from (pop-to-buffer jao-first-window--from)) (setq jao-first-window--from cb)))) (global-set-key (kbd "s-a") #'jao-first-window) (global-set-key (kbd "H-s-a") #'jao-first-window) (global-set-key (kbd "M-o") #'other-window) #+end_src *** winner mode #+begin_src emacs-lisp (winner-mode 1) #+end_src * Frames *** Frame geometry #+begin_src emacs-lisp (defvar jao-frames-default-font "Hack-9") (setq frame-resize-pixelwise nil) ;;; modeline, toolbars and co. (modify-all-frames-parameters `((horizontal-scroll-bars . nil) (vertical-scroll-bars . nil) (scroll-bar-width . 11) (menu-bar . nil) (alpha . (,jao-frames-default-alpha ,jao-frames-default-alpha)) (font . ,jao-frames-default-font))) #+end_src *** Frame layout, title, etc. #+BEGIN_SRC emacs-lisp (setq frame-title-format '("%b")) (use-package fringe) (fringe-mode) (menu-bar-mode (jao-d-l 1 -1)) ;; (setting it to nil avoids mouse wrapping after other-frame) (setq focus-follows-mouse t) (use-package scroll-bar) (set-scroll-bar-mode nil) (use-package tool-bar) (tool-bar-mode -1) (defun jao-trisect (&optional force) (interactive) (let ((fw (frame-width))) (delete-other-windows) (cond ((or force (>= fw 240)) (let ((w (- (/ fw 3)))) (delete-other-windows) (split-window-horizontally w) (split-window-horizontally w) (balance-windows))) ((> fw 162) (split-window-horizontally) (switch-to-buffer (other-buffer)))))) (defun jao-bisect () (interactive) (jao-trisect t) (next-window) (delete-window)) #+END_SRC *** afio #+begin_src emacs-lisp (use-package jao-afio) (defun jao-xmonad-goto-1 () (shell-command "sendCommand 1")) (defun jao-afio--goto-scratch-1 () (interactive) (jao-afio-goto-scratch t)) (jao-afio-setup 'jao-afio--goto-scratch-1 t) (defun jao-current--frame-id () (propertize (if (and jao-exwm-enabled-p (not (bound-and-true-p jao-exwm--use-afio))) (format "F%s" exwm-workspace-current-index) (format "%s" (jao-afio-current-no))) 'face 'font-lock-warning-face)) (add-hook 'jao-afio-switch-hook #'tracking-remove-visible-buffers) (add-hook 'jao-afio-switch-hook #'jao-minibuffer-refresh t) (jao-minibuffer-add-variable '(jao-current--frame-id) 100) #+end_src * Writing and writing modes *** Org mode #+begin_src emacs-lisp (jao-load-org "org") #+end_src *** Blog #+begin_src emacs-lisp (jao-load-org "blog") #+end_src *** Text-ish mode settings #+begin_src emacs-lisp ;;; SENTENCES separated by just one space (setq sentence-end "[.?!][]\"')]*\\($\\|\t\\| \\)[ \t\n]*") (setq sentence-end-double-space t) ;;; copy rectangle (defun kill-rectangle-save (start end) "Save the region-rectangle as the last killed one." (interactive "r") (require 'rect) ; Make sure killed-rectangle is defvar'ed. (setq killed-rectangle (extract-rectangle start end)) (message "Rectangle saved")) ;;; indent on yank (defvar jao-auto-indent-modes '(emacs-lisp-mode ;; clojure-mode scheme-mode objc-mode tuareg-mode c-mode c++-mode tcl-mode sql-mode perl-mode cperl-mode java-mode jde-mode LaTeX-mode TeX-mode)) ;; (defadvice yank (after indent-region activate) ;; (if (member major-mode jao-auto-indent-modes) ;; (indent-region (region-beginning) (region-end) nil))) ;; text mode, autoinserts and write hooks ;;; misc (setq default-major-mode 'text-mode) (add-hook 'text-mode-hook 'turn-on-auto-fill) (add-hook 'write-file-functions 'copyright-update) #+end_src *** Dictionaries #+BEGIN_SRC emacs-lisp (defun jao-word-definition-lookup () "Look up the word under cursor in a browser." (interactive) (require 'thingatpt) (browse-url (concat "http://www.wordnik.com/words/" ;; "http://www.answers.com/main/ntquery?s=" (thing-at-point 'word)))) (use-package dictionary :init (setq dictionary-use-single-buffer t dictionary-server "localhost") :commands (dictionary-search dictionary-match-words dictionary-lookup-definition dictionary dictionary-mouse-popup-matching-words dictionary-popup-matching-words dictionary-tooltip-mode global-dictionary-tooltip-mode) :bind (("C-c d" . dictionary-search) ("C-c D" . jao-word-definition-lookup))) (setq ispell-personal-dictionary (expand-file-name "~/.emacs.d/ispell.dict")) #+END_SRC *** Markdown #+BEGIN_SRC emacs-lisp (use-package markdown-mode :ensure t) (use-package markdown-toc :ensure t) (dolist (ext '("\\.md$" "\\.markdown$")) (add-to-list 'auto-mode-alist (cons ext 'markdown-mode))) #+END_SRC *** TeX and LaTex #+BEGIN_SRC emacs-lisp (use-package tex-site :ensure auctex :init (progn (setq TeX-auto-save t) (setq TeX-parse-self t) (setq TeX-a4-paper t) (setq TeX-auto-local ".tex-auto-local") ;; Preferred view format: dvi, ps, pdf, pdfs (setq TeX-view-format "pdf") (setq-default TeX-master "../main") ; nil to ask (setq TeX-view-program-selection (jao-d-l '((output-dvi "open") (output-pdf "open") (output-html "open")) '(((output-dvi has-no-display-manager) "dvi2tty") ((output-dvi style-pstricks) "dvips and gv") (output-dvi "xdvi") (output-pdf "xdg-open") (output-html "xdg-open")))) ;; to make RefTeX faster for large documents, try these: (setq reftex-enable-partial-scans t) (setq reftex-save-parse-info t) (setq reftex-use-multiple-selection-buffers t) ;; to integrate with AUCTeX (setq reftex-plug-into-AUCTeX t) (setq reftex-ref-style-default-list '("Hyperref" "Varioref" "Fancyref")) (add-hook 'LaTeX-mode-hook 'turn-on-reftex) (setq LaTeX-command "latex -shell-escape") (setq LaTeX-biblatex-use-Biber t) (setq bibtex-dialect 'biblatex) (jao-when-darwin (jao-exec-path "/usr/local/texlive/2016/bin/x86_64-darwin")))) ;; (use-package ebib ;; :ensure t ;; :config (setq ebib-bibtex-dialect 'biblatex)) ;; for M-x biblio-lookup ;; (use-package biblio :ensure t) #+END_SRC * Browsing *** Variables #+begin_src emacs-lisp (defvar jao-browse-doc-use-emacs-p t) (defvar jao-browse-url-function nil) (defvar jao-browse-url-external-function nil) #+end_src *** URL around point #+begin_src emacs-lisp (defun jao-url-around-point (&optional current-url) (or (and (fboundp 'w3m-anchor) (w3m-anchor)) (shr-url-at-point nil) (ffap-url-at-point) (thing-at-point 'url) (when current-url (or (and (fboundp 'w3m-anchor) (w3m-anchor)) (and (derived-mode-p 'eww-mode) (plist-get eww-data :url)))))) (defun jao--url-prompt () (let* ((def (jao-url-around-point t)) (prompt (concat "URL" (if def (format " (%s): " def) ": ")))) (read-string prompt nil nil def))) #+end_src *** Downloads using wget #+BEGIN_SRC emacs-lisp (defun jao-wget--get-title (filename) (let ((fn (file-name-base filename))) (if (string-blank-p fn) (plist-get eww-data :title) (subst-char-in-string ?- ? (capitalize fn))))) (defun jao-wget (url &optional user pwd) "Download URL using wget." (let* ((def (file-name-nondirectory url)) (pmt (format "Save %s to: " url)) (read-file-name-function nil) (dest (expand-file-name (read-file-name pmt jao-sink-dir nil nil def))) (title (jao-wget--get-title dest)) (src-url (jao-url-around-point t)) (auth (when (and user pwd) `(,(format "--http-user=%s" user) ,(format "--http-password=%s" pwd))))) (switch-to-buffer-other-window (get-buffer-create "*downloads*")) (erase-buffer) (kill-new (format "[[doc:%s][%s]] (from [[%s][here]])" (file-name-nondirectory dest) (read-string "Title: " title) (or src-url (file-name-directory url)))) (apply 'make-term `("downloads" "wget" nil ,@auth "-O" ,dest ,url)))) (defun jao-download (url &optional pws) "Download URL using wget" (interactive (list (jao--url-prompt))) (when url (let ((usr (and pws (read-string "Login name: "))) (pwd (and pws (read-passwd "Password: ")))) (jao-wget url usr pwd)))) (with-eval-after-load "embark" (define-key embark-url-map (kbd "d") #'jao-download)) #+END_SRC *** Video #+BEGIN_SRC emacs-lisp (defvar jao-video--url-rx (format "^https?://\\(?:www\\.\\)?%s/.+" (regexp-opt '("youtu.be" "youtube.com" "blip.tv" "vimeo.com" "infoq.com") t))) (defun jao-video--url-p (url) (string-match-p jao-video--url-rx url)) (defun jao--remote-run (url prg) (let ((args (format "%s %s" prg (shell-quote-argument url)))) (start-process-shell-command prg nil args))) (defun jao--mpv (url &rest args) (jao--remote-run url "mpv")) (defun jao--vlc (url &rest args) (jao--remote-run url "vlc")) (defvar jao--video-player 'jao--mpv) (defun jao-view-video (url) "Tries to stream a video from the current or given URL" (interactive (list (jao--url-prompt))) (when url (funcall jao--video-player url))) (defun jao-maybe-view-video (url &rest _ignored) (interactive) (if (y-or-n-p "View video (y) or web page (n)? ") (jao-view-video url) (funcall jao-browse-url-function url))) #+END_SRC *** Browse URL #+BEGIN_SRC emacs-lisp (require 'browse-url) (setq browse-url-generic-program "~/bin/firehog") (defun jao-browse-with-external-browser (&rest url) "Browse with external hogging" (interactive "s") (let ((url (or (car url) (jao-url-around-point)))) (if (not url) (message "No URL at point") (when (and jao-exwm-enabled-p (fboundp 'jao-exwm-firefox)) (jao-exwm-firefox)) (when (and jao-sway-enabled-p (fboundp 'jao-sway-firefox)) (jao-sway-firefox)) (browse-url-generic url)))) (setq jao-browse-url-external-function 'jao-browse-with-external-browser) (defun jao--fln (url) (shell-quote-argument (if (string-match "^[^:]*:/*?\\(/?[^/].*\\)" url) (match-string-no-properties 1 url) url))) (defun jao--browse-doc (url search &optional no-add) (let* ((url (substring-no-properties url)) (file (jao--fln url))) (when file (unless (file-exists-p file) (error "File %s does not exist" file)) (jao-open-doc file)))) (defun jao--make-file-rx (exts) (format "file:/?/?.+\\.%s$" (regexp-opt exts))) (defvar jao--see-exts (jao--make-file-rx '("jpg" "jpeg" "png" "mov" "wmv" "avi" "mp4"))) (defvar jao--doc-exts (jao--make-file-rx '("ps" "ps.gz" "pdf" "dvi" "djvu" "chm"))) (defvar jao-browse-url-wget-exts '("ps" "pdf" "dvi" "djvu" "zip" "gz" "tgz" "mp4" "mp3" "flv")) (defun jao-wget--regexp () (concat "^http[s]?://.+\\(\\." (mapconcat 'identity jao-browse-url-wget-exts "\\|\\.") "\\)\\'")) (defun jao--see (url &rest _r) (start-process-shell-command "see" nil (format "see %s" (jao--fln url)))) (defun jao--find-file-other-window (url &rest _) (find-file-other-window (jao--fln url))) (use-package elpher :ensure t) (defun jao-elpher--browse (url &rest _) (elpher-go url)) (setq browse-url-handlers `(("^\\(gemini\\|gopher\\)://.*" . jao-elpher--browse) (,jao--doc-exts . jao--browse-doc) (,jao--see-exts . jao--see) ("^file://?.+\\.html?$" . ,jao-browse-url-function) ("^file://?" . jao--find-file-other-window) ("^https?://.*\\.slack\\..*" . ,jao-browse-url-external-function) ("^https?://.*\\.gotomeeting\\.com\\.*" . browse-url-chrome) ("^https?://meet\\.google\\.com\\.*" . ,jao-browse-url-external-function) (,(jao-wget--regexp) . jao-download) (jao-video--url-p . jao-maybe-view-video) ("." . ,jao-browse-url-function))) (setq browse-url-browser-function 'browse-url-default-browser) #+END_SRC *** Subscribe rss using r2e #+begin_src emacs-lisp (autoload 'View-quit "view") (defun jao-rss--find-url () (when (derived-mode-p 'w3m-mode 'eww-mode) (save-excursion (if (fboundp 'w3m-view-source) (w3m-view-source) (eww-view-source)) (goto-char (point-min)) (when (re-search-forward "type=\"application/\\(?:atom\\|rss\\)\\+xml\" +" nil t) (let ((url (save-excursion (when (re-search-forward "href=\"\\([^\n\"]+\\)\"" nil t) (match-string-no-properties 1)))) (title (when (re-search-forward "\\(?:title=\"\\([^\n\"]+\\)\" +\\)" nil t) (match-string-no-properties 1)))) (if (fboundp 'w3m-view-mode) (w3m-view-source) (View-quit)) (when url (cons url (or title "")))))))) (defun jao-list-mailboxes (base) (let ((dir (expand-file-name base "~/var/mail"))) (seq-difference (directory-files dir) '("." ".." "sent" "inbox" "trash")))) (defun jao-rss-subscribe () (interactive) (let* ((url (or (jao-url-around-point) (jao-rss--find-url) (read-string "Feed URL: "))) (url+title (if (consp url) url (cons url (read-string "Feed name: ")))) (url (car url+title)) (title (cdr url+title))) (if url (let ((url (if (string-match "^feed:" url) (substring url 5) url))) (when (y-or-n-p (format "Subscribe to <%s>? " url)) (let* ((name (read-string "Name: " title)) (cat (completing-read "Category: " (jao-list-mailboxes "feeds") nil t))) (shell-command (format "r2e add %s %s jao+feeds_%s@localhost && r2e run %s" name url cat name))))) (message "No feeds found")))) #+end_src *** Web browsers #+begin_src emacs-lisp ;; (jao-load-org "eww") (jao-load-org "w3m") #+end_src * Email #+begin_src emacs-lisp (setq jao-afio-mail-function 'gnus) ;; 'notmuch 'gnus 'mu4e (jao-load-org "email") #+end_src * PDFs *** doc-view #+begin_src emacs-lisp (use-package doc-view :init (setq doc-view-cache-directory "~/.emacs.d/cache/docview" doc-view-resolution 110 doc-view-continuous t doc-view-conversion-refresh-interval 1) :config ;; this is an ugly hack: when jao-minibuffer is active, ;; somehow docview scrolling is not triggering a refresh, ;; specially for scroll down movements, so we advice the ;; scrolling functions to force a redisplay by going to ;; another window. (defun jao--refresh (&rest _rest) (let ((jao-minibuffer-enabled-p nil)) (other-window 1) (other-window -1))) (dolist (f '(doc-view-scroll-up-or-next-page doc-view-scroll-down-or-previous-page doc-view-previous-line-or-previous-page doc-view-next-line-or-next-page image-eol image-bol)) (advice-add f :after #'jao--refresh)) :bind (:map doc-view-mode-map ("j" . doc-view-next-line-or-next-page) ("J" . doc-view-scroll-up-or-next-page) ("k" . doc-view-previous-line-or-previous-page) ("K" . doc-view-scroll-down-or-previous-page))) (use-package jao-doc-view :bind (:map doc-view-mode-map ("b" . jao-doc-view-back) ("B" . jao-doc-view-forward) ("S" . jao-doc-view-save-session) ("u" . jao-doc-view-visit-url))) (use-package saveplace-pdf-view :ensure t :demand t :after doc-view) #+end_src *** open pdfs #+begin_src emacs-lisp (setq jao-open-doc-fun 'jao-find-or-open) (defun jao-find-or-open (file) (let* ((buffs (buffer-list)) (b (catch 'done (while buffs (when (string-equal (buffer-file-name (car buffs)) file) (throw 'done (car buffs))) (setq buffs (cdr buffs)))))) (jao-afio--goto-docs) (if b (pop-to-buffer b) (find-file file)))) (defun jao-open-doc (&optional file) (interactive) (when-let (file (or file (read-file-name "Document: " (concat jao-org-dir "/doc/")))) (funcall jao-open-doc-fun file))) (defun jao-afio-open-pdf (file page &optional height) (jao-open-doc file) (when page (jao-doc-view-goto-page page height))) (setq jao-org-open-pdf-fun #'jao-afio-open-pdf) #+end_src *** Hydra #+begin_src emacs-lisp (major-mode-hydra-define doc-view-mode nil ("Notes" (("o" jao-org-pdf-goto-org "notes file") ("O" (jao-org-pdf-goto-org 4) "notes file, linking")) "Navigation" (("b" jao-doc-view-back "back jump") ("B" jao-doc-view-back "forward jump") ("u" jao-doc-view-visit-url "visit URL")) "Slices" (("cb" doc-view-set-slice-from-bounding-box "bounding box") ("cm" doc-view-set-slice-using-mouse "using mouse")) "Session" (("s" jao-open-pdf-session "load session") ("S" jao-doc-view-save-session "save session") ("d" doc-view-dired-cache "visit cache directory")))) #+end_src * Shells *** shell modes #+begin_src emacs-lisp (setq sh-basic-offset 2) ;; translates ANSI colors into text-properties, for eshell (autoload 'ansi-color-for-comint-mode-on "ansi-color" nil t) (add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on) #+end_src *** vterm #+begin_src emacs-lisp (use-package vterm :ensure t :init (setq vterm-kill-buffer-on-exit t vterm-copy-exclude-prompt t vterm-use-vterm-prompt-detection-method t vterm-buffer-name-string nil) :config (define-key vterm-mode-map [(f1)] nil) :bind (:map vterm-mode-map (("C-c C-c" . vterm-send-C-c)))) (defun jao-exec-in-vterm (cmd &optional name) (vterm) (when name (vterm-send-string "unset PROMPT_COMMAND\n")) (vterm-send-string cmd) (vterm-send-return) (when name (rename-buffer name))) (defvar-local jao-vterm--cmd nil) (defun jao-vterm--find (cmd) (seq-find (lambda (b) (and (eq (buffer-local-value 'major-mode b) 'vterm-mode) (string= (or (buffer-local-value 'jao-vterm--cmd b) "") cmd))) (buffer-list))) (defmacro jao-def-exec-in-vterm (name cmd &rest prelude) `(defun ,(intern (format "jao-vterm-%s" name)) () (interactive) ,@prelude (if-let ((b (jao-vterm--find ,cmd))) (pop-to-buffer b) (jao-exec-in-vterm (format "%s; exit" ,cmd) ,(when name (format "%s" name))) (setq-local jao-vterm--cmd ,cmd)))) (jao-def-exec-in-vterm aptitude "aptitude" (jao-afio--goto-scratch)) (jao-def-exec-in-vterm htop "htop" (jao-afio--goto-scratch)) #+end_src *** Eshell ***** Basic custom #+begin_src emacs-lisp (use-package eshell :init (setq eshell-directory-name "~/.emacs.d/eshell") (setq eshell-aliases-file (jao-data-file "eshell.alias")) (setq eshell-hist-ignoredups 'erase) :config (add-hook 'eshell-mode-hook (lambda () (setq outline-regexp eshell-prompt-regexp)))) #+end_src ***** Colors #+begin_src emacs-lisp (autoload 'ansi-color-apply "ansi-color") ;; (add-hook 'eshell-preoutput-filter-functions 'ansi-color-filter-apply) (add-hook 'eshell-preoutput-filter-functions 'ansi-color-apply) (use-package eshell-syntax-highlighting :after esh-mode :ensure t :config ;; Enable in all Eshell buffers. (eshell-syntax-highlighting-global-mode +1)) #+end_src ***** Visual commands #+BEGIN_SRC emacs-lisp (require 'em-term) ;;; commands using ansi scape seqs (dolist (c '("editor" "more" "wget" "dict" "vim" "links" "w3m" "ssh" "autossh" "zmore" "pager" "aptitude" "su" "htop" "top" "screen" "whizzml" "iex")) (add-to-list 'eshell-visual-commands c)) (setq eshell-visual-subcommands '(("git" "log" "diff" "show") ("sudo" "vim")) eshell-destroy-buffer-when-process-dies nil eshell-escape-control-x t) #+END_SRC ***** bol #+begin_src emacs-lisp (defun jao-eshell-maybe-bol () (interactive) (let ((p (point))) (eshell-bol) (if (= p (point)) (beginning-of-line)))) #+end_src ***** Prompt #+BEGIN_SRC emacs-lisp ;; tracking git repos (defun jao-eshell--git-dirty () (shell-command-to-string "git diff-index --quiet HEAD -- || echo -n '*'")) (use-package git-ps1-mode :ensure t :init (setq git-ps1-mode-showupstream "1" git-ps1-mode-showdirtystate "1")) (defun jao-eshell--git-info () (if (fboundp 'git-ps1-mode-get-current) (git-ps1-mode-get-current) (let ((desc (shell-command-to-string "git branch --no-color"))) (when (string-match "^* \\(\\<.+\\>\\)" desc) (format "%s%s" (match-string 1 desc) (jao-eshell--git-dirty)))))) (defun jao-eshell--git-current-branch (suffix) (let ((desc (or (jao-eshell--git-info) ""))) (cond ((and (string-empty-p desc) suffix) (format " (%s)" suffix)) ((string-empty-p (or suffix "")) (format " (%s)" desc)) (t (format " (%s %s)" desc suffix))))) (defun jao-eshell--virtualenv () (let ((venv (getenv "VIRTUAL_ENV"))) (when (and venv (string-match ".*/\\([^/]+\\)/$" venv)) (match-string-no-properties 1 venv)))) (defun jao-eshell-prompt-function () (let* ((venv (jao-eshell--virtualenv)) (venv (if venv (format "%s" venv) ""))) (concat (abbreviate-file-name (eshell/pwd)) (jao-eshell--git-current-branch venv) (if (= (user-uid) 0) " # " " $ ")))) (setq eshell-prompt-function 'jao-eshell-prompt-function) #+END_SRC ***** in-term #+begin_src emacs-lisp (defun eshell/in-term (prog &rest args) (switch-to-buffer (apply #'make-term (format "in-term %s %s" prog args) prog nil args)) (term-mode) (term-char-mode)) #+end_src ***** Dir navigation #+BEGIN_SRC emacs-lisp (use-package eshell-up :ensure t :config (setq eshell-up-print-parent-dir t)) (use-package eshell-autojump :ensure t) #+END_SRC ***** Completion #+begin_src emacs-lisp (defun jao-eshell-completion-capf () (bash-completion-dynamic-complete-nocomint (save-excursion (eshell-bol) (point)) (point) t)) (defun jao-eshell--add-bash-completion () (setq completion-at-point-functions '(jao-eshell-completion-capf pcomplete-completions-at-point t))) (use-package bash-completion :ensure t :hook (eshell-mode . jao-eshell--add-bash-completion)) #+end_src ***** History #+BEGIN_SRC emacs-lisp (setq eshell-history-size 10000) ;;; Fix eshell history completion to allow !$ ;; This is done by advising eshell-history-reference to expand !$ ;; into !!:$ which works... (defadvice jao-eshell-history-reference (before ben-fix-eshell-history) "Fixes eshell history to allow !$ as abbreviation for !!:$" (when (string= (ad-get-arg 0) "!$") (ad-set-arg 0 "!!:$"))) (ad-activate 'jao-eshell-history-reference) #+END_SRC This is needed if we want ! to expand in emacs >= 27 #+BEGIN_SRC emacs-lisp (add-hook 'eshell-expand-input-functions #'eshell-expand-history-references) #+END_SRC ***** Workarounds #+begin_src emacs-lisp ;; at some point, bash completion started insertig the TAB ;; after the commands ends (defun jao-eshell--clean-prompt () (eshell-bol) (ignore-errors (kill-line))) (add-hook 'eshell-after-prompt-hook 'jao-eshell--clean-prompt) #+end_src ***** Keybindings #+begin_src emacs-lisp (defun jao-eshell--kbds () (define-key eshell-mode-map "\C-a" 'jao-eshell-maybe-bol) (define-key eshell-mode-map "\C-ci" 'consult-outline)) ;; Eshell mode is sillily re-creating its mode map ;; in every buffer in emacs < 28. (if (> emacs-major-version 27) (jao-eshell--kbds) (add-hook 'eshell-mode-hook #'jao-eshell--kbds)) #+end_src *** Shell here #+begin_src emacs-lisp (defun jao-shell-here--find-window (b) (when-let ((w (car (cl-remove-if-not `(lambda (w) (eq (window-buffer w) ,b)) (window-list))))) (select-window w))) (defvar jao-shell-here-use-vterm nil) (defun jao-shell-frame-buffer (&optional b vt) (let ((p (if (or vt jao-shell-here-use-vterm) 'jao-vterm-buffer 'jao-eshell-buffer))) (if b (set-frame-parameter nil p b) (frame-parameter nil p)))) (defun jao-shell-here (&optional stay) (interactive) (let* ((dir default-directory) (b (jao-shell-frame-buffer))) (if (buffer-live-p b) (pop-to-buffer b nil t) (if jao-shell-here-use-vterm (jao-with-attached-buffer "^vterm$" 35 (vterm)) (eshell (when (and (boundp 'jao-exwm--use-afio) (not jao-exwm--use-afio)) exwm-workspace-current-index))) (jao-shell-frame-buffer (current-buffer))) (when (not jao-shell-here-use-vterm) (eshell-save-some-history)) (when (not stay) (if jao-shell-here-use-vterm (progn (vterm-send-C-a) (vterm-send-C-k) (vterm-send-string (format "cd %s\n" dir))) (eshell-kill-input) (eshell/cd dir) (insert "\n") (eshell-send-input))))) (jao-define-attached-buffer "^\\*eshell\\*" 35) (defun eshell/x () (when (derived-mode-p 'eshell-mode) (when (fboundp 'eshell-autojump-save) (eshell-autojump-save)) (eshell-save-some-history)) (if (> (window-height) (1+ (/ (frame-height) 2))) (bury-buffer) (delete-window))) (with-eval-after-load "vterm" (add-to-list 'vterm-eval-cmds '("x" eshell/x))) (defun jao-shell-here-toggle () (interactive) (if (or (eq (current-buffer) (jao-shell-frame-buffer)) (eq (current-buffer) (jao-shell-frame-buffer nil t))) (eshell/x) (jao-shell-here t))) (defun jao-vterm-here-toggle () (interactive) (let ((jao-shell-here-use-vterm t)) (call-interactively 'jao-shell-here-toggle))) (global-set-key (kbd "C-!") #'jao-shell-here) (global-set-key [(f1)] #'jao-shell-here-toggle) #+end_src * Version control and CI *** General options #+BEGIN_SRC emacs-lisp (setq vc-follow-symlinks t) (setq auto-revert-check-vc-info nil) #+END_SRC *** Diff fringe indicators (diff-hl) #+BEGIN_SRC emacs-lisp (use-package diff-hl :ensure t :config (setq diff-hl-draw-borders nil diff-hl-side 'right) (map-keymap (lambda (_k cmd) (put cmd 'repeat-map 'diff-hl-command-map)) diff-hl-command-map) (add-hook 'magit-post-refresh-hook 'diff-hl-magit-post-refresh)) (global-diff-hl-mode) #+END_SRC *** Git config files: more informative diffs See [[https://protesilaos.com/codelog/2021-01-26-git-diff-hunk-elisp-org/][Informative diff hunks for Emacs Lisp and Org | Protesilaos Stavrou]] #+begin_src config :tangle ~/.config/git/attributtes :comments no *.clj diff=lisp *.cljc diff=lisp *.cljs diff=lisp *.lisp diff=lisp *.el diff=lisp *.org diff=org #+end_src #+begin_src gitconfig :tangle ~/.config/git/config [diff "lisp"] xfuncname = "^(((;;;+ )|\\(|([ \t]+\\(((cl-|el-patch-)?def(un|var|macro|method|custom)|gb/))).*)$" [diff "org"] xfuncname = "^(\\*+ +.*)$" #+end_src *** Magit and forge #+begin_src emacs-lisp (use-package magit :ensure t :commands magit-status :init (setq magit-status-initial-section nil magit-completing-read-function 'magit-builtin-completing-read magit-display-buffer-function 'magit-display-buffer-fullcolumn-most-v1 magit-delete-by-moving-to-trash nil magit-last-seen-setup-instructions "1.4.0" magit-log-edit-confirm-cancellation t magit-omit-untracked-dir-contents t magit-process-connection-type nil magit-push-always-verify nil magit-repository-directories '(("/home/jao/usr/bigml" . 2) ("/home/jao/usr/jao" . 2) ("/home/jao/lib" . 2)) magit-save-repository-buffers 'dontask magit-status-buffer-switch-function 'switch-to-buffer magit-status-show-hashes-in-headers t) :bind (("" . magit-status) :map magit-status-mode-map ("C-c C-r" . github-review-forge-pr-at-point))) (use-package forge :ensure t :after magit :init (setq forge-database-file (format "~/.emacs.d/forge-database-%s.sqlite" emacs-major-version) forge-topic-list-limit (cons 25 10)) ;; workaround for ghub problems (shoudn't be needed in 27.x) (when (< emacs-major-version 27) (setq gnutls-algorithm-priority "NORMAL:-VERS-TLS1.3") (setq ghub-use-workaround-for-emacs-bug nil)) :bind (:map forge-topic-mode-map ("M-w" . copy-region-as-kill)) :config (remove-hook 'magit-status-sections-hook #'forge-insert-issues) ;; (add-hook 'magit-status-sections-hook #'forge-insert-notifications t) (add-hook 'magit-status-sections-hook #'forge-insert-requested-reviews t) (add-hook 'magit-status-sections-hook #'forge-insert-assigned-issues t) (add-hook 'magit-status-sections-hook #'forge-insert-issues t)) #+end_src *** Other git packages #+begin_src emacs-lisp (use-package git-messenger :ensure t :bind (("C-x v p" . git-messenger:popup-message))) (use-package gist :ensure t) (use-package git-timemachine :ensure t) ;; git config --local git-link.remote / git-link.branch (use-package git-link :ensure t) (use-package gitconfig-mode :ensure t) (use-package github-review :ensure t :config (defun jao-gnus-github-review () (interactive) (gnus-summary-select-article-buffer) (goto-char (point-min)) (when (re-search-forward "https://github\.com/.*/pull/.*" nil t) (let ((url (match-string-no-properties 0))) (when (yes-or-no-p (format "Start review for %s" url)) (github-review-start url))))) (eval-after-load "gnus-art" '(progn (define-key gnus-summary-mode-map "\C-cG" 'jao-gnus-github-review) (define-key gnus-article-mode-map "\C-cG" 'jao-gnus-github-review))) :mode-hydra (github-review-mode nil ("Review" (("a" github-review-approve "Approve") ("r" github-review-reject "Reject") ("c" github-review-reject "Comment")) "Quit" (("Q" bury-buffer "Bury buffer") ("k" kill-buffer "Kill buffer"))))) #+end_src *** Jenkins [[https://github.com/rmuslimov/jenkins.el][GitHub - rmuslimov/jenkins.el: Jenkins plugin for emacs]] #+BEGIN_SRC emacs-lisp (use-package jenkins :ensure t :init ;; one also needs jenkins-api-token, jenkins-username and jenkins-url ;; optionally: jenkins-colwidth-id, jenkins-colwidth-last-status (setq jenkins-colwidth-name 35) :config (defun jao-jenkins-first-job () (interactive) (goto-char (point-min)) (when (re-search-forward "^- Job" nil t) (goto-char (match-beginning 0)))) (add-hook 'jenkins-job-view-mode-hook #'jao-jenkins-first-job) :bind (:map jenkins-job-view-mode-map (("n" . next-line) ("p" . previous-line) ("f" . jao-jenkins-first-job) ("RET" . jenkins--show-console-output-from-job-screen)) :map jenkins-console-output-mode-map (("n" . next-line) ("p" . previous-line) ("g" . jenkins--refresh-console-output)))) #+END_SRC * Programming *** Automatic modes #+BEGIN_SRC emacs-lisp (add-to-list 'auto-mode-alist '("\\.mix\\'" . hexl-mode)) (add-to-list 'auto-mode-alist '("\\.m4\\'" . m4-mode)) (add-to-list 'auto-mode-alist '("\\.am\\'" . makefile-mode)) (add-to-list 'auto-mode-alist '("\\.pl\\'\\|\\.pm\\'" . cperl-mode)) #+END_SRC *** Vterm repls #+begin_src emacs-lisp (use-package jao-vterm-repl) (jao-define-attached-buffer "^\\* vrepl - .+ \\*.*") #+end_src *** Smart scan #+begin_src emacs-lisp (use-package smartscan :ensure t :commands smartscan-mode :init (add-hook 'prog-mode-hook #'smartscan-mode) :diminish) #+end_src *** Paredit and parens #+begin_src emacs-lisp (require 'paren) (show-paren-mode t) (use-package paredit :ensure t :commands paredit-mode :hook ((pie-mode . paredit-mode) (scheme-mode . paredit-mode) (clojure-mode . paredit-mode) (emacs-lisp-mode . paredit-mode) (eval-expression-minibuffer-setup . paredit-mode) (lisp-interaction-mode . disable-paredit-mode)) :diminish ((paredit-mode . " þ"))) #+end_src *** Diff/Ediff #+BEGIN_SRC emacs-lisp (setq ediff-split-window-function 'split-window-horizontally) (setq ediff-make-buffers-readonly-at-startup nil) (setq ediff-window-setup-function 'ediff-setup-windows-plain) (setq ediff-keep-variants nil) #+END_SRC *** Compilation ***** Compilation mode options #+begin_src emacs-lisp (require 'compile) (setq compilation-scroll-output t) (setq compilation-error-regexp-alist (remove 'omake compilation-error-regexp-alist)) ;; (add-hook 'compilation-mode-hook #'visual-line-mode) #+end_src ***** Mode line (no "Compiling"!) #+BEGIN_SRC emacs-lisp (require 'compile) (diminish 'compilation-minor-mode " ‡") (when (< emacs-major-version 27) (setcdr (assq 'compilation-in-progress minor-mode-alist) '(" ‡"))) (when (> emacs-major-version 26) (setcdr (assq 'compilation-in-progress mode-line-modes) '("‡ "))) #+END_SRC ***** Colorizing compilation buffer #+BEGIN_SRC emacs-lisp (require 'ansi-color) (defun endless/colorize-compilation () "Colorize from `compilation-filter-start' to `point'." (let ((inhibit-read-only t)) (ansi-color-apply-on-region compilation-filter-start (point)))) (add-hook 'compilation-filter-hook #'endless/colorize-compilation) #+END_SRC ***** Compilation commands #+begin_src emacs-lisp (use-package jao-compilation :commands jao-compilation-setup :bind (("C-c C" . compile) ("C-c c" . jao-compile))) (jao-compilation-setup) #+end_src ***** Next error #+begin_src emacs-lisp (setq next-error-find-buffer-function #'next-error-buffer-on-selected-frame next-error-verbose t) #+end_src *** Flymake #+begin_src emacs-lisp (use-package flymake :ensure t :custom ((flymake-mode-line-format '(" " flymake-mode-line-counters))) :hook ((haskell-mode . flymake-mode)) :config (jao-define-attached-buffer "^\\*Flymake diagnostics .*\\*\\'") :bind (:map flymake-mode-map (("s-f n" . flymake-goto-next-error) ("s-f p" . flymake-goto-prev-error) ("s-f i" . flymake-show-diagnostic) ("s-f f" . flymake-show-diagnostics-buffer) ("s-f l" . consult-flymake)))) #+end_src *** Eglot #+begin_src emacs-lisp (use-package eglot :ensure t :hook ((erlang-mode . eglot) (elixir-mode . eglot))) (jao-define-attached-buffer "\\*eldoc\\( .*\\)?\\*" 0.33) #+end_src * Programming languages *** Elisp Some helper packages #+BEGIN_SRC emacs-lisp (use-package edit-list :ensure t) (use-package package-lint :ensure t) #+END_SRC Functions to operate on elisp sexps a la slime or geiser: #+BEGIN_SRC emacs-lisp (add-hook 'emacs-lisp-mode-hook 'eldoc-mode) ;; (add-hook 'emacs-lisp-mode-hook ;; (lambda () ;; (when (eq major-mode 'emacs-lisp-mode) ;; (paredit-mode 1)))) (defun elisp-disassemble (function) (interactive (list (function-called-at-point))) (disassemble function)) (defun elisp-pp (sexp) (with-output-to-temp-buffer "*Pp Eval Output*" (pp sexp) (with-current-buffer standard-output (emacs-lisp-mode)))) (defun elisp-macroexpand (form) (interactive (list (form-at-point 'sexp))) (elisp-pp (macroexpand form))) (defun elisp-macroexpand-all (form) (interactive (list (form-at-point 'sexp))) (elisp-pp (cl-macroexpand-all form))) (defun elisp-push-point-marker () (require 'etags) (cond ((featurep 'xemacs) (push-tag-mark)) (t (ring-insert find-tag-marker-ring (point-marker))))) (defun elisp-pop-found-function () (interactive) (cond ((featurep 'xemacs) (pop-tag-mark nil)) (t (pop-tag-mark)))) (defun elisp-find-definition (name) "Jump to the definition of the function (or variable) at point." (interactive (list (thing-at-point 'symbol))) (cond (name (let ((symbol (intern-soft name)) (search (lambda (fun sym) (let* ((r (save-excursion (funcall fun sym))) (buffer (car r)) (point (cdr r))) (cond ((not point) (error "Found no definition for %s in %s" name buffer)) (t (switch-to-buffer buffer) (goto-char point) (recenter 1))))))) (cond ((fboundp symbol) (elisp-push-point-marker) (funcall search 'find-function-noselect symbol)) ((boundp symbol) (elisp-push-point-marker) (funcall search 'find-variable-noselect symbol)) (t (message "Symbol not bound: %S" symbol))))) (t (message "No symbol at point")))) (defun elisp-bytecompile-and-load () (interactive) (or buffer-file-name (error "The buffer must be saved in a file first")) (require 'bytecomp) ;; Recompile if file or buffer has changed since last compilation. (when (and (buffer-modified-p) (y-or-n-p (format "save buffer %s first? " (buffer-name)))) (save-buffer)) (let ((filename (expand-file-name buffer-file-name))) (with-temp-buffer (byte-compile-file filename t)))) #+END_SRC Bindinging the functions above to "natural" keys in elisp buffers: #+BEGIN_SRC emacs-lisp (defvar elisp-extra-keys '( ;; ((kbd "C-c d") 'elisp-disassemble) ((kbd "C-c C-m") 'elisp-macroexpand) ((kbd "C-c C-M") 'elisp-macroexpand-all) ((kbd "C-c C-c") 'compile-defun) ((kbd "C-c C-k") 'elisp-bytecompile-and-load) ((kbd "C-c C-l") 'load-file) ((kbd "C-c C-p") 'pp-eval-last-sexp) ((kbd "M-.") 'elisp-find-definition) ((kbd "M-,") 'elisp-pop-found-function) ((kbd "C-c <") 'list-callers))) (dolist (binding elisp-extra-keys) (let ((key (eval (car binding))) (val (eval (cadr binding)))) (define-key emacs-lisp-mode-map key val) (define-key lisp-interaction-mode-map key val))) #+END_SRC *** Erlang #+begin_src emacs-lisp (use-package erlang :ensure t :custom ((inferior-erlang-machine-options '("shell")) (inferior-erlang-machine "rebar3") (inferior-erlang-shell-type nil) (erlang-indent-level 4)) :bind (:map erlang-mode-map (("C-c C-z" . jao-vterm-repl-pop-to-repl))) :init (require 'jao-vterm-repl) (add-to-list 'auto-mode-alist '("^rebar\\.config\\`" . erlang-mode)) (jao-vterm-repl-register "rebar.config" "rebar3 shell" "^[0-9]+> ") :config (defun jao-erlang-current-module () (when (save-excursion (goto-char (point-min)) (re-search-forward "^-module(\\([^)]+\\))" nil t)) (match-string-no-properties 1))) (defun jao-erlang-compile (arg) (interactive "P") (save-some-buffers) (when-let ((mname (jao-erlang-current-module))) (with-current-buffer (jao-vterm-repl) (vterm-send-string (format "c(%s).\n" mname)) (sit-for 0) (setq compilation-last-buffer (current-buffer)) (when arg (jao-vterm-repl-pop-to-repl))))) (setq erlang-shell-function #'jao-vterm-repl erlang-shell-display-function #'jao-vterm-repl-pop-to-repl erlang-compile-function #'jao-erlang-compile)) #+end_src *** Idris #+begin_src emacs-lisp (use-package idris-mode :ensure t :custom ((idris-interpreter-path "idris2") (idris-pretty-printer-width 80) (idris-repl-history-file "~/.emacs.d/cache/idris-history.eld") (idris-stay-in-current-window-on-compiler-error t))) (jao-define-attached-buffer "^\\*idris.*" 0.4) #+end_src *** Elixir ***** packages #+begin_src emacs-lisp (use-package elixir-mode :ensure t :custom (lsp-clients-elixir-server-executable (expand-file-name "~/usr/share/elixir-ls/language_server.sh")) :bind (:map elixir-mode-map (("C-c C-z" . jao-vterm-repl-pop-to-repl)))) (use-package mix :ensure t :hook (elixir-mode . mix-minor-mode) :init (jao-vterm-repl-register "mix.exs" "iex -S mix" "^iex([0-9]+)> ") :diminish ((mix-minor-mode . ""))) (use-package exunit :ensure t) #+end_src ***** hydra #+begin_src emacs-lisp (major-mode-hydra-define elixir-mode nil ("Doc" (("dd" lsp-describe-thing-at-point "Describe thing at point")) "Xref" (("xd" xref-find-definitions "Definitions") ("xo" xref-find-definitions-other-window "-> other win") ("xr" xref-find-references "References")) "LSP" (("lg" lsp-goto-implementation "Implementation") ("lf" lsp-format-buffer "Format buffer") ("ls" lsp-describe-session "Describe session")) "LSP modes" (("Tl" lsp-lens-mode "Lens mode" :toggle t) ("Td" lsp-modeline-diagnostics-mode "Modeline diagnostics" :toggle t) ("Tb" lsp-headerline-breadcrumb-mode "Header breadcrumb" :toggle t) ("Ti" lsp-toggle-trace-io "Trace I/O" :toggle lsp-print-io)) "Mix" (("me" mix-execute-task "Execute mix task") ("mt" mix-test "Run tests") ("mc" mix-compile "Compile") ("mm" jao-elixir-pop-to-iex "Pop to iex")) "Mix subproject" (("Me" (lambda () (interactive) (mix-execute-task nil t)) "Execute task") ("Mt" (lambda () (interactive) (mix-compile nil t)) "Compile") ("Mt" (lambda () (interactive) (mix-test nil t)) "Run tests")) "Tests" (("tt" exunit-verify-single "Run single test") ("tr" exunit-rerun "Re-run tests") ("ta" exunit-verify "Run test suites") ("tA" exunit-verify-all "Run all test suites")))) #+end_src *** Clojure #+BEGIN_SRC emacs-lisp (use-package clojure-mode :ensure t :config (add-hook 'clojure-mode-hook (lambda () (setq mode-name "λ")))) (use-package cider :ensure t :commands cider-mode ;; :pin melpa-stable :init (setq cider-annotate-completion-candidates t cider-auto-select-error-buffer nil clojure-docstring-fill-column 72 cider-show-error-buffer 'except-in-repl cider-lein-parameters "repl :headless :host localhost" cider-mode-line " ÷" cider-prompt-for-symbol nil cider-repl-pop-to-buffer-on-connect nil cider-repl-history-file (expand-file-name "~/.emacs.d/cache/cider.history") cider-repl-use-pretty-printing t cider-test-show-report-on-success nil cider-auto-select-test-report-buffer nil cider-use-overlays nil cider-use-fringe-indicators nil cider-eldoc-display-for-symbol-at-point t eldoc-echo-area-use-multiline-p nil nrepl-prompt-to-kill-server-buffer-on-quit nil) :hook ((cider-mode . cider-company-enable-fuzzy-completion) (cider-mode . cider-eldoc-setup) (cider-mode . eldoc-mode))) (eval-after-load "cider-test" '(progn (advice-add 'cider-scale-background-color :override (lambda () (frame-parameter nil 'background-color))) (setq cider-test-items-background-color (frame-parameter nil 'background-color)))) (use-package cider-macroexpansion :after cider :diminish ((cider-macroexpansion-mode . " µ"))) #+END_SRC *** Geiser #+begin_src emacs-lisp (defun jao-org--set-geiser-impl () (setq-local geiser-repl--impl 'guile)) (add-hook 'org-mode-hook #'jao-org--set-geiser-impl) (jao-load-path "geiser/geiser/elisp") (use-package geiser :init (setq geiser-repl-history-filename "~/.emacs.d/cache/geiser-history") (setq geiser-repl-startup-time 20000) (setq geiser-debug-auto-display-images-p t)) (jao-load-path "geiser/mit") (use-package geiser-mit) ;; (jao-load-path "geiser/chicken") ;; (use-package geiser-chicken) ;; (jao-load-path "geiser/chibi") ;; (use-package geiser-chibi) (jao-load-path "geiser/guile") (use-package geiser-guile) (jao-load-path "geiser/chez") (use-package geiser-chez :init (setq geiser-chez-binary "scheme")) (jao-load-path "geiser/gambit") (use-package geiser-gambit) #+end_src *** Pie #+begin_src emacs-lisp (jao-load-path "pie") (use-package pie :demand t :commands (pie-mode)) #+end_src *** Lisp #+begin_src emacs-lisp (use-package sly :ensure t :init (setq inferior-lisp-program "sbcl") :config (sly-setup)) (use-package sly-quicklisp :after (sly) :ensure t) #+end_src *** Haskell ***** packages #+begin_src emacs-lisp (use-package haskell-mode :ensure t :custom ((inferior-haskell-find-project-root t) (haskell-check-remember-last-command-p nil) (haskell-font-lock-symbols nil) (haskell-interactive-popup-errors nil) (haskell-process-auto-import-loaded-modules t) (haskell-process-log t) (haskell-process-suggest-remove-import-lines t) (haskell-process-suggest-hoogle-imports t) (haskell-process-type 'cabal-repl) (haskell-process-use-presentation-mode t) (haskell-stylish-on-save nil)) :config (defun jao-haskell-hoogle (query) (interactive (hoogle-prompt)) (haskell-hoogle query t)) (require 'haskell-doc) (dolist (h '(interactive-haskell-mode haskell-doc-mode haskell-decl-scan-mode haskell-indentation-mode haskell-auto-insert-module-template)) (add-hook 'haskell-mode-hook h)) :bind (:map haskell-mode-map (("C-c C-d" . jao-haskell-hoogle) ("C-c h" . haskell-hoogle-lookup-from-local) ("C-c C-c" . haskell-compile)))) (require 'haskell) (diminish 'interactive-haskell-mode " λ") (diminish haskell-doc-mode) (diminish haskell-decl-scan-mode) (jao-define-attached-buffer "\\*hoogle\\*.*") ;; needs cabal install apply-refact (use-package hlint-refactor :ensure t :after (haskell-mode) :diminish "" :hook (haskell-mode . hlint-refactor-mode)) #+end_src ***** hydra #+begin_src emacs-lisp (major-mode-hydra-define haskell-mode nil ("Imports" (("in" haskell-navigate-imports "Navigate imports") ("if" haskell-mode-format-imports "Format imports") ("is" haskell-sort-imports "Sort imports") ("ia" haskell-align-imports "Align imports")) "Code" (("c" haskell-compile "Compile") ("s" haskell-mode-stylish-buffer "stylish on buffer")) "Hoogle" (("h" jao-haskell-hoogle "Hoogle") ("H" haskell-hoogle-lookup-from-local "Hoogle from local server")))) #+end_src *** Prolog #+BEGIN_SRC emacs-lisp (use-package ediprolog :ensure t) (use-package prolog :ensure t :commands (run-prolog prolog-mode mercury-mode) :init (progn (setq prolog-system 'swi) (add-to-list 'auto-mode-alist '("\\.pl$" . prolog-mode)) (setq prolog-consult-string '((t "[%f]."))) (setq prolog-program-name '(((getenv "EPROLOG") (eval (getenv "EPROLOG"))) (eclipse "eclipse") (mercury nil) (sicstus "sicstus") (swi "swipl") (t "prolog"))))) #+END_SRC *** Python ***** Virtual envs (with eshell support) See also [[https://github.com/porterjamesj/virtualenvwrapper.el][the docs]]. #+begin_src emacs-lisp (use-package virtualenvwrapper :ensure t :config (venv-initialize-eshell) (jao-compilation-env "VIRTUAL_ENV")) #+end_src *** Coq #+begin_src emacs-lisp :load no (use-package proof-general :ensure t) (use-package company-coq :ensure t :hook (coq-mode . company-coq-mode)) #+end_src *** JSON #+BEGIN_SRC emacs-lisp (use-package json-mode :ensure t) ;; (use-package json-navigator :ensure nil) #+END_SRC * Graphics *** Images #+begin_src emacs-lisp (setq image-use-external-converter t) #+end_src *** Gnuplot #+BEGIN_SRC emacs-lisp (use-package gnuplot :ensure t :commands (gnuplot-mode gnuplot-make-buffer) :init (add-to-list 'auto-mode-alist '("\\.gp$" . gnuplot-mode))) #+END_SRC * Network *** network monitor #+begin_src emacs-lisp (jao-def-exec jao-nm-applet "nm-applet") (defun jao-toggle-nm-applet () (interactive) (if (string-empty-p (jao-exec-string "pidof nm-applet")) (jao-nm-applet) (jao-exec-string "killall nm-applet"))) #+end_src *** Bluetooth #+BEGIN_SRC emacs-lisp (use-package bluetooth :ensure t) #+END_SRC *** Enwc (network monitor) #+BEGIN_SRC emacs-lisp (use-package enwc :ensure t :init (setq enwc-default-backend 'nm enwc-backend 'nm enwc-display-mode-line nil enwc-wired-device "enp3s0f0" enwc-wireless-device "wlp1s0")) #+END_SRC *** Proton #+BEGIN_SRC emacs-lisp (require 'jao-proton-utils) (defalias 'proton-vpn 'proton-vpn-status) #+END_SRC *** ssh #+begin_src emacs-lisp (use-package tramp) (defun jao-tramp-hosts () (remove-duplicates (mapcan (lambda (x) (remove* nil (mapcar 'cadr (apply (car x) (cdr x))))) (tramp-get-completion-function "ssh")) :test #'string=)) (defun jao-ssh () (interactive) (let ((h (completing-read "Host: " (jao-tramp-hosts)))) (jao-exec-in-vterm (format "ssh %s" h) (format "* %s *" h)))) #+end_src * Chats *** Circe ***** General configuration #+begin_src emacs-lisp (defvar jao-irc-channels '()) (use-package circe :ensure t :bind (:map circe-channel-mode-map (("C-c C-a" . lui-track-jump-to-indicator))) :init (setq circe-default-realname "https://jao.io" circe-default-part-message "" circe-default-quit-message "" circe-ignore-list nil circe-server-coding-system '(undecided . undecided) circe-server-killed-confirmation 'ask-and-kill-all circe-server-auto-join-default-type :after-auth circe-format-say "({nick}) {body}" circe-format-self-say "(jao) {body}" circe-new-buffer-behavior 'ignore circe-new-buffer-behavior-ignore-auto-joins t circe-nickserv-ghost-style 'after-auth circe-prompt-string ": " circe-completion-suffix ", " circe-reduce-lurker-spam t circe-nick-next-function (lambda (old) (replace-regexp-in-string "-" "`" (circe-nick-next old))) circe-lagmon-mode-line-format-string "" ;; "%.0f " circe-lagmon-mode-line-unknown-lag-string "" ;; "? " circe-lagmon-timer-tick 120 circe-lagmon-reconnect-interval 180 lui-max-buffer-size 30000 lui-fill-column 80 lui-time-stamp-position 'right lui-time-stamp-format "%H:%M" lui-flyspell-p nil lui-track-indicator 'fringe lui-track-behavior 'before-tracking-next-buffer) :config (defvar jao-bitlbee-channels ()) (setq circe-network-options (let ((up (jao--get-user/password "freenode")) (bup (jao--get-user/password "bitlbee"))) `(("Freenode" :nick ,(car up) :channels ,jao-irc-channels :tls t :sasl-username ,(car up) :sasl-password ,(cadr up)) ("Bitlbee" :host "127.0.0.1" :nick ,(car bup) :channels ,jao-bitlbee-channels :lagmon-disabled t :nickserv-password ,(cadr bup) :user ,(car bup))))) (jao-shorten-modes 'circe-channel-mode 'circe-server-mode 'circe-query-mode) (circe-lagmon-mode) (enable-circe-color-nicks) (enable-circe-display-images) (enable-lui-track)) #+end_src ***** Commands (recover &co.) #+begin_src emacs-lisp (with-eval-after-load "circe" (defun circe-command-NICKNO (&rest ignore) (message "%s nicks" (length (circe-channel-nicks)))) (advice-add 'circe-command-NAMES :after #'circe-command-NICKNO) (defun circe-command-RECOVER (&rest ignore) "Recover nick" (let* ((fn (jao--get-user/password "freenode")) (u (car fn)) (p (cadr fn))) (circe-command-MSG "nickserv" (format "IDENTIFY %s %s" u p)) (circe-command-MSG "nickserv" (format "GHOST %s" u)) (circe-command-MSG "nickserv" (format "RELEASE %s" u)) (circe-command-NICK u)))) #+end_src ***** Follow twitter/mastodon threads #+begin_src emacs-lisp (defun jao-twitter-find-ref () (interactive) (when-let (no (save-excursion (move-end-of-line nil) (when (re-search-backward "\\[[0-9a-f]+->\\([0-9a-f]+\\)\\]" nil t) (match-string-no-properties 1)))) (push-mark (point)) (re-search-backward (format "\\[%s[]-]" no)))) (with-eval-after-load "circe" (define-key circe-channel-mode-map "\C-c\C-p" 'jao-twitter-find-ref)) #+end_src *** Slack [[https://github.com/jackellenberger/emojme#finding-a-slack-token][How to get a token]]: It's easyish! Open and sign into the slack customization page, e.g. https://my.slack.com/customize, right click anywhere > inspect element. Open the console and paste: =window.prompt("your api token is: ", TS.boot_data.api_token)= Lately things are iffy. We've needed to add the ~:override~ to slack-counts update, and it might be needed to replace ~slack-conversations-view~ by ~slack-conversations-history~ #+BEGIN_SRC emacs-lisp (use-package slack :ensure t :commands (slack-start) :init (setq slack-alert-icon (jao-data-file "slack.svg") slack-buffer-emojify nil slack-buffer-create-on-notify t slack-display-team-name t slack-typing-visibility 'never ;; 'buffer, 'frame slack-profile-image-file-directory "/tmp/slack-imgs/" slack-image-file-directory "/tmp/slack-imgs/" slack-file-dir "/tmp/slack-files/" slack-prefer-current-team t slack-message-tracking-faces '(warning) slack-log-level 'warn slack-message-custom-notifier (lambda (msg room team) room)) :bind (:map slack-mode-map (("@" . slack-message-embed-mention) ("#" . slack-message-embed-channel))) :config (dolist (f (list slack-file-dir slack-image-file-directory)) (when (not (file-exists-p f)) (make-directory f))) (jao-shorten-modes 'slack-message-buffer-mode 'slack-thread-message-buffer-mode) (jao-tracking-face 'warning)) #+END_SRC *** Telegram #+begin_src emacs-lisp (use-package telega :ensure t :custom (telega-use-tracking-for '(unmuted) ;; '(or unmuted mention) telega-rainbow-color-custom-for nil telega-msg-rainbow-title nil telega-sticker-set-download t) :config (define-key global-map (kbd "C-c C-t") telega-prefix-map) (setq telega-chat-show-avatars nil telega-root-show-avatars nil telega-chat-prompt-show-avatar-for nil telega-emoji-use-images nil telega-temp-dir "/tmp/telega" telega-symbol-checkmark "·" telega-symbol-heavy-checkmark "×" telega-symbol-verified "*" telega-mode-line-string-format '(:eval (telega-mode-line-unread-unmuted))) (with-eval-after-load "tracking" (jao-shorten-modes 'telega-chat-mode) (jao-tracking-face 'telega-tracking)) (telega-mode-line-mode 1)) #+end_src *** Signel #+begin_src emacs-lisp (jao-load-org "lib/net/signel.org") (with-eval-after-load "tracking" (jao-tracking-face 'signel-notification) (jao-shorten-modes 'signel-chat-mode)) (setq signel-report-deliveries t) #+end_src *** Startup #+begin_src emacs-lisp (defun jao-circe (&optional p) (interactive "P") ;; (when (or p (y-or-n-p "Connect to bitlbee using circe? ")) ;; (circe "Bitlbee")) (when (or p (y-or-n-p "Connect to freenode using circe? ")) (circe "Freenode"))) (defun jao-chats (&optional p) (interactive "P") (when (or p (y-or-n-p "Connect to slack? ")) (slack-start)) (when (or p (y-or-n-p "Connect to telegram? ")) (telega)) ;; (when (and (not (signel-signal-cli-process)) ;; (or p (y-or-n-p "Start signel? "))) ;; (signel-start)) (jao-circe p)) (pretty-hydra-define jao-hydra-chats (global-map "s-q" :color blue :quit-key "q") ("Connect" (("A" (jao-chats t) "all chats -y") ("a" jao-chats "all chats") ("S" slack-start "slack") ("C" (jao-circe t) "circe -y") ("s-q" jao-hydra-chats/body nil)) "Go" (("c" (jao-buffer-same-mode 'circe-channel-mode) "circe buffer") ("s" (jao-buffer-same-mode 'slack-message-buffer-mode) "slack buffer") ("t" (jao-buffer-same-mode 'telega-chat-mode) "telega buffer") ("T" telega "telega rooster")))) (global-set-key (kbd "H-s-q") #'jao-hydra-chats/body) #+end_src * Multimedia *** mixer #+begin_src emacs-lisp (defun jao-mixer-get-level (dev) (let* ((s (shell-command-to-string (format "amixer sget %s" dev))) (s (car (last (split-string s "\n" t))))) (when (string-match ".*Front .*\\[\\([0-9]+\\)%\\] .*" s) (let ((level (match-string 1 s))) (message "%s level: %s%%" dev level) (string-to-number level))))) (defun jao-mixer-set (dev v) (jao-exec-string "amixer sset %s %s" dev v) (jao-mixer-get-level dev)) (defun jao-mixer-master-toggle () (interactive) (jao-mixer-set "Master" "toggle")) (defun jao-mixer-master-up () (interactive) (jao-mixer-set "Master" "10%+")) (defun jao-mixer-master-down () (interactive) (jao-mixer-set "Master" "10%-")) (defun jao-mixer-capture-up () (interactive) (jao-mixer-set "Capture" "10%+")) (defun jao-mixer-capture-down () (interactive) (jao-mixer-set "Capture" "10%-")) (jao-def-exec jao-audio-applet "pasystray") (defun jao-toggle-audio-applet () (interactive) (if (string-empty-p (jao-exec-string "pidof pasystray")) (jao-audio-applet) (jao-exec-string "killall pasystray"))) (global-set-key (kbd "") #'jao-toggle-audio-applet) #+end_src *** emms ***** configuration #+BEGIN_SRC emacs-lisp (use-package emms :pin gnu :ensure t :init (setq emms-score-file "~/.emacs.d/score" emms-stream-bookmarks-file "~/.emacs.d/streams" emms-history-file "~/.emacs.d/cache/emms-history" emms-cache-file "~/.emacs.d/cache/emms-cache" emms-show-format "%s") (setq emms-source-file-default-directory "~/var/lib/music/" emms-player-list '(emms-player-mpd) emms-player-mpd-server-name "localhost" emms-player-mpd-server-port "6600" emms-player-mpd-music-directory emms-source-file-default-directory) (setq emms-volume-change-function 'emms-volume-mpd-change emms-volume-change-amount 10 emms-info-ogginfo-coding-system 'utf-8) ;; from http://www.shellarchive.co.uk/index.html#%20Prettify%20emms (setq emms-browser-info-genre-format "%i· %n" emms-browser-info-artist-format "%i· %n" emms-browser-info-album-format "%i◨ %n" emms-browser-info-title-format "%i♪ %n") (setq emms-last-played-format-alist '(((emms-last-played-seconds-today) . "Today at %H:%M") (604800 . "%a at %H:%M") ((emms-last-played-seconds-month) . "%d") ((emms-last-played-seconds-year) . "%m-%d") (t . ""))) :hook ((emms-player-started . emms-player-mpd-show)) :config (eval-after-load "emms-info" '(add-to-list 'emms-info-functions 'emms-info-mpd))) (emms-all) (emms-mode-line -1) (emms-playing-time 1) (emms-playing-time-disable-display) (use-package jao-emms-random-album :after emms :commands (jao-emms-random-album-next) :init (setq jao-emms-random-album-notify-icon jao-notify-audio-icon)) (use-package jao-emms-info-track :after emms :init (setq jao-emms-show-icon jao-notify-audio-icon) :config (jao-emms-info-setup 50)) (use-package jao-emms-lyrics :after emms :init (setq jao-lyrics-info-function 'jao-emms-lyrics-track-data)) (defvar jao-emms-random-album-notify--pause-icon "/usr/share/icons/Tango/scalable/actions/media-playback-pause.svg") (defun jao-emms--show-status (s status) (jao-notify (format "%s%s%s" (cadr s) (cdr (assoc (car s) status)) (caddr s)) "emms" (if (string= "pause" (cdr (assoc "state" status))) jao-emms-random-album-notify--pause-icon jao-notify-audio-icon))) (defun jao-emms--osd-status (s &optional pref suff) (emms-player-mpd-get-status (list s (or pref "") (or suff "")) 'jao-emms--show-status)) #+END_SRC ***** helper functions #+begin_src emacs-lisp (defun jao-emms-volume-delta (d) (funcall emms-volume-change-function d)) (defun jao-emms-show-volume () (jao-emms--osd-status "volume" "Volume " "%")) (defalias 'jao-emms-update-cache 'emms-player-mpd-update-all-reset-cache) (defun jao-emms-load-streams () (interactive) (emms-play-playlist (expand-file-name "~/var/lib/music/streams.list"))) (defun jao-emms-search () (interactive) (let ((by (completing-read "Search by: " '("artist" "composer" "performer" "title" "album" "names")))) (if (string= "names" by) (emms-browser-search-by-names) (emms-browser-search (list (intern (concat "info-" by))))))) (defun jao-emms-echo () (interactive) (emms-show) (jao-emms-update-echo-string) (emms-show)) #+end_src ***** Media global aliases #+begin_src emacs-lisp (defalias 'jao-player-connect 'emms-player-mpd-connect) (defalias 'jao-player-toggle 'emms-pause) (defalias 'jao-player-next 'emms-next) (defalias 'jao-player-previous 'emms-previous) (defalias 'jao-player-stop 'emms-stop) (defalias 'jao-player-start 'emms-start) (defalias 'jao-player-seek-forward 'emms-seek-forward) (defalias 'jao-player-seek-backward 'emms-seek-backward) (defalias 'jao-player-play 'emms-start) (defalias 'jao-player-search 'jao-emms-search) (defalias 'jao-player-vol-delta 'jao-emms-volume-delta) (defalias 'jao-player-volume 'jao-emms-show-volume) (defalias 'jao-player-osd 'jao-emms-show-osd) (defalias 'jao-player-echo 'jao-emms-echo) (defalias 'jao-player-list 'emms-playlist-mode-go) (defalias 'jao-player-browse 'emms-browser) (defalias 'jao-player-random-album 'jao-emms-random-album-next) #+end_src *** mpris #+begin_src emacs-lisp (use-package jao-mpris :config (jao-mpris-minibuffer-order 50) (dolist (name '("spotifyd" "spotify" "mopidy")) (jao-mpris-minibuffer-register name) (jao-mpris-minibuffer-register name :system))) #+end_src *** spotify Access to spotify uses packages tangled from [[./lib/media/espotify.org][espotify.org]], which offers functionality tailored to the completion engines at hand: #+begin_src emacs-lisp (jao-load-path "espotify") (use-package espotify :demand t) (use-package consult-spotify :demand t) (defalias 'jao-spotify-album #'consult-spotify-album) (defalias 'jao-spotify-track #'consult-spotify-track) (defalias 'jao-spotify-artist #'consult-spotify-artist) (defalias 'jao-spotify-playlist #'consult-spotify-playlist) #+end_src *** mpdel #+BEGIN_SRC emacs-lisp (jao-load-path "libmpdel") (jao-load-path "mpdel") (jao-load-path "navigel") (use-package navigel :init (setq navigel-display-messages nil)) (defun jao-mpdel-dup-dir-p (dir) (and (libmpdel-directory-p dir) (string-match-p "\\[.+\\]\\b" (or (libmpdel--directory-path dir) "")))) (defun jao-mpdel--filter (dirs) (cl-remove-if 'jao-mpdel-dup-dir-p dirs)) (use-package libmpdel :init (setq libmpdel-port 6669)) (use-package mpdel :diminish :init (setq mpdel-browser-list-clean-up-function 'identity mpdel-browser-top-level-entries '(directories empty-line stored-playlists current-playlist empty-line "Spotify/Top Lists/Top artists/Personal" "Spotify/Playlists/Featured" empty-line search-album search-artist search-title)) (defun jao-mpdel--show-osd (data song ml) (let* ((no (1+ (string-to-number (or (cdr (assq 'song data)) "0")))) (to (or (cdr (assq 'playlistlength data)) "0")) (album (or (libmpdel-album-name song) "")) (artist (or (libmpdel-artist-name song) "")) (tms (split-string (or (cdr (assq 'time data)) "0/0") ":")) (tm (format "%s/%s" (libmpdel-time-to-string (car tms)) (libmpdel-time-to-string (cadr tms)))) (title (format "%s %s/%s. %s" tm no to (or (libmpdel-entity-name song) "")))) (if ml (message "%s %s - %s (%s)" tm title artist album) (jao-notify (format "%s (%s)" artist album) title jao-notify-audio-icon)))) (defun jao-mpdel-show-osd (&optional ml) (interactive "P") (let ((song (libmpdel-current-song))) (when song (libmpdel-send-command "status" `(lambda (data) (jao-mpdel--show-osd data ,song ,ml)))))) (defun jao-mpdel-search (&optional type) (interactive (list (completing-read "Search by: " '("album" "artist" "title")))) (let* ((func (cond ((string= type "album") 'mpdel-core-search-by-album) ((string= type "artist") 'mpdel-core-search-by-artist) ((string= type "title") 'mpdel-core-search-by-title))) (thing (read-from-minibuffer (format "Search for %s: " type)))) (mpdel-core-open (libmpdel-search-criteria-create :type type :what thing))))) (use-package mpdel-browser) (defalias 'mpdel-pop-to-browser 'mpdel-browser-open) (mpdel-mode) (define-key mpdel-browser-mode-map (kbd "n") #'next-line) (define-key mpdel-browser-mode-map (kbd "p") #'previous-line) #+END_SRC *** hydras #+begin_src emacs-lisp (require 'jao-lyrics) (defun jao-show-some-lyrics (arg) (interactive "P") (if (string-blank-p (or jao-mpris-track-string "")) (jao-show-lyrics arg 'jao-emms-lyrics-track-data) (jao-show-lyrics arg 'jao-mpris-artist-title))) (defalias 'jao-player-show-lyrics 'jao-show-some-lyrics) (defun jao-player-volume-delta (raise) (jao-player-vol-delta (if raise 5 -5)) (sit-for 0.05) (jao-player-show-volume)) (defun jao-player-volume-raise () (interactive) (jao-player-volume-delta t)) (defun jao-player-volume-lower () (interactive) (jao-player-volume-delta nil)) (defun jao-player-show-volume () (interactive) (jao-notify "Volume" (format "%s%%" (jao-player-volume)))) (use-package jao-emms-random-album) (pretty-hydra-define jao-hydra-spotify (global-map "s-s" :color blue :quit-key "q") ("Search" (("a" jao-spotify-album "album") ("A" jao-spotify-artist "artist") ("t" jao-spotify-track "track") ("P" jao-spotify-playlist "playlist")) "Play" (("s" espotify-play-pause "toggle") ("n" espotify-next "next") ("p" espotify-previous "previous") ("w" jao-mpdel-show-osd "currently playing")) "Browse" (("b" mpdel-pop-to-browser "browser") ("l" mpdel-playlist-open "playing list") ;; ("m" jao-counsel-spotify-change-mpris "change mpris provider") ("c" (mpdel-core-replace-current-playlist) "clear list" :color red) ("s-s" jao-hydra-spotify/body nil)))) (pretty-hydra-define jao-hydra-media (global-map "s-m" :color blue :quit-key "q") ("Play" (("m" jao-player-toggle "toggle") ("n" jao-player-next "next") ("p" jao-player-previous "previous") ("f" jao-player-seek-forward "seek fwd" :color red) ("F" jao-player-seek-backward "seek bwd" :color red)) "Browse" (("b" jao-player-browse "browse") ("l" jao-player-list "show play list") ("L" jao-player-show-lyrics "show lyrics") ("w" jao-player-echo "now playing (text)") ("s" jao-player-search "search")) "Master volume" (("d" jao-mixer-master-down "master down" :color red) ("u" jao-mixer-master-up "master up" :color red) ("M" jao-mixer-master-toggle "master toggle") ("v" (jao-mixer-get-level "Master") "show")) "Capture volume" (("D" jao-mixer-capture-down "capture down" :color red) ("U" jao-mixer-capture-up "capture up" :color red) ("V" (jao-mixer-get-level "Capture") "show")) "Utilities" (("C" jao-emms-update-cache "refresh cache") ("c" jao-player-connect "reconnect to mpd") ("r" jao-emms-random-album-toggle "toggle random album" :toggle jao-emms-random-album-p) ("N" jao-player-random-album "random album") ("s-m" jao-hydra-media/body nil)))) #+end_src * Key bindings #+begin_src emacs-lisp (global-set-key "\C-cj" #'join-line) (global-set-key "\C-cq" #'auto-fill-mode) (global-set-key "\C-xr\M-w" #'kill-rectangle-save) (global-set-key "\C-c\C-z" #'comment-or-uncomment-region) (global-set-key "\C-z" #'comment-or-uncomment-region) (pretty-hydra-define jao-hydra-emacs-utils (:color blue :quit-key "q") ("Notes" (("n" jao-org-notes-open-or-create "capture note") ("N" jao-org-notes-open "go to note")) "Packages" (("a" jao-vterm-aptitude "aptitude") ("l" (progn (jao-afio--goto-scratch) (list-packages)) "package list") ) "Network" (("s" jao-ssh "ssh") ("v" proton-vpn "proton vpn") ("m" run-proton-bridge "proton bridge")) "" (("b" bluetooth-list-devices "bluetooth") ("f" (jao-sway-run-or-focus "firefox") "switch to firefox")) "Monitors" (("p" jao-vterm-htop "htop") ("t" jao-time-echo-times "current time") ) "Looks" (("T" jao-toggle-transparency "toggle transparency" :toggle (jao-transparent-p) :color red) ("w" jao-set-wallpaper "set wallpaper") ("W" jao-set-random-wallpaper "set radom wallpaper")) "Sleep" (("L" jao-lock-screen "lock screen") ("z" jao-suspend "sleep") ("u" jao-screensaver-toggle "toggle screensaver" :toggle (jao-screensaver-enabled))) "Helpers" (("r" org-reveal "org reveal") ("k" jao-kb-toggle "toggle keyboard" :toggle (jao-kb-toggled-p) :color red) ("M" jao-minibuffer-toggle "toggle minibuffer" :toggle jao-minibuffer-enabled-p)))) #+end_src * Last minute (post.el) #+begin_src emacs-lisp (jao-load-site-el "post") #+end_src