#+property: header-args :lexical t :tangle yes :comments yes :results silent :shebang ";; -*- lexical-binding: t -*-" :tangle-mode (identity #o644) * Packages *** Use package #+begin_src emacs-lisp (unless (package-installed-p 'use-package) (package-refresh-contents) (package-install 'use-package)) (require 'use-package) #+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 *** 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-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) (add-to-list 'load-path "/usr/local/share/emacs/site-lisp/") (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 "~/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 (and window-system (not (daemonp))) (server-start)) #+end_src * System utilities *** Tramp #+begin_src emacs-lisp (setq tramp-mode nil) #+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) " ")))) (defun jao-exec-running-p (pr) (not (string-blank-p (shell-command-to-string (concat "pidof " pr))))) #+end_src *** App launcher #+begin_src emacs-lisp (jao-load-path "app-launcher") (use-package app-launcher :bind (("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 #+begin_src emacs-lisp (use-package repeat :config (setq repeat-echo-function #'repeat-echo-mode-line)) (when (> emacs-major-version 27) (repeat-mode)) (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) (setq echo-keystrokes 1 suggest-key-bindings nil) #+end_src *** Transient #+begin_src emacs-lisp (use-package transient :init (setq transient-show-popup 2.0) :demand t :config (transient-bind-q-to-quit)) (defmacro jao-transient-major-mode (mode &rest suffix) (declare (indent defun)) (let ((mode (intern (format "%s-mode" mode))) (mmap (intern (format "%s-mode-map" mode))) (name (intern (format "jao-transient-%s" mode)))) `(progn (transient-define-prefix ,name () ,(format "Transient ops for %s" mode) [,(format "Operations for %s" mode) :if-derived ',mode ,@suffix]) (define-key ,mmap (kbd "s-SPC") #',name)))) (defmacro jao-transient-major-mode+1 (mode suffix) (declare (indent defun)) (let ((name (intern (format "jao-transient-%s" mode)))) (if (fboundp name) `(transient-append-suffix ',name '(0 -1) ,suffix) `(jao-transient-major-mode ,mode ,suffix)))) (defmacro jao-transient-major-mode+ (mode &rest suffixes) (declare (indent defun)) `(progn ,@(mapcar (lambda (s) `(jao-transient-major-mode+1 ,mode ,s)) suffixes))) #+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 *** pass #+begin_src emacs-lisp (use-package password-store :ensure t :bind (("C-c p" . jao-transient-password))) (transient-define-prefix jao-transient-password () [[("c" "copy secret" password-store-copy) ("C" "copy field" password-store-copy-field)] [("i" "insert entry" password-store-insert) ("e" "edit entry" password-store-edit) ("g" "generate password" password-store-generate)] [("d" "delete entry" password-store-remove) ("r" "rename entry" password-store-rename)]]) #+end_src *** Pinentry #+begin_src emacs-lisp (use-package pinentry :ensure t) (pinentry-start) #+end_src * Fonts and colour themes *** Widgets #+begin_src emacs-lisp (setq widget-image-enable nil widget-link-prefix "" widget-link-suffix "↗" widget-button-prefix " " widget-button-suffix " " widget-push-button-prefix "" widget-push-button-suffix "") #+end_src *** Fonts ***** fontsets 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 (f) (set-fontset-font t 64257 "Quivira" f) (set-fontset-font t 'egyptian "Noto Sans Egyptian Hieroglyphs" f) (set-fontset-font t 'hangul "NanumGothicCoding" f) (set-fontset-font t 'unicode (face-attribute 'default :family) f) (set-fontset-font t 'unicode-bmp (face-attribute 'default :family) f) (set-fontset-font t 'symbol "Symbola-10" f) (set-fontset-font t 'greek "GFS Didot" f) (set-fontset-font t 'mathematical "FreeSerif" f) (set-fontset-font t 'emoji "Noto Color Emoji" f) ;; boxes (set-fontset-font t '(9472 . 9599) "Source Code Pro" f) ;; variation selector-16 (set-fontset-font t 65039 "BabelStone Modern-1" f)) (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)) (defvar jao-default-font "Hack-9") ;; "Fira Code-9" (require 'jao-themes) (defun jao-themes-setup () (let ((dark (jao-colors-scheme-dark-p))) (load-theme (if dark 'jao-dark 'jao-light) t))) (when (and window-system (not (eq window-system 'pgtk))) (jao-themes-setup)) (global-font-lock-mode 1) #+end_src * Help system *** Help buffers and shortcuts #+begin_src emacs-lisp (setq help-window-select t help-link-key-to-documentation t) (use-package find-func :bind (("C-h C-v" . find-variable) ("C-h C-f" . find-function) ("C-h C-k" . find-function-on-key) ("C-h C-l" . find-library))) #+end_src *** eldoc #+begin_src emacs-lisp (use-package eldoc :init (setq eldoc-mode-line-string nil eldoc-echo-area-use-multiline-p t eldoc-echo-area-prefer-doc-buffer nil eldoc-display-functions '(eldoc-display-in-echo-area)) :config (global-eldoc-mode 1) :diminish ((eldoc-mode . ""))) #+end_src *** Bookmarks #+begin_src emacs-lisp (setq bookmark-default-file "~/.emacs.d/emacs.bmk" bookmark-set-fringe-mark nil) #+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 *** transparency #+begin_src emacs-lisp (defvar jao-transparent-only-bg t) (defvar jao-frames-default-alpha (cond ((eq window-system 'pgtk) 80) (jao-transparent-only-bg 85) (t 85))) (defvar jao-transparent-frame (< jao-frames-default-alpha 100)) (defun jao-transparent-p () jao-transparent-frame) (defun jao-alpha-parameters (&optional level) (let ((level (or level jao-frames-default-alpha))) (if jao-transparent-only-bg `((alpha-background . ,level) (alpha)) `((alpha . ,(cons level level)) (alpha-background))))) (defun jao-set-transparency (&optional level all) (interactive "nOpacity (0-100): ") (let ((level (or level jao-frames-default-alpha))) (setq jao-transparent-frame (< level 100)) (if all (modify-all-frames-parameters (jao-alpha-parameters level)) (modify-frame-parameters nil (jao-alpha-parameters level))))) (defun jao-toggle-transparency (&optional all) (interactive "P") (let ((level (if jao-transparent-frame 100 jao-frames-default-alpha))) (jao-set-transparency level all))) #+end_src *** 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 nil) (defun jao-exwm-enabled-p () jao-exwm-enabled) (defun jao-exwm-enable () (jao-load-org "exwm.org") (setq jao-exwm-enabled t) (display-time-mode -1) (exwm-enable) (setq jao-transparent-only-bg t jao-frames-default-alpha 88) (jao-set-transparency) (x-change-window-property "_XMONAD_TRAYPAD" "" nil nil nil nil 0) (jao-trisect t)) #+end_src *** xmonad #+begin_src emacs-lisp (defvar jao-xmonad-enabled (string= "xmonad" (or (getenv "wm") ""))) (defun jao-xmonad-enable () (setq jao-browse-doc-use-emacs-p t) (setq jao-minibuffer-right-margin " ") (setq jao-wallpaper-random-wake nil) (jao-trisect) (setq jao-transparent-only-bg t jao-frames-default-alpha 88) (jao-set-transparency) (jao-themes-setup) (message "Welcome to xmonad")) (when jao-xmonad-enabled (add-hook 'after-init-hook #'jao-xmonad-enable)) #+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 (and (eq window-system 'pgtk) (not jao-xmonad-enabled))) (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 (jao-exec-running-p "firefox") (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-run-or-focus-deezer () (interactive) (if (jao-exec-running-p "deezer-desktop") (jao-swaymsg "[app_id=Deezer] scratchpad show") (start-process-shell-command "deezer" nil "deezer &") (jao-sway-run-or-focus-deezer))) (defun jao-sway-run-or-focus-firefox () (interactive) (jao-sway-run-or-focus "firefox")) (defun jao-sway-enable () (setq jao-browse-doc-use-emacs-p t) (setq jao-minibuffer-right-margin "") (setq jao-wallpaper-random-wake nil) (jao-trisect) (jao-set-transparency 85) (jao-themes-setup) ;; (display-time-mode 1) (global-set-key (kbd "s-f") #'jao-sway-run-or-focus-firefox) (message "Welcome to sway")) (when jao-sway-enabled (defalias 'x-change-window-property #'ignore) (add-hook 'after-init-hook #'jao-sway-enable)) #+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 (jao-sway-set-wallpaper (expand-file-name f)) (shell-command (format "xwallpaper --zoom %s" f)))))) (defun jao-set-random-wallpaper () (interactive) (when (or (called-interactively-p 'interactive) 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" "systemctl" "suspend") (jao-def-exec jao-poweroff "sudo" "systemctl" "poweroff") (defun jao-lock-screen () (interactive) (if jao-sway-enabled (shell-command "swaylock -i ~/.lockimage") (jao-xlock-screen))) (transient-define-prefix jao-transient-sleep () ["Sleep" ("l" "lock screen" jao-lock-screen) ("z" "sleep" jao-suspend) ("u" "enable/disable screensaver" jao-screensaver-toggle) ("poof" "power-off" jao-poweroff)]) #+end_src *** X clipboard #+BEGIN_SRC emacs-lisp (setq select-enable-clipboard t select-enable-primary t selection-timeout 100) #+END_SRC * Mode line and minibuffer *** 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) "Transform a time string to an epoch integer in milliseconds." (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) "Transform an epoch, given in milliseconds, to a time string." (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)))))) (setq display-time-day-and-date nil display-time-24hr-format nil display-time-default-load-average nil display-time-format " %a %e %H:%M") #+end_src *** Minibuffer #+begin_src emacs-lisp (defvar jao-modeline-in-minibuffer-p (and window-system t)) (use-package jao-minibuffer :init (if (jao-colors-scheme-dark-p) (setq jao-minibuffer-active-buffer-line-color "azure4" jao-minibuffer-inactive-buffer-line-color "grey25") (setq jao-minibuffer-active-buffer-line-color "burlywood3" jao-minibuffer-inactive-buffer-line-color "grey65")) :commands (jao-minibuffer-add-variable jao-minibuffer-refresh jao-minibuffer-add-mode-line jao-minibuffer-mode)) (setq enable-recursive-minibuffers t) (require 'mb-depth) (minibuffer-depth-indicate-mode 1) (require 'minibuf-eldef) (setq minibuffer-eldef-shorten-default t) (minibuffer-electric-default-mode 1) (jao-minibuffer-mode 1) (when jao-modeline-in-minibuffer-p (add-hook 'display-time-hook #'jao-minibuffer-refresh) (jao-minibuffer-add-mode-line 90)) #+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")) (setq mode-line-percent-position '(" %l" (:eval (format "/%d" (line-number-at-pos (point-max)))))) (line-number-mode -1) (column-number-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--set-inactive-face (x frame) (unless (eq x (face-attribute 'mode-line-inactive :height frame)) (set-face-attribute 'mode-line-inactive frame :height x))) (defun jao--hide-inactive-mode-line (frame) (jao--set-inactive-face 1 frame)) (defun jao--show-inactive-mode-line (frame) (jao--set-inactive-face 'unspecified frame)) (when (and window-system (not jao-modeline-in-minibuffer-p)) (add-hook 'after-init-hook #'jao-toggle-inactive-mode-line) (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 "autorevert" '(diminish 'auto-revert-mode ""))) #+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 ")) ;; " 🔋%b%p " (display-battery-mode 1) (with-eval-after-load "jao-minibuffer" (unless jao-modeline-in-minibuffer-p (jao-minibuffer-add-variable 'battery-mode-line-string 80))) #+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) #+end_src *** tracking #+begin_src emacs-lisp (use-package tracking :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-tracking-update-minibuffer)) :bind (("C-c C-SPC" . jao-tracking-next-buffer))) (use-package jao-tracking :demand t :init (setq jao-tracking-bkg (if (jao-colors-scheme-dark-p) "grey20" "grey93"))) #+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 (setq appt-display-format nil) (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))))) (add-to-list 'display-buffer-alist `(,(regexp-quote diary-fancy-buffer) (display-buffer-at-bottom) (window-parameters (mode-line-format . none)) (window-height . fit-window-to-buffer))) (defun jao-diary--select () (switch-to-buffer diary-fancy-buffer)) (add-hook 'diary-fancy-display-mode-hook #'jao-diary--select) (setq org-calendar-insert-diary-entry-key nil org-agenda-diary-file 'diary-file) #+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) (term-send-string "clear;curl wttr.in\n")) (jao-exec-in-term "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) (setq dired-kill-when-opening-new-dired-buffer 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) (global-set-key (kbd "C-c D") #'find-name-dired) #+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 *** Executable scripts #+begin_src emacs-lisp (add-hook 'after-save-hook 'executable-make-buffer-file-executable-if-script-p) #+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 *** Completion #+begin_src emacs-lisp (jao-load-org "completion") #+end_src * Buffers *** cursor and mark #+begin_src emacs-lisp (transient-mark-mode -1) (blink-cursor-mode -1) (setq cursor-in-non-selected-windows nil) #+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 kill-buffer-delete-auto-save-files t) (setq lock-file-name-transforms '(("\\`/.*/\\([^/]+\\)\\'" "/tmp/emacs-lock/\\1" 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) (declare (indent defun)) `(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 switch-fn) (interactive) (let* ((mode (or mode major-mode)) (modes (if (symbolp mode) (list mode) mode)) (pred `(lambda (b) (let ((b (get-buffer (if (consp b) (car b) b)))) (member (buffer-local-value 'major-mode b) ',modes)))) (buff (read-buffer "Buffer: " nil t pred))) (when pre-fn (funcall pre-fn)) (if switch-fn (funcall switch-fn buff) (pop-to-buffer buff)))) (global-set-key (kbd "C-c C-b") #'jao-buffer-same-mode) #+end_src *** projects #+begin_src emacs-lisp (use-package project :bind (("C-x C-p" . project-prefix-map))) #+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 4 scroll-step 2 redisplay-skip-fontification-on-input t) #+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 already visible in ;; this 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 (> arg 0) (1- arg) (1+ arg)))))) (defun jao-transpose-windows-prev () (interactive) (jao-transpose-windows -1)) (define-key ctl-x-4-map (kbd "t") #'jao-transpose-windows) (global-set-key (kbd "M-O") #'jao-transpose-windows) (global-set-key (kbd "M-P") #'jao-transpose-windows-prev) #+end_src *** Window navigation #+begin_src emacs-lisp (defvar jao-first-window--from nil) (defun jao-first-window () "Go to previous windows in frame, remembering where we were." (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)))) (defun jao-prev-window () "Go to previous window." (interactive) (other-window -1)) (defun jao--nth-window (n) (let ((jao-minibuffer-mode nil) (ignore-window-parameters t)) (select-window (frame-first-window)) (other-window n)) (jao-minibuffer-refresh)) (defalias 'jao-other-window 'other-window) (global-set-key (kbd "s-a") #'jao-first-window) (global-set-key (kbd "C-x p") 'jao-prev-window) (global-set-key (kbd "M-o") #'jao-other-window) (global-set-key (kbd "M-p") #'jao-prev-window) (global-set-key (kbd "C-c 0") #'jao-first-window) (dolist (n '(0 1 2 3 4 5 6 7 8)) (global-set-key (format "\C-c%s" (1+ n)) (lambda () (interactive) (jao--nth-window n)))) #+end_src *** winner mode #+begin_src emacs-lisp (winner-mode 1) #+end_src * Frames *** Frame geometry #+begin_src emacs-lisp (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) (font . ,jao-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 -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) (jao-minibuffer-add-variable '(jao-current--frame-id) 100) (defun jao-afio--set-mode-line () (if (string= "Docs" (jao-afio-current-frame)) (jao--show-inactive-mode-line nil) (jao--hide-inactive-mode-line nil))) (unless jao-modeline-in-minibuffer-p (add-hook 'jao-afio-switch-hook #'jao-afio--set-mode-line)) #+end_src * Writing and writing modes *** Copyright notices #+begin_src emacs-lisp (setq copyright-year-ranges t) (add-hook 'write-file-functions 'copyright-update) #+end_src *** Indent on yank #+begin_src emacs-lisp ;;; 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))) #+end_src *** 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")) ;; text mode, autoinserts and write hooks ;;; misc (setq default-major-mode 'text-mode) (add-hook 'text-mode-hook 'turn-on-auto-fill) #+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 (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 ;; '((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")) (setq LaTeX-command "latex -shell-escape") (setq LaTeX-biblatex-use-Biber t) (setq bibtex-dialect 'biblatex) :config (add-hook 'TeX-after-compilation-finished-functions #'TeX-revert-document-buffer) (add-hook 'LaTeX-mode-hook 'turn-on-reftex) ) ;; (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))) (defvar jao-video--ext-rx (format "^https?://.+/.+\\.%s" (regexp-opt '("mp3" "webm" "mp4")))) (defun jao-video--url-p (url) (or (string-match-p jao-video--url-rx url) (string-match-p jao-video--ext-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 *** Web browsers #+begin_src emacs-lisp (defun jao-www--buffer-p (b) (with-current-buffer b (or (derived-mode-p 'w3m-mode 'eww-mode) (member (buffer-local-value 'exwm-class-name b) '("vlc" "mpv"))))) ;; (jao-load-org "w3m") (jao-load-org "eww") #+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 (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")) (defvar jao-browse-external-domains '("github.com" "gitlab.com" "slack.com" "meet.google.com" "twitter.com" "t.com" "linkedin.com" "bigml.com")) (defvar jao-browse--external-regexp (format "https?://.*%s\\(/.*\\)?" (regexp-opt jao-browse-external-domains))) (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)) (defvar jao-browse--sound-rx (format "^https?://.*/.*\\.%s" (regexp-opt '("mp4" "mp3" "flv")))) (defun jao-browse-add-url-to-mpc (url &rest _) "Add the given URL to mpc's playing list, or just play it." (let ((p (yes-or-no-p (format "Play %s right now?" url)))) (when p (jao-mpc-clear)) (jao-mpc-add-url url) (if p (jao-mpc-play) (message "%s added to mpc queue" 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) (,jao-browse--external-regexp . ,jao-browse-url-external-function) ("^https?://.*\\.gotomeeting\\.com\\.*" . browse-url-chrome) (,jao-browse--sound-rx . jao-browse-add-url-to-mpc) (,(jao-wget--regexp) . jao-download) (jao-video--url-p . jao-maybe-view-video) ("." . ,jao-browse-url-function))) (when (< emacs-major-version 28) (setf (alist-get 'jao-video--url-p browse-url-handlers nil t) nil) (setq browse-url-browser-function browse-url-handlers)) #+end_src *** Subscribe rss using r2e #+begin_src emacs-lisp (autoload 'View-quit "view") (defun jao-rss--find-url () (save-excursion (when (derived-mode-p 'w3m-mode 'eww-mode) (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)))) (cond ((derived-mode-p 'w3m-view-mode) (w3m-view-source)) ((string-match-p ".*\\*eww-source\\b.*" (buffer-name)) (View-quit))) (when url (cons url (or title ""))))))) (defun jao-rss2e-append (name url mbox) (with-current-buffer (find-file-noselect "~/.config/rss2email.cfg") (goto-char (point-max)) (insert "[feed." name "]\nurl = " url) (insert "\nto = " mbox "+" name "@localhost") (insert "\nmaildir-mailbox = " mbox "\n\n") (save-buffer))) (defun jao-rss-subscribe (url) "Subscribe to a given RSS URL. If URL not given, look for it." (interactive (list (or (jao-url-around-point) (jao-rss--find-url) (read-string "Feed URL: ")))) (let* ((url+title (if (consp url) url (list url))) (url (car url+title)) (title (cdr url+title)) (cats (jao-notmuch--subtags "feeds"))) (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 "Feed name: " title)) (cat (completing-read "Category: " cats nil t)) (subs (format "r2e add %s '%s' feeds.%s@localhost" name url cat))) ;; (jao-rss2e-append name url cat) (shell-command-to-string subs) (shell-command (format "r2e run %s" name))))) (message "No feeds found")))) #+end_src * Email #+begin_src emacs-lisp (setq jao-afio-mail-function 'notmuch) (setq jao-afio-mail-function 'gnus) (jao-load-org "email") #+end_src * PDFs *** doc-view and pdf-tools #+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) :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 pdf-tools :ensure t :demand t :init (add-hook 'after-init-hook (lambda () (setq pdf-view-midnight-colors (cons (frame-parameter nil 'foreground-color) (frame-parameter nil 'background-color))))) :config (pdf-tools-install) :diminish ((pdf-view-midnight-minor-mode . "")) :bind (:map pdf-view-mode-map (("C-c C-d" . pdf-view-midnight-minor-mode) ("j" . pdf-view-next-line-or-next-page) ("J" . pdf-view-scroll-up-or-next-page) ("k" . pdf-view-previous-line-or-previous-page) ("K" . pdf-view-scroll-down-or-previous-page)))) (use-package saveplace-pdf-view :ensure t :demand t :after doc-view) (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))) #+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) (defun jao-select-pdf () (interactive) (jao-buffer-same-mode '(pdf-view-mode doc-view-mode) #'jao-afio--goto-docs)) #+end_src *** transient #+begin_src emacs-lisp (defun jao-org-pdf-goto-org-linking () (interactive) (jao-org-pdf-goto-org 4)) (jao-transient-major-mode doc-view ["Notes" ("o" "notes file" jao-org-pdf-goto-org) ("O" "notes file, linking" jao-org-pdf-goto-org-linking)] ["Navigation" ("b" "back jump" jao-doc-view-back) ("B" "forward jump" jao-doc-view-back) ("u" "visit URL" jao-doc-view-visit-url)] ["Slices" ("cb" "bounding box" doc-view-set-slice-from-bounding-box) ("cm" "using mouse" doc-view-set-slice-using-mouse)] ["Session" ("s" "load session" jao-open-pdf-session) ("S" "save session" jao-doc-view-save-session) ("d" "visit cache directory" doc-view-dired-cache)]) (jao-transient-major-mode pdf-view ["Notes" ("o" "notes file" jao-org-pdf-goto-org) ("O" "notes file, linking" jao-org-pdf-goto-org-linking)] ["Navigation" ("b" "back jump" pdf-history-backward) ("f" "forward jump" pdf-history-forward)] ["Session" ("s" "load session" jao-afio-open-pdf-session) ("S" "save session" jao-doc-view-save-session)]) ;; (transient-get-suffix 'jao-transient-pdf-view '(0 -1)) #+end_src * Shells and terms *** 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 (defvar jao-use-vterm nil) (use-package vterm :ensure t :demand t :commands (vterm vterm-mode) :init (setq vterm-kill-buffer-on-exit t vterm-copy-exclude-prompt t jao-use-vterm t) :config (jao-define-attached-buffer "\\*vterm\\*" 0.5) :bind (("" . vterm))) (defun jao-exec-in-vterm (cmd bname) (if (string-blank-p (or cmd "")) (vterm) (let ((vterm-shell cmd) (vterm-kill-buffer-on-exit t) (buff (generate-new-buffer bname))) (switch-to-buffer buff) (vterm-mode)))) #+end_src *** term #+begin_src emacs-lisp (defvar-local jao-term--cmd nil) (defun jao-term--find (cmd) (seq-find (lambda (b) (with-current-buffer b (and (derived-mode-p 'term-mode 'vterm-mode) (string= (or jao-term--cmd "") cmd)))) (buffer-list))) (defun jao-exec-in-term (cmd &optional name) (if jao-use-vterm (jao-exec-in-vterm cmd name) (ansi-term "bash" name) (set-process-sentinel (get-buffer-process (current-buffer)) (lambda (process event) (when (string= event "finished\n") (kill-buffer (process-buffer process))))) (term-send-string nil (concat cmd " ; exit\n")))) (defmacro jao-def-exec-in-term (name cmd &rest prelude) `(defun ,(intern (format "jao-term-%s" name)) (&optional term) (interactive "P") ,@prelude (let ((jao-use-vterm (if term (not jao-use-vterm) jao-use-vterm))) (if-let ((b (jao-term--find ,cmd))) (pop-to-buffer b) (jao-exec-in-term ,cmd ,(format "*%s*" name)) (setq-local jao-term--cmd ,cmd))))) #+end_src *** eshell ***** Basic custom #+begin_src emacs-lisp (use-package eshell :init (setq eshell-directory-name "~/.emacs.d/eshell") (setq eshell-hist-ignoredups 'erase) (defun jao-eshell--outline () (setq-local outline-regexp eshell-prompt-regexp)) :hook (eshell-mode . jao-eshell--outline)) #+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" "guile" "ssh" "autossh" "zmore" "pager" "aptitude" "su" "htop" "top" "screen" "whizzml" "iex" "spt")) (add-to-list 'eshell-visual-commands c)) (setq eshell-visual-subcommands '(("git" "log" "diff" "show") ("sudo" "vim") ("rebar3" "shell")) eshell-destroy-buffer-when-process-dies nil eshell-escape-control-x t) (use-package eshell-vterm :ensure t) (when jao-use-vterm (eshell-vterm-mode)) #+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 () (let* ((b (save-excursion (eshell-bol) (point))) (c (bash-completion-dynamic-complete-nocomint b (point) t))) (when (and c (listp c)) (append c '(:exclusive no))))) (defun jao-eshell--set-up-completion () (setq-local completion-styles '(basic partial-completion) completion-at-point-functions '(jao-eshell-completion-capf pcomplete-completions-at-point t))) (use-package bash-completion :ensure t :hook (eshell-mode . jao-eshell--set-up-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 ***** Toggle #+begin_src emacs-lisp (use-package jao-eshell-here :demand t :config (jao-define-attached-buffer "^\\*eshell" 0.5) :bind (("" . jao-eshell-here-toggle) ("C-" . jao-eshell-here-toggle-new))) #+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 * 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 :custom ((diff-hl-draw-borders nil) (diff-hl-side 'right) (diff-hl-margin-symbols-alist '((insert . "+") (delete . "-") (change . "~") (unknown . "?") (ignored . "i")))) :config (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) (when (jao-colors-scheme-dark-p) (diff-hl-margin-mode 1))) (global-diff-hl-mode 1) #+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-define-global-key-bindings 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/elisp" . 3) ("/usr/local/src" . 1)) magit-save-repository-buffers 'dontask magit-status-buffer-switch-function 'switch-to-buffer magit-status-show-hashes-in-headers t) :bind (("" . magit-status))) (use-package code-review :ensure t :after forge :bind (:map magit-status-mode-map ("C-c C-r" . code-review-forge-pr-at-point))) (use-package forge :ensure t :after magit :init (setq forge-topic-list-limit (cons 25 10)) :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 *** Eldoc for magit status/log buffers [[https://tsdh.org/posts/2021-06-21-using-eldoc-with-magit.html][Using Eldoc with Magit]]. #+begin_src emacs-lisp (defun jao-magit-eldoc-for-commit (_callback) (when-let ((commit (magit-commit-at-point))) (with-temp-buffer (magit-git-insert "show" "--format=format:%an <%ae>, %ar" (format "--stat=%d" (window-width)) commit) (goto-char (point-min)) (put-text-property (point-min) (line-end-position) 'face 'bold) (buffer-string)))) (defun jao-magit-eldoc-setup () (add-hook 'eldoc-documentation-functions #'jao-magit-eldoc-for-commit nil t) (eldoc-mode 1)) (add-hook 'magit-log-mode-hook #'jao-magit-eldoc-setup) (add-hook 'magit-status-mode-hook #'jao-magit-eldoc-setup) (with-eval-after-load "eldoc" (eldoc-add-command 'magit-next-line) (eldoc-add-command 'magit-previous-line) (eldoc-add-command 'magit-section-forward) (eldoc-add-command 'magit-section-backward)) #+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 git-modes :ensure t) #+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 (&rest _) (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) (advice-add 'jenkins-job-render :after #'jao-jenkins-first-job) (defun jenkins-refresh-console-output () (interactive) (let ((n (buffer-name))) (when (string-match "\\*jenkins-console-\\([^-]+\\)-\\(.+\\)\\*$" n) (jenkins-get-console-output (match-string 1 n) (match-string 2 n)) (goto-char (point-max))))) :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 *** 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) (setq show-paren-context-when-offscreen 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 (setq compilation-message-face 'default) (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 *** Workarounds #+begin_src emacs-lisp (setq c-type-finder-time-slot nil) #+end_src * Programming languages *** Elisp #+begin_src emacs-lisp (use-package edit-list :ensure t) (use-package package-lint :ensure t) (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 (macroexpand-all form))) (defun elisp-find-definition (name) (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) (xref-push-marker-stack) (funcall search 'find-function-noselect symbol)) ((boundp symbol) (xref-push-marker-stack) (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)))) (use-package elisp-mode :bind (:map emacs-lisp-mode-map (("C-c C-M" . emacs-lisp-macroexpand) ("C-c C-m" . elisp-macroexpand-all) ("C-c C-k" . elisp-bytecompile-and-load) ("C-c C-p" . pp-eval-last-sexp) ("M-." . elisp-find-definition) ("M-," . pop-tag-mark) ("C-c <" . lc-show-package-summary)))) #+end_src *** Erlang #+begin_src emacs-lisp (use-package erlang :disabled t :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.*") #+end_src *** Clojure #+begin_src emacs-lisp (use-package clojure-mode :ensure t :config (defun jao-clojure--fix-things () (setq-local completion-styles '(basic partial-completion emacs22)) (eldoc-mode 1) (setq mode-name "λ")) :hook (clojure-mode . jao-clojure--fix-things)) (use-package cider :ensure t :commands cider-mode :init (setq cider-annotate-completion-candidates t cider-auto-select-error-buffer nil cider-auto-select-test-report-buffer nil cider-eldoc-display-for-symbol-at-point t cider-enrich-classpath nil cider-lein-parameters "repl :headless :host localhost" cider-mode-line " ÷" cider-prompt-for-symbol nil cider-repl-history-file (expand-file-name "~/.emacs.d/cache/cider.history") cider-repl-pop-to-buffer-on-connect nil cider-repl-use-pretty-printing t cider-show-error-buffer 'except-in-repl cider-test-show-report-on-success nil cider-use-fringe-indicators nil cider-use-overlays nil clojure-docstring-fill-column 72 nrepl-prompt-to-kill-server-buffer-on-quit nil)) (with-eval-after-load "cider-test" (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 " µ") #+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" geiser-repl-startup-time 20000 geiser-debug-auto-display-images-p t geiser-log-verbose-p t geiser-active-implementations '(guile) geiser-default-implementation 'guile)) (jao-load-path "geiser/guile") (use-package geiser-guile) ;; (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/chez") ;; (use-package geiser-chez ;; :init (setq geiser-chez-binary "scheme")) ;; (jao-load-path "geiser/gambit") ;; (use-package geiser-gambit) ;; (jao-load-path "geiser/gauche") ;; (use-package geiser-gauche) (jao-define-attached-buffer "^\\* ?Geiser .*\\*" 0.4) (jao-define-attached-buffer "^\\* Guile REPL \\*" 0.4) #+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)) (put 'haskell-process-args-cabal-repl 'safe-local-variable (apply-partially #'seq-every-p #'stringp)) (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 ***** transient #+begin_src emacs-lisp (jao-transient-major-mode haskell ["Imports" ("in" "Navigate imports" haskell-navigate-imports) ("if" "Format imports" haskell-mode-format-imports) ("is" "Sort imports" haskell-sort-imports) ("ia" "Align imports" haskell-align-imports)] ["Code" ("c" "Compile" haskell-compile) ("s" "stylish on buffer" haskell-mode-stylish-buffer)] ["Hoogle" ("h" "Hoogle" jao-haskell-hoogle) ("H" "Hoogle from local server" haskell-hoogle-lookup-from-local)]) #+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 :tangle no (use-package sly :ensure t :init (setq inferior-lisp-program "sbcl") :config (sly-setup)) (use-package sly-quicklisp :after (sly) :ensure t) #+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 *** Racket #+begin_src emacs-lisp :tangle no (use-package racket-mode :ensure t :init (setq racket-show-functions '(racket-show-echo-area)) :config (jao-define-attached-buffer "\\`\\*Racket REPL") (jao-define-attached-buffer "\\`\\*Racket Describe" 0.5) (add-hook 'racket-mode-hook #'paredit-mode) (require 'racket-xp) (add-hook 'racket-mode-hook #'racket-xp-mode) :bind (:map racket-mode-map (("C-c C-d" . racket-xp-describe) ("C-c C-S-d" . racket-xp-documentation)))) #+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 *** 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 *** nm applet #+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 *** enwc #+begin_src emacs-lisp (use-package enwc :ensure t :custom ((enwc-default-backend 'nm) (enwc-wired-device "wlp164s0") (enwc-wireless-device "wlp164s0") (enwc-display-mode-line nil))) #+end_src *** bluetooth #+BEGIN_SRC emacs-lisp (use-package bluetooth :ensure t) #+END_SRC *** vpn #+begin_src emacs-lisp (use-package jao-mullvad :demand t) #+end_src *** ssh #+begin_src emacs-lisp (use-package tramp) (defun jao-tramp-hosts () (seq-uniq (mapcan (lambda (x) (remove nil (mapcar 'cadr (apply (car x) (cdr x))))) (tramp-get-completion-function "ssh")) #'string=)) (defun jao-ssh () (interactive) (let ((h (completing-read "Host: " (jao-tramp-hosts)))) (jao-afio-goto-scratch) (jao-exec-in-term (format "ssh %s" h) (format "*ssh %s*" h)))) #+end_src * Chats *** circe #+begin_src emacs-lisp (defvar jao-libera-channels '()) (defvar jao-oftc-channels '()) (defvar jao-bitlbee-channels '()) (use-package circe :ensure t :bind (:map circe-channel-mode-map (("C-c C-a" . lui-track-jump-to-indicator))) :init (setq circe-chat-buffer-name "{target}" 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 (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))) (defun circe-command-NNICKS (&rest _) "Echo number of nicks" (circe-display-server-message (format "%d nicks in this channel" (length (circe-channel-nicks))))) (advice-add 'circe-command-NAMES :after #'circe-command-NNICKS) (setq circe-network-options (let ((up (jao--get-user/password "libera")) (oup (jao--get-user/password "oftc")) (bup (jao--get-user/password "bitlbee"))) `(("Libera Chat" :nick ,(car up) :channels ,jao-libera-channels :tls t :sasl-username ,(car up) :sasl-password ,(cadr up)) ("OFTC" :nick ,(car oup) :channels ,jao-oftc-channels :nickserv-password ,(cadr oup) :tls t :sasl-username ,(car oup) :sasl-password ,(cadr oup)) ("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) (enable-lui-track) (circe-lagmon-mode) (enable-circe-display-images)) #+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 :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 "~/var/download/slack/" 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)) :map slack-message-buffer-mode-map (("C-c C-e" . slack-message-edit) ("C-c C-a" . slack-file-upload))) :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-faces 'warning) (jao-define-attached-buffer "\\*Slack .+ Edit Message [0-9].+" 20)) #+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-chat-prompt-format ">> " telega-root-show-avatars 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-faces '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-faces 'signel-notification) (jao-shorten-modes 'signel-chat-mode)) (setq signel-report-deliveries t) #+end_src *** startup #+begin_src emacs-lisp (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 (or p (y-or-n-p "Connect to libera? ")) (circe "Libera Chat"))) (defun jao-all-chats () (interactive) (jao-chats t)) (defun jao-chats-telega () (interactive) (jao-buffer-same-mode '(telega-root-mode telega-chat-mode))) (add-to-list 'mct-completion-passlist #'jao-chats-telega) (defun jao-chats-slack () (interactive) (jao-buffer-same-mode 'slack-message-buffer-mode)) (add-to-list 'mct-completion-passlist #'jao-chats-slack) (defun jao-chats-irc () (interactive) (jao-buffer-same-mode '(circe-channel-mode circe-query-mode erc-mode))) (add-to-list 'mct-completion-passlist #'jao-chats-irc) #+end_src * Multimedia *** mixer #+begin_src emacs-lisp (defun jao-mixer-get-level (&optional dev) (interactive) (let* ((dev (or dev "Master")) (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 *** mpris #+begin_src emacs-lisp (defun jao-mpris-lyrics (&optional force) (interactive "P") (jao-show-lyrics force #'jao-mpris-artist-title)) (use-package jao-mpris :demand t) (defalias 'jao-streaming-list (if jao-sway-enabled #'jao-sway-run-or-focus-deezer #'ignore)) (defalias 'jao-streaming-like #'ignore) (defalias 'jao-streaming-dislike #'ignore) (defalias 'jao-streaming-lyrics #'jao-mpris-lyrics) (defalias 'jao-streaming-toggle #'jao-mpris-play-pause) (defalias 'jao-streaming-next #'jao-mpris-next) (defalias 'jao-streaming-prev #'jao-mpris-previous) (defalias 'jao-streaming-current #'jao-mpris-show-osd) (defalias 'jao-streaming-seek #'jao-mpris-seek) (defalias 'jao-streaming-seek-back #'jao-mpris-seek-back) (defalias 'jao-streaming-volume #'jao-mpris-vol) (defalias 'jao-streaming-volume-down #'jao-mpris-vol-down) (jao-mpris-register "playerctld" :session (if jao-modeline-in-minibuffer-p -10 70)) #+end_src *** mpc #+begin_src emacs-lisp (use-package jao-mpc :demand t :commands jao-mpc-setup) ;; (defvar jao-mopidy-port 6669) (defvar jao-mopidy-port nil) (jao-mpc-setup jao-mopidy-port (if jao-modeline-in-minibuffer-p -10 70)) (defun jao-mpc-pport () (when (jao-mpc--playing-p jao-mopidy-port) jao-mopidy-port)) (defmacro jao-defun-play (name &optional mpc-name) `(defun ,(intern (format "jao-player-%s" name)) () (interactive) (,(intern (format "jao-mpc-%s" (or mpc-name name))) (jao-mpc-pport)))) (jao-defun-play toggle) (jao-defun-play next) (jao-defun-play previous) (jao-defun-play stop) (jao-defun-play echo echo-current) (jao-defun-play list show-playlist) (jao-defun-play info lyrics-track-data) (defun jao-player-seek (delta) (jao-mpc-seek delta (jao-mpc-pport))) (defalias 'jao-player-browse 'jao-mpc-show-albums) (defalias 'jao-player-connect 'jao-mpc-connect) (defalias 'jao-player-play 'jao-mpc-play) #+end_src *** transients #+begin_src emacs-lisp (require 'jao-lyrics) (setq jao-lyrics-info-function #'jao-player-info) (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)))) (defun jao-player-seek-10 () (interactive) (jao-player-seek 10)) (defun jao-player-seek--10 () (interactive) (jao-player-seek -10)) (defun jao-streaming-clear () (interactive) (jao-mpc-clear jao-mopidy-port)) (defun jao-streaming-echo-current () (interactive) (jao-mpc-echo-current jao-mopidy-port)) (defun jao-streaming-show-playlist () (interactive) (jao-mpc-show-playlist jao-mopidy-port)) (defun jao-player-level-cap () (interactive) (jao-mixer-level "Capture")) (use-package jao-random-album :demand t) (jao-def-exec-in-term "aptitude" "aptitude" (jao-afio--goto-scratch)) (jao-def-exec-in-term "htop" "htop" (jao-afio--goto-scratch)) (transient-define-prefix jao-transient-streaming () [:description (lambda () (format "Streaming using %s" jao-mpris-player)) ;; ["Search" ;; ("a" "album" jao-streaming-album) ;; ("A" "artist" jao-streaming-artist) ;; ("t" "track" jao-streaming-track) ;; ("P" "playlist" jao-streaming-playlist)] ["Play" ("s" "toggle" jao-streaming-toggle) ("n" "next" jao-streaming-next) ("p" "previous" jao-streaming-prev)] ["Seek & shout" ("f" "seek fwd" jao-streaming-seek :transient t) ("F" "seek bwd" jao-streaming-seek-back :transient t) ("u" "up" jao-streaming-volume :transient t) ("d" "down" jao-streaming-volume-down :transient t)] ["Browse" ("l" "playing list" jao-streaming-list) ("L" "lyrics" jao-streaming-lyrics) ("w" "currently playing" jao-streaming-current)] ["Act" ("k" "like" jao-streaming-like) ("K" "dislike" jao-streaming-dislike)]]) (transient-define-prefix jao-transient-media () [["Play" ("m" "toggle" jao-player-toggle) ("n" "next" jao-player-next) ("p" "previous" jao-player-previous) ("s" "toggle streaming" jao-streaming-toggle) ] ["Seek and search" ("f" "seek fwd" jao-player-seek-10 :transient t) ("F" "seek bwd" jao-player-seek--10 :transient t) ("a" "select album" jao-mpc-select-album)] ["Browse" ("b" "browse" jao-player-browse) ("l" "show play list" jao-player-list) ("L" "show lyrics" jao-show-lyrics) ("w" "now playing" jao-player-echo)] ["Master volume" ("d" "master down" jao-mixer-master-down :transient t) ("u" "master up" jao-mixer-master-up :transient t) ("M" "master toggle" jao-mixer-master-toggle) ("v" "show" jao-mixer-get-level)] ["Capture volume" ("D" "capture down" jao-mixer-capture-down :transient t) ("U" "capture up" jao-mixer-capture-up :transient t) ("V" "show" jao-player-level-cap)] ["Utilities" ("c" "reconnect to mpd" jao-player-connect) ("N" "next random album" jao-random-album-next) ("r" (lambda () (concat (if jao-random-album-p "dis" "en") "able random album")) jao-random-album-toggle)]]) (global-set-key (kbd "s-m") #'jao-transient-media) #+end_src * General transients #+begin_src emacs-lisp (defun jao-list-packages () (interactive) (jao-afio--goto-scratch-1) (package-list-packages)) (transient-define-prefix jao-transient-utils () "Global operations in X11." [["Notes" ("n" "capture note" jao-org-notes-open-or-create) ("/" "search notes" jao-org-notes-open) ("\\" "grep notes" jao-org-notes-grep)] ["Documents" :if window-system ("d" "go to doc" jao-select-pdf) ("D" "open to doc" jao-open-doc)] ["Packages" ("a" "aptitude" jao-term-aptitude) ("l" "packages" jao-list-packages)] ["Monitors" ("p" "htop" jao-term-htop) ("v" "vpn status" jao-mullvad-status) ("T" "telegram rooster" telega) ("N" "network interfaces" enwc)] ["Network" ("S" "ssh" jao-ssh) ("b" "bluetooth" bluetooth-list-devices) ("c" "connect chats" jao-all-chats)] ["Chats" ("t" "telegram" jao-chats-telega) ("s" "slack" jao-chats-slack) ("i" "irc" jao-chats-irc)] ["Windows" :if window-system ("w" "set wallpaper" jao-set-wallpaper) ("W" "set radom wallpaper" jao-set-random-wallpaper)] ["Helpers" ("r" "org reveal" org-reveal) ("k" (lambda () (concat "keyboard" (when (jao-kb-toggled-p) "*"))) jao-kb-toggle :if window-system) ("M" (lambda () (concat "minibuffer" (when jao-minibuffer-mode "*"))) jao-minibuffer-mode)]]) (global-set-key (kbd "s-w") #'jao-transient-utils) #+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) #+end_src * Last minute (post.el) #+begin_src emacs-lisp (jao-load-site-el "post") #+end_src