diff options
Diffstat (limited to '')
-rw-r--r-- | .dir-locals.el | 7 | ||||
-rw-r--r-- | .gitignore | 4 | ||||
-rw-r--r-- | Makefile | 37 | ||||
-rw-r--r-- | README.org | 195 | ||||
-rw-r--r-- | emacs-00-private.el.gpg | bin | 0 -> 1289 bytes | |||
-rw-r--r-- | emacs-init.org | 6556 | ||||
-rw-r--r-- | gnuplot.org | 215 | ||||
-rw-r--r-- | gnus.org | 646 | ||||
-rw-r--r-- | gpg-agent.org | 51 | ||||
-rw-r--r-- | init-exwm.org | 451 | ||||
-rw-r--r-- | ledgerrc.org | 32 | ||||
-rw-r--r-- | mail.org | 472 | ||||
-rw-r--r-- | package-versions.el | 106 | ||||
-rw-r--r-- | rc.org | 1391 | ||||
-rw-r--r-- | redshift.org | 66 | ||||
-rw-r--r-- | rofi.org | 141 | ||||
-rw-r--r-- | ssh_config.org.gpg | bin | 0 -> 1003 bytes |
17 files changed, 10369 insertions, 1 deletions
diff --git a/.dir-locals.el b/.dir-locals.el new file mode 100644 index 0000000..05bfae2 --- /dev/null +++ b/.dir-locals.el @@ -0,0 +1,7 @@ +;;; Directory Local Variables +;;; For more information see (info "(emacs) Directory Variables") + +((org-mode . ((eval . (add-hook 'before-save-hook + (lambda nil + (fpi/tangle-async)) + nil t))))) @@ -1 +1,3 @@ -tangle/*
\ No newline at end of file +tangle/* +hash/* +*.patch
\ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..0eb9bc8 --- /dev/null +++ b/Makefile @@ -0,0 +1,37 @@ +dst_readme := tangle.sh merge.sh pull.sh link.sh dots.sh + +.PHONY: update merge dev install link tangle fetch pull clean + +update: pull merge dev + git rebase dev+ work+ + +merge: tangle/merge.sh + tangle/merge.sh + +dev: + git fetch + git rebase origin/dev+ dev+ + git rebase master dev+ + git push --force origin dev+ + +install: tangle link + +tangle: tangle/tangle.sh + tangle/tangle.sh + +clean: + rm hash/* + +link: tangle/link.sh + tangle/link.sh + +fetch: + git fetch + +pull: tangle/pull.sh + tangle/pull.sh + +.SILENT: $(addprefix tangle/,$(dst_readme)) +$(addprefix tangle/,$(dst_readme)) &: README.org + mkdir -p tangle + emacs --batch --eval "(and (require 'org) (org-babel-tangle-file \"README.org\"))" &> /dev/null diff --git a/README.org b/README.org new file mode 100644 index 0000000..f336ad0 --- /dev/null +++ b/README.org @@ -0,0 +1,195 @@ +#+PROPERTY: header-args:shell :noweb yes :tangle-mode (identity #o555) +* Contents :QUOTE:TOC_2_gh: +#+BEGIN_QUOTE +- [[#my-dotfiles][My dotfiles]] + - [[#initial-setup][Initial setup]] + - [[#git-setup][Git setup]] + - [[#updating-all-tangled-files][Updating all tangled files]] + - [[#creating-symlinks][Creating symlinks]] + - [[#dots-script][=dots= script]] +#+END_QUOTE + +* My dotfiles +The config files are organized in [[https://www.gnu.org/software/emacs/][emacs]] [[https://orgmode.org/][org mode]] files. They are tangled +and symlinked to the appropriate directories. + +[[file:emacs-init.org::tangle-hook][A hook]] tangles all files automatically on each save. In addition there +are shell scripts that tangle all =.org= files at once. + +The symlinks can be created by manually running the appropriate [[https://orgmode.org/worg/org-contrib/babel/][babel]] +source block in each configuration file or by running the scripts +below. + +** Initial setup +After cloning this repository run + +#+begin_example shell +make install +#+end_example + +to setup the tangled config files and create the necessary symlinks. + +** Git setup +This repository somewhat abuses git branches. Every program's +configuration lives in its own separate branch. All branches are then +merged into =master= using an [[https://git-scm.com/docs/merge-strategies#Documentation/merge-strategies.txt-octopus][octopus merge]]. To keep the git history +clean I reset =master= for every merge. Here is a small script to do +that and push the changes. I mark branches, which I want to keep local +only, with a trailing =+= and then exclude them with the ~+$~ pattern +in grep. + +#+begin_src shell :shebang "#!/bin/bash" :tangle tangle/merge.sh +git checkout master +git reset --hard init +git branch -a | grep -v -e +$ -e master | sed "s/[ *] //" | xargs git merge +git push --force origin master +#+end_src + +To integrate changes from =origin= perform a rebase instead of merge +to loose the old merge commit but keep any local changes. + +#+begin_src shell :shebang "#!/bin/bash" :tangle tangle/pull.sh +git fetch +git rebase origin/master master +#+end_src + +** Updating all tangled files +This script (re-)tangles all =.org= and =.org.gpg= files in the +current directory. Run this in case the org files were updated outside +of your local emacs (e.g. after pulling from a remote). Make sure to +run it from the dotfiles directory. + +#+begin_src shell :shebang "#!/bin/bash" :tangle no +emacs --batch --eval="\ + (progn (require 'org) + (let ((org-confirm-babel-evaluate nil)) + (mapc 'org-babel-tangle-file (split-string \"$(ls *.org *.org.gpg)\"))))" +#+end_src + +The above won't quite work for me as I use [[https://orgmode.org/worg/org-tutorials/encrypting-files.html#org697961a][org-crypt]] in some +configuration files and it also needs to be loaded & setup. For +details see [[file:emacs-init.org::org-crypt-tangle-setup][emacs-init.org]]. + +#+begin_src shell :shebang "#!/bin/bash" :tangle tangle/tangle.sh +files=$(ls *.org *.org.gpg) + +<<checkhashes>> + +echo "Tangling files:$tanglefiles ..." + +emacs --batch --eval="\ + (progn (require 'org) + (require 'org-crypt) + (org-crypt-use-before-save-magic) + (setq org-tags-exclude-from-inheritance '(\"crypt\")) + (setq org-crypt-key \"F1EF502F9E81D81381B1679AF973BBEA6994521B\") + (defun save-without-hook () + (let ((before-save-hook nil)) + (save-buffer))) + (setq org-babel-pre-tangle-hook '(org-decrypt-entries save-without-hook)) + (advice-add 'org-babel-tangle :after '(lambda (&rest r) + (org-encrypt-entries) + (save-without-hook))) + (let ((org-confirm-babel-evaluate nil)) + (mapc 'org-babel-tangle-file (split-string \"$tanglefiles\"))))" +#+end_src + +*** Saving commit hashes to reduce tangling +To reduce the amount of unnecessary tangling, save the commit hash +upon tangling and check it before tangling again. + +Get the commit hash of a file using ~git log~. + +#+NAME: gethash +#+begin_src shell +function gethash { + git log -n 1 --pretty=format:%H -- $1 +} +#+end_src + +We can save all commit hashes by looping over all files. + +#+NAME: savehashes +#+begin_src shell +HASHDIR="hash" +<<gethash>> +for file in $files +do + gethash $file > $HASHDIR/$file +done +#+end_src + +But we really want to check the saved hash against the current hash +first. If they do not match keep the file for tangling. + +#+NAME: checkhashes +#+begin_src shell +HASHDIR="hash" +mkdir -p $HASHDIR +tanglefiles="" +<<gethash>> + +exec 3>&2 +exec 2> /dev/null # disable stderr + +for file in $files +do + if [ $(cat $HASHDIR/$file) == $(gethash $file) ] + then + : # noop + else # if strings not equal or ~cat~ fails + tanglefiles="$tanglefiles $file" + gethash $file > $HASHDIR/$file # save hash + fi +done + +exec 2>&3 #reset stderr +#+end_src + +** Creating symlinks +Each config files contains a source block which creates symlinks of +the tangled configurations to their respective target locations. These +blocks all have the ~:tangle tangle/symlink.sh~ and ~:shebang +#!/bin/bash~ header arguments. The symlinks are created with ~ln -siv~ +to list created symlinks (~-v~) and to ask when overwriting existing +files (~-i~). To always replace all symlinks you can pipe ~yes~ into +the ~ln -siv~ calls: ~yes | tangle/link.sh~. Make sure to run it from +the dotfiles directory. + +As the symlink shell source blocks are scattered in all configuration +files, all files are collected together using ~cat~ and then all blocks +with the correct ~:tangle~ target are tangled. Unfortunately there is +no function to directly only tangle blocks with a certain target, so +this is not straightforward. +#+begin_src shell :shebang "#!/bin/bash" :tangle tangle/link.sh +catFile="concat.org" +symlinkFile="tangle/symlink.sh" + +cat <(cat *.org) <(ls *.org.gpg | xargs gpg --decrypt) > $catFile + +emacs --batch --eval="\ + (progn (require 'org) + (let ((org-confirm-babel-evaluate nil)) + (find-file \"$catFile\") + (search-forward \":tangle $symlinkFile\") + (org-babel-tangle '(16))))" + +rm $catFile + +$symlinkFile +#+end_src + +** =dots= script +I place this script in my =PATH= to execute commands in the dotfiles +directory from anywhere. + +#+begin_src shell :shebang "#!/bin/bash" :tangle tangle/dots.sh +cd ~/git/projects/dotfiles +$@ +#+end_src + +Create a symlink for this script. + +#+BEGIN_SRC sh :tangle tangle/symlink.sh :results silent :shebang "#!/bin/bash" +ln -siv $(pwd)/tangle/dots.sh ~/.local/bin/dots +#+END_SRC diff --git a/emacs-00-private.el.gpg b/emacs-00-private.el.gpg Binary files differnew file mode 100644 index 0000000..1efdb54 --- /dev/null +++ b/emacs-00-private.el.gpg diff --git a/emacs-init.org b/emacs-init.org new file mode 100644 index 0000000..5054727 --- /dev/null +++ b/emacs-init.org @@ -0,0 +1,6556 @@ +# -*- coding: utf-8-unix -*- +#+PROPERTY: header-args:emacs-lisp :tangle tangle/emacs-10-init.el :results silent :noweb yes :tangle-mode (identity #o444) +* Contents :QUOTE:TOC_2_gh: +#+BEGIN_QUOTE +- [[#overview][Overview]] + - [[#about-this-document][About this document]] +- [[#base-settings][Base settings]] + - [[#meta-packages][Meta packages]] + - [[#gui-interface][GUI Interface]] + - [[#devices][Devices]] + - [[#server][Server]] + - [[#exwm][Exwm]] + - [[#font][Font]] + - [[#theme--faces][Theme & Faces]] + - [[#user-info][User info]] + - [[#garbage-collection][Garbage collection]] + - [[#desktop-module][Desktop module]] + - [[#customize][Customize]] + - [[#file-and-input-history][File and input history]] + - [[#local-variables][Local variables]] + - [[#personal-keymap][Personal keymap]] + - [[#base-commands-simpleel][Base commands (simple.el)]] +- [[#selection-and-search-methods][Selection and search methods]] + - [[#completion-frameworks][Completion frameworks]] + - [[#isearch-enhancements][isearch enhancements]] +- [[#directory-project-buffer-window-management][Directory, project, buffer, window management]] + - [[#dired][Dired]] + - [[#tramp][Tramp]] + - [[#git][Git]] + - [[#projects][Projects]] + - [[#consult][Consult]] + - [[#working-with-buffers][Working with buffers]] + - [[#window-configuration][Window configuration]] + - [[#file-encryption][File encryption]] +- [[#applications-and-utilities][Applications and utilities]] + - [[#calendar][Calendar]] + - [[#pdfs][PDFs]] + - [[#latex][Latex]] + - [[#programming-languages][Programming languages]] + - [[#cad][CAD]] + - [[#calc][Calc]] + - [[#org-mode][Org mode]] + - [[#deft][Deft]] + - [[#shell][Shell]] + - [[#grep][Grep]] + - [[#proced][Proced]] + - [[#passwords][Passwords]] + - [[#ledger][Ledger]] + - [[#plotting-data][Plotting data]] + - [[#html-renderer][HTML renderer]] + - [[#email][Email]] + - [[#footnote-mode][Footnote Mode]] + - [[#bbdb][BBDB]] + - [[#compile][Compile]] + - [[#speed-reading][Speed reading]] + - [[#context-aware-hydra][Context aware hydra]] + - [[#ssh-tunnels][SSH tunnels]] + - [[#minor-utilities][Minor utilities]] + - [[#embark][Embark]] +- [[#language-settings][Language settings]] + - [[#spellcheck][Spellcheck]] +- [[#interface][Interface]] + - [[#general][General]] + - [[#rainbow-mode][Rainbow mode]] + - [[#parentheses][Parentheses]] + - [[#whitespace][Whitespace]] + - [[#notifications][Notifications]] + - [[#undo][Undo]] + - [[#electric-stuff][Electric stuff]] + - [[#writing-setup][Writing Setup]] +- [[#wrapping-up][Wrapping up]] +#+END_QUOTE + +* Overview +** About this document +This files contains all the elisp code normally placed in the .emacs +file. It and the =init.el= file are then symlinked to my =~/.emacs.d/= +directory. Instead of symlinking the files could also be directly +tangled to =~/.emacs.d/=. +#+BEGIN_SRC shell :results silent :tangle tangle/symlink.sh :shebang "#!/bin/bash" :noweb yes +ln -siv $(pwd)/emacs-init.org ~/.emacs.d/ +ln -siv $(pwd)/tangle/init.el ~/.emacs.d/ +ln -siv $(pwd)/tangle/emacs-10-init.el ~/.emacs.d/ +ln -siv $(pwd)/tangle/init-exwm.el ~/.emacs.d/ +ls emacs-*.el.gpg | xargs -I FILE ln -siv $(pwd)/FILE ~/.emacs.d +<<symlinks>> +#+END_SRC + +An often seen setup is to use ~org-babel-load-file~ in =init.el= to +load this =.org= configuration file. Instead I chose to auto-tangle +the =.org= file on every save and load the tangled =.el= file +directly. This saves time on startup as tangling does not occur +everytime and also allows for more flexibility regarding tangling file +locations in this configuration file. Namely I can include the content +of =init.el= in this file without problems. + +To share this configuration publicly, even though it contains private +information, several solutions are possible. To keep everything in one +file, [[elisp:(find-library "org-crypt")][org-crypt]] is a possible solution. Marking the headings with +private information with the tag =:crypt:= and adding the following to +=init.el= works as a basic setup for =org-crypt=. Also make sure to +disable ~buffer-auto-save-file-name~ for the files. +#+BEGIN_SRC emacs-lisp :noweb-ref org-crypt :tangle no +(use-package org-crypt + :config (org-crypt-use-before-save-magic) + :custom + (org-crypt-key "F1EF502F9E81D81381B1679AF973BBEA6994521B")) +#+END_SRC + +#+BEGIN_SRC emacs-lisp :noweb-ref org-custom-no-inheritance-tags :tangle no +"crypt" +#+END_SRC + +I use =.org= configuration files also for my other dotfiles. To ensure +they are tangled upon save I use this function. +#+NAME: tangle-hook +#+BEGIN_SRC emacs-lisp :tangle no +(defun fpi/tangle-dotfiles () + "If the current file is in '~/.dotfiles' tangle all code blocks." + (when (equal (file-name-directory (directory-file-name buffer-file-name)) + (expand-file-name "git/projects/dotfiles/" (getenv "HOME"))) + (org-babel-tangle) + (message "%s tangled" buffer-file-name))) +(defmacro fpi/tangle-async (&optional file) + "Tangle FILE with a separate emacs instance. + +Note that this does not respect any customization of the tangle +process in your init file as it is not loaded. This uses the +emacs-async library." + (interactive) + (let ((file (or file (buffer-file-name)))) + (and file + (not (file-remote-p file)) + `(async-start + (lambda () + (require 'org) + (require 'org-clock) + (org-babel-tangle-file ,file) + (org-notify (format "Tangled %s" ,file)) + 'ignore))))) +#+END_SRC +As I use =org-crypt= all =.org= files need to be decrypted before +tangling, saved without encrypting and encrypted after tangling and +saved again. The latter part is not directly supported by =org=. +~org-babel-post-tangle-hook~ is executed in the created tangled files +and not inside the source =.org= file. Instead I add an advice to +~org-babel-tangle~. +#+NAME: org-crypt-tangle-setup +#+BEGIN_SRC emacs-lisp :tangle no +(defun save-without-hook () + (let ((before-save-hook nil)) + (save-buffer))) + +(setq org-babel-pre-tangle-hook '(org-decrypt-entries save-without-hook)) +;; (setq org-babel-post-tangle-hook '(org-encrypt-entries save-without-hook)) +(advice-add 'org-babel-tangle :after '(lambda (&rest r) + (org-encrypt-entries) + (save-without-hook))) +#+END_SRC + +Using =org-crypt= unfortunately leads to unusable diffs in =git= for +the encrypted parts. So I tend to only use it for configuration files +which I do not want to split into multiple files. The approach of +using a separate =.el.gpg= or =.org.gpg= file has the same problem. +But =git= can be told to decrypt =.gpg= files before creating the diff +using the following settings (see [[https://magit.vc/manual/magit/How-to-show-diffs-for-gpg_002dencrypted-files_003f.html][here]]). +#+begin_src shell +git config --global diff.gpg.textconv "gpg --no-tty --decrypt" +echo "*.gpg filter=gpg diff=gpg" > .gitattributes +#+end_src +A similar behaviour can be achieved using [[https://github.com/AGWA/git-crypt][git-crypt]]. I save private +details regarding my emacs configuration in =.el.gpg= files and +load them in =init.el= using some code like this. +#+begin_src emacs-lisp :tangle no +(mapc (lambda (file) (load file)) + (directory-files default-directory t "^emacs-.*el.gpg$")) +#+end_src + +This is the content of =init.el=. Notice the ~:tangle tangle/init.el~ +header argument in the source code. +#+begin_src emacs-lisp :tangle tangle/init.el +<<straight.el>> + +;; package.el to enable use of list-packages +<<package.el>> + +(setq vc-follow-symlinks t) + +;; For use on Windows via SSH X-Forwarding +;; See https://emacs.stackexchange.com/a/42440/25850 +(setq default-frame-alist + (append default-frame-alist '((inhibit-double-buffering . t)))) +(setq posframe-inhibit-double-buffering t) + +(mapc (lambda (file) (load file)) + (directory-files user-emacs-directory t "^emacs-.*el\\(.gpg\\)\\{0,1\\}")) +#+end_src + +I always wanted to reorganize my old init file with >5000 lines, but +never managed to do it completely. So I decided to start from scratch. +The structure and some of the base content is loosely based on the +[[https://gitlab.com/protesilaos/dotemacs/][config of Protesilaos Stavrou]]. Several functions and definitions are +from other configs as well. They are mentioned in the appropriate +places. + +Notable configs: +- [[https://gitlab.com/protesilaos/dotemacs/][Protesilaos Stavrou]] +- [[http://doc.rix.si/cce/cce.html][Ryan Rix]] +- [[http://doc.norang.ca/org-mode.html][Bernt Hansen]] + +* Base settings +** Meta packages +Packages that don't do anything by themselves, but can be used to help +with other package definition and customization. +*** package.el +=package.el= setup. While I switched to [[id:eef88cd4-f2f5-4e4b-b7bb-75faac36dcb8][straight.el]], I keep =package.el= loaded for now to be able to browse ELPA/MELPA with ~M-x list-packages~. +#+BEGIN_SRC emacs-lisp :noweb-ref package.el :tangle no +(require 'package) +;; (package-initialize) +(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t) +(add-to-list 'package-archives '("org" . "http://orgmode.org/elpa/") nil) +(package-refresh-contents t) +#+END_SRC +*** straight.el +:PROPERTIES: +:ID: eef88cd4-f2f5-4e4b-b7bb-75faac36dcb8 +:END: +[[https://github.com/raxod502/straight.el][straight.el]] is a package manager for emacs, which in contrast to =package.el= keeps track of the current package versions and supports local development on packages. See the [[https://github.com/raxod502/straight.el#comparison-to-other-package-managers][github page]] for a detailed comparison with other package managers. +#+begin_src emacs-lisp :noweb-ref straight.el :tangle no +(defvar bootstrap-version) +(let ((bootstrap-file + (expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory)) + (bootstrap-version 5)) + (unless (file-exists-p bootstrap-file) + (with-current-buffer + (url-retrieve-synchronously + "https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el" + 'silent 'inhibit-cookies) + (goto-char (point-max)) + (eval-print-last-sexp))) + (load bootstrap-file nil 'nomessage)) +#+end_src + +#+BEGIN_SRC emacs-lisp +(setq straight-profiles `((nil . ,(expand-file-name "package-versions.el" "~/git/projects/dotfiles")))) +(setq straight-recipe-overrides + '(nil . ( + <<straight-recipe-overrides>> + ))) +#+END_SRC +**** straight.el documentation excerpts +:PROPERTIES: +:header-args:emacs-lisp: :tangle no +:END: +***** General usage +#+begin_quote +- To restore each package to its canonical state (a clean working + directory with the main branch checked out, and the remotes set + correctly), run ~M-x straight-normalize-package~ or ~M-x + straight-normalize-all~. +- To fetch from each package's configured remote, run ~M-x + straight-fetch-package-and-deps~ or ~M-x straight-fetch-all~; to + also fetch from the upstream for forked packages, supply a prefix + argument. +- To merge changes from each package's configured remote, run ~M-x + straight-merge-package-and-deps~ or ~M-x straight-merge-all~; to + also merge from the upstream for forked packages, supply a prefix + argument. +- To push all local changes to each package's configured remote, run + ~M-x straight-push-package~ or ~M-x straight-push-all~. +#+end_quote +***** Freezing package versions +#+begin_quote +To save the currently checked out revisions of all of your packages, +run ~M-x straight-freeze-versions~. The resulting file +(~~/.emacs.d/straight/versions/default.el~), together with your +init-file, perfectly define your package configuration. Keep your +version lockfile checked into version control; when you install your +Emacs configuration on another machine, the versions of packages +specified in your lockfile will automatically be checked out after the +packages are installed. You can manually revert all packages to the +revisions specified in the lockfile by running ~M-x +straight-thaw-versions~. +#+end_quote +***** =use-package= integration +#+begin_src emacs-lisp +(use-package el-patch + :straight (:host github :repo "raxod502/el-patch" + :branch "develop")) +(use-package tex-site + :straight (auctex :host github + :repo "emacsmirror/auctex" + :files (:defaults (:exclude "*.el.in")))) +#+end_src +*** Use-package +#+begin_src emacs-lisp +(straight-use-package 'use-package) +#+end_src +*** Hydra +#+begin_src emacs-lisp +(use-package hydra + :straight t) +#+end_src +This package allows hydra definitions in use-package. +#+begin_src emacs-lisp +(use-package use-package-hydra + :straight t) +#+end_src +*** which-key +In Emacs you can press =?= or =C-h= after starting a key combination +to get a list of available commands. =which-key= shows these in a +small popup, which I think is more handy. +#+begin_src emacs-lisp +(use-package which-key + :straight t + :custom + (which-key-idle-delay 0.4) + (which-key-lighter "") + :config (which-key-mode 1)) +#+end_src +*** Try +Sometimes I stumble over a package and want to try it out without +commiting to it and installing it fully – possibly forgetting to +remove it. =Try= installs packages temporarily for this emacs session +only. +#+begin_src emacs-lisp +(use-package try + :straight t) +#+end_src +** GUI Interface +Disable most of the user interface. +#+BEGIN_SRC emacs-lisp +(use-package emacs + :custom + <<emacs-custom>> + :config + (tooltip-mode -1) + (tool-bar-mode -1) + (menu-bar-mode -1) + (scroll-bar-mode -1) + ) +#+END_SRC + +Audible bell is useless when the sound is turned off and annoying when sound is on. Instead use visible bell. +#+begin_src emacs-lisp :tangle no :noweb-ref emacs-custom +(visible-bell t) +#+end_src + +In /awesomewm/ and other tiling window managers the emacs window +leaves a gap at the bottom. This removes it. +#+BEGIN_SRC emacs-lisp +(setq frame-resize-pixelwise t) +#+END_SRC +*** Mode Line & Header Line +=header-info= is an easy way to move part of the mode line information to the header line instead. + +#+begin_src emacs-lisp +(use-package header-info + :straight (:host github :repo "fpiper/header-info" + :branch "master")) +#+end_src +**** Remove mode line clutter +#+begin_src emacs-lisp +(use-package delight + :straight t + :after use-package) +#+end_src +If removing mode symbols with =delight= is not enough, the mode line +can also be completely removed by setting ~mode-line-format~ to ~nil~. +=hide-mode-line= is a small minor mode that can toggle the mode-line +on and off. I added ~redraw-display~, because i had problems with the +mode-line not being redisplayed, when turning the mode off even though +it calls ~force-mode-line-update~. +#+begin_src emacs-lisp +(use-package hide-mode-line + :straight t + :hook + (hide-mode-line-mode . redraw-display) + (help-mode . hide-mode-line-mode)) +(global-set-key (kbd "C-c m") 'hide-mode-line-mode) +#+end_src +** Devices +To support different settings on different devices storing some device information seems useful. +#+begin_src emacs-lisp +(setq fpi/current-device (system-name)) +(setq fpi/devices + '(("peter" + (:type desktop + :os win10)) + ("pan" + (:type desktop + :wm exwm)) + ("xcarb" + (:type mobile)) + ("DESKTOP-PM1PPEC" + (:type mobile + :os win10)) + )) +(defun fpi/device-info (device prop) + "Return property PROP of DEVICE as stored in `fpi/devices'." + (let ((info (cadr (assoc device fpi/devices)))) + (plist-get info prop))) +(defun fpi/current-device-info (prop) + "Return property PROP of current device." + (let ((info (cadr (assoc fpi/current-device fpi/devices)))) + (plist-get info prop))) +#+end_src +Now we can easily extract info on the current device. +#+begin_src emacs-lisp :tangle no :exports both :results replace +(fpi/device-info "pan" :type) +#+end_src + +#+RESULTS: +: desktop +** Server +#+begin_src emacs-lisp :tangle no +(use-package server + :config + (unless (server-running-p) (server-start))) +#+end_src +** Exwm +The previous sections cover all basic settings which may be useful when loading =exwm=. +My =exwm= configurations are in [[file:init-exwm.org][init-exwm.org]] and we can load the tangled version here. In the future I may convert it into a standalone package. +#+begin_src emacs-lisp +(when (and (equal (getenv "DESKTOP_SESSION") "exwm") + (eq window-system 'x)) + (load (concat user-emacs-directory "init-exwm.el")) +#+end_src +Also enable =exwm=. This does nothing if =emacs= is not started as window manager. +#+begin_src emacs-lisp + (exwm-enable)) +#+end_src +** Font +I am still not quite sure on my choice of font. + +=fpi/set-font= is a safe way to choose a font based on +availability. When starting with =emacs --daemon= it does not work as +=(font-family-list)= won't return anything. +#+begin_src emacs-lisp :tangle no +(use-package emacs + :config + (defun fpi/set-font () + (interactive) + (cond + ((member "Hack" (font-family-list)e) + (add-to-list 'default-frame-alist '(font . "Hack-12"))) + ((member "Source Code Pro" (font-family-list)) + (add-to-list 'default-frame-alist '(font . "Source Code Pro-12"))))) + (add-to-list 'default-frame-alist '(font . "Hack-12")) + ;; :hook (after-init . fpi/set-font) + ) +#+end_src + +Instead of the above code I set the font directly using +=set-face-attribute=. This is overwritten by my theme settings. +#+begin_src emacs-lisp +(set-face-attribute 'default nil :font "Hack-11") +#+end_src + +#+begin_src emacs-lisp +(use-package emacs + :commands (prot/font-set-face-attribute + prot/font-set-fonts + prot/font-set-font-size-family + prot/font-fonts-dwim) + :config + (setq x-underline-at-descent-line t) + (setq underline-minimum-offset 1) + + (defconst prot/font-fontconfig-params + "embeddedbitmap=false:autohint=false:hintstyle=hintslight" + "Additional parameters for the given font family. +These are specific to the fontconfig backend for GNU/Linux systems.") + + (defvar prot/font-set-fonts-hook nil + "Hook that is called after setting fonts. +See, for example, `prot/font-set-fonts'.") + + ;; The idea with this association list is to use font combinations + ;; that are suitable to the given point size and intended function. + ;; Basically, I have three modes: my laptop's small screen, my laptop + ;; attached to a larger external monitor in a desktop setup (my normal + ;; case), and when I do presentations (i.e. my videos on Emacs). + ;; + ;; I find that at smaller sizes the open and wide proportions of + ;; Hack+FiraGO combined with their more intense typographic colour + ;; work best, while the more compact Iosevka+Source Sans Pro are + ;; better at larger point sizes. The "desktop" combo is ideal for use + ;; on a larger monitor at a regular point size. The latter is what I + ;; typically use to write prose or code. + ;; + ;; Note that the "Hack" typeface mentioned here is my patched version + ;; of it, which uses some alternative glyphs, is built on top of the + ;; latest dev branch, and is meant to improve both the Roman and + ;; Italic variants (alt glyphs are part of the Hack project): + ;; https://gitlab.com/protesilaos/hackfontmod + (defconst prot/font-sizes-families-alist + '(("laptop" . (10.5 "Hack" "Source Sans Pro" 1)) + ("desktop" . (13 "Hack" "Alegreya" 4)) + ("presentation" . (19 "Iosevka SS08" "Source Sans Pro" 1))) + "Alist of desired point sizes and their typefaces. +Each association consists of a display type mapped to a point +size, followed by monospaced and proportionately-spaced font +names, and a difference in desired size between the latter two to +account for their innate differences in proportions (this number +represents pixels and is found empirically). + +The monospaced typeface is meant to be applied to the `default' +and `fixed-pitch' faces. The proportionately-space font is +intended for the `variable-pitch' face.") + + (defun prot/font-set-face-attribute (face family size &optional params) + "Set FACE font to FAMILY at SIZE with optional PARAMS." + (let ((params (if params + params + prot/font-fontconfig-params))) + (set-face-attribute + `,face nil :font + (format "%s-%s:%s" family (number-to-string size) params)))) + + + + + + (defun prot/font-set-fonts (&optional points font-mono font-var) + "Set default font size using presets. + +POINTS is the font's point size, represented as either '10' or +'10.5'. FONT-MONO should be a monospaced typeface, due to the +alignment requirements of the `fixed-pitch' face. FONT-VAR could +be a proportionately-spaced typeface or even a monospaced one, +since the `variable-pitch' it applies to is not supposed to be +spacing-sensitive. Both families must be represented as a string +holding the family's name." + (interactive) + (let* ((data prot/font-sizes-families-alist) + (displays (mapcar #'car data)) + (choice (if points + points + (completing-read "Pick display size: " displays nil t))) + (size (if points + points + (nth 1 (assoc `,choice data)))) + (mono (if font-mono + font-mono + (if (member choice displays) + (nth 2 (assoc `,choice data)) + nil))) + (var (if font-var + font-var + (if (member choice displays) + (nth 3 (assoc `,choice data)) + nil))) + (adjust (nth 4 (assoc `,choice data)))) + (when window-system + (dolist (face '(default fixed-pitch)) + (prot/font-set-face-attribute `,face mono size)) + (prot/font-set-face-attribute 'variable-pitch var (+ size adjust)))) + (run-hooks 'prot/font-switch-fonts-hook)) + + (defvar prot/font-monospaced-fonts-list + '("Hack" "Iosevka SS08" "Iosevka Slab" "Source Code Pro" + "Ubuntu Mono" "Fantasque Sans Mono" "DejaVu Sans Mono" + "Fira Code" "Victor Mono" "Roboto Mono") + "List of typefaces for coding. +See `prot/font-set-font-size-family' for how this is used.") + + (defun prot/font-set-font-size-family () + "Set point size and main typeface. +This command is intended for testing various font families at +some common point sizes. + +See `prot/font-set-fonts' for the function I would normally use +or `prot/font-fonts-dwim' which just wraps this one with that." + (interactive) + (let* ((fonts prot/font-monospaced-fonts-list) + (font (completing-read "Select main font: " fonts nil t)) + (nums (list 13 14 15 16)) + (sizes (mapcar 'number-to-string nums)) + (size (completing-read "Select or insert number: " sizes nil)) + (var (face-attribute 'variable-pitch :family))) + (dolist (face '(default fixed-pitch)) + (prot/font-set-face-attribute face font (string-to-number size))) + (prot/font-set-face-attribute 'variable-pitch var (string-to-number size)) + (run-hooks 'prot/font-switch-fonts-hook))) + + (defun prot/font-fonts-dwim (&optional arg) + "Set fonts interactively. +This is just a wrapper around `prot/font-set-fonts' and +`prot/font-set-font-size-family', whose sole purpose is to +economise on dedicated key bindings." + (interactive "P") + (if arg + (prot/font-set-font-size-family) + (prot/font-set-fonts))) + + (defvar prot/font-fonts-line-spacing-alist + '(("Iosevka SS08" . 1) + ("Iosevka Slab" . 1) + ("Source Code Pro" . 1) + ("Ubuntu Mono" . 2)) + "Font families in need of extra `line-spacing'. +See `prot/font-line-spacing' for how this is used.") + + (defvar prot/font-fonts-bold-weight-alist + '(("Source Code Pro" . semibold)) + "Font families in need of a variegated weight for `bold'. +See `prot/font-bold-face' for how this is used.") + + (defmacro prot/font-adjustment (fn doc alist cond1 cond2) + "Macro for functions that employ `prot/font-switch-fonts-hook'. +NAME is the name of the resulting function. DOC is its +docstring. ALIST is an assosiation list of cons cells. COND1 +and COND2 is the body of an `if' statement's 'if' and 'then' part +respectively." + `(defun ,fn () + ,doc + (let* ((data ,alist) + (fonts (mapcar #'car data)) + ;; REVIEW This should be adjusted to account for the + ;; possibility of a distinct font family for the `bold' + ;; face. + (font (face-attribute 'default :family)) + (x (cdr (assoc font data)))) + (if (member font fonts) + ,cond1 + ,cond2)))) + + (prot/font-adjustment + prot/font-line-spacing + "Determine desirable `line-spacing', based on font family." + prot/font-fonts-line-spacing-alist + (setq-default line-spacing `,x) + (setq-default line-spacing nil)) + + ;; XXX This will not work with every theme, but only those that + ;; inherit the `bold' face instead of specifying a weight property. + ;; The intent is to configure this once and have it propagate wherever + ;; a heavier weight is displayed. My Modus themes handle this + ;; properly. + (prot/font-adjustment + prot/font-bold-face + "Determine weight for the `bold' face, based on font family." + prot/font-fonts-bold-weight-alist + (set-face-attribute 'bold nil :weight `,x) + (set-face-attribute 'bold nil :weight 'bold)) + + (defun prot/font-fonts-per-monitor () + "Use font settings based on screen size. +Meant to be used at some early initialisation stage, such as with +`after-init-hook'." + (let* ((display (if (<= (display-pixel-width) 1366) + "laptop" + "desktop")) + (data prot/font-sizes-families-alist) + (size (cadr (assoc `,display data))) + (mono (nth 2 (assoc `,display data))) + (var (nth 3 (assoc `,display data))) + (adjust (nth 4 (assoc `,display data)))) + (dolist (face '(default fixed-pitch)) + (prot/font-set-face-attribute face mono size)) + (prot/font-set-face-attribute 'variable-pitch var (+ size adjust)) + (run-hooks 'prot/font-switch-fonts-hook))) + + :hook ((after-init-hook . prot/font-fonts-per-monitor) + (prot/font-set-fonts-hook . prot/font-line-spacing) + (prot/font-set-fonts-hook . prot/font-bold-face)) + ;; Awkward key because I do not need it very often. Maybe once a day. + ;; The "C-c f" is used elsewhere. + :bind ("C-c F" . prot/font-fonts-dwim)) +#+end_src +*** Emoji +For undefined characters in the default font, we can set a fallback font using [[info:emacs#Fontsets][fontsets]]. + +Here we set it to use the google icons as fallback. +#+begin_src emacs-lisp +(set-fontset-font "fontset-default" 'unicode "Noto Color Emoji") +#+end_src +Alternatively we could use =OpenMoji= or other icon sets. +#+begin_src emacs-lisp :tangle no +(set-fontset-font "fontset-default" 'unicode "OpenMoji") +#+end_src +** Theme & Faces +=hc-zenburn= is the theme I chose for a long time. Lately I started to +appreciate light themes more. [[https://gitlab.com/protesilaos/modus-themes][modus-operandi]] is an interesting light +theme promising high color contrast. I ended up using the +=spacemacs-light= and =spacemacs-dark= themes. + +This is written here for clarity, but only executed at the end of my +init files, after some variables which depend on the current theme are +defined, for example ~pdf-view-midnight-colors~. +#+NAME: themes +#+begin_src emacs-lisp :tangle no +<<theme-functions>> +(defcustom fpi/light-theme-list '(spacemacs-light spacemacs-light-customizations) + "List of themes to activate when using a light theme.") +(defcustom fpi/dark-theme-list '(spacemacs-dark spacemacs-dark-customizations) + "List of themes to activate when using a dark theme.") +(defcustom fpi/current-theme 'light + "Currently activated theme variation.") + +(fpi/load-themes) +#+end_src + +Functions to load themes based on the ~fpi/current-theme~ setting and to toggle the current theme between light and dark. +#+begin_src emacs-lisp :noweb-ref theme-functions :tangle no +(defun fpi/load-themes (&optional theme-variation) + "Load themes based on the value of `fpi/current-theme'. + +Optionally provide THEME-VARIATION to override +`fpi/current-theme'. Loaded themes are based on the value +of `(format \"fpi/%s-theme-list\" fpi/current-theme)'" + (interactive) + (mapc 'disable-theme custom-enabled-themes);; disable all themes + (let* ((theme-variation (or theme-variation fpi/current-theme)) + (themes (eval (intern (format "fpi/%s-theme-list" theme-variation))))) + (mapc (lambda (theme) (load-theme theme t)) themes))) +(defun fpi/toggle-theme () + "Toggle between light and dark theme." + (interactive) + (if (eq fpi/current-theme 'light) + (progn + (customize-save-variable 'fpi/current-theme 'dark) + (fpi/load-themes)) + (customize-save-variable 'fpi/current-theme 'light) + (fpi/load-themes))) +#+end_src +#+begin_src emacs-lisp :tangle no :noweb-ref fpi-bindings +(define-key fpi/toggle-map "dt" #'fpi/toggle-theme) +#+end_src +*** Getting themes +#+begin_src emacs-lisp +(use-package spacemacs-light-theme + :no-require t + :straight (spacemacs-theme)) +(use-package spacemacs-dark-theme + :no-require t + :straight (spacemacs-theme)) +#+end_src + +#+begin_src emacs-lisp :tangle no +(use-package modus-operandi-theme + :straight t) +(use-package modus-vivendi-theme + :straight t) +#+end_src +*** Theme customization +In this section is code to produce a custom theme out of a list of predefined colors and custom face specs. + +First a function to replace colors in the face specs. +#+begin_src emacs-lisp +(defun prep-custom-theme-set-faces (colors faces-alist) + (defmacro get-proper-faces () + `(let* (,@colors) + (backquote ,faces-alist))) + (get-proper-faces)) +#+end_src + +This call now creates a custom theme based on the settings in the sections +[[id:82021d54-89d6-4712-8e5a-df2fc6177c96][Colors]] and [[id:a3b74d3b-675e-426d-b675-e70dcfd3d2b6][Faces]]. These are my customizations to the spacemacs theme. Make sure to manually run these customization blocks after changing a face, as only the result blocks are tangled! +#+begin_src emacs-lisp :tangle no :results code replace :wrap "src emacs-lisp :tangle tangle/spacemacs-dark-customizations-theme.el" :exports both +`(progn + (deftheme spacemacs-dark-customizations + "My customizations to spacemacs-dark (Created 2020-06-27)") + (custom-theme-set-faces + 'spacemacs-dark-customizations + ,@(prep-custom-theme-set-faces + (quote + <<colors>>) + <<faces-spacemacs-dark>>)) + (provide-theme 'spacemacs-dark-customizations)) +#+end_src + +#+RESULTS: +#+begin_src emacs-lisp :tangle tangle/spacemacs-dark-customizations-theme.el +(progn + (deftheme spacemacs-dark-customizations "My customizations to spacemacs-dark (Created 2020-06-27)") + (custom-theme-set-faces 'spacemacs-dark-customizations + '(default + ((t + (:family "Hack" :background "#1c1e1f" :foreground "#fbf8ef")))) + '(variable-pitch + ((t + (:family "Source Sans Pro")))) + '(header-line + ((t + (:background nil :inherit nil)))) + '(show-paren-match + ((t + (:background "#f92672" :foreground "#1c1e1f")))) + '(magit-section-heading + ((t + (:foreground "#f92672")))) + '(magit-header-line + ((t + (:background nil :foreground "#1c1e1f" :box nil)))) + '(magit-diff-hunk-heading + ((t + (:background "#525254" :foreground "#bbb")))) + '(magit-diff-hunk-heading-highlight + ((t + (:background "#525254" :foreground "#ffffff")))) + '(tooltip + ((t + (:foreground "#bbb" :background "#1c1c1c")))) + '(mode-line + ((t + (:background "#1c1c1c")))) + '(mode-line-inactive + ((t nil))) + '(powerline-active1 + ((t nil))) + '(powerline-active2 + ((t nil))) + '(powerline-inactive1 + ((t nil))) + '(powerline-inactive2 + ((t nil))) + '(highlight + ((t + (:background "#39393d" :foreground "#ffffff")))) + '(hl-line + ((t + (:background "#2d2e2e")))) + '(org-document-title + ((t + (:inherit variable-pitch :height 1.3 :weight normal :foreground "#bbb")))) + '(org-document-info + ((t + (:foreground "#bbb" :slant italic)))) + '(org-archived + ((t nil))) + '(org-level-1 + ((t + (:inherit variable-pitch :height 1.3 :weight bold :foreground "#f92672" :background "#1c1e1f")))) + '(org-level-2 + ((t + (:inherit variable-pitch :weight bold :height 1.2 :foreground "#bbb" :background "#1c1e1f")))) + '(org-level-3 + ((t + (:inherit variable-pitch :weight bold :height 1.1 :foreground "#8FA1B3" :background "#1c1e1f")))) + '(org-level-4 + ((t + (:inherit variable-pitch :weight bold :height 1.1 :foreground "#8FA1B3" :background "#1c1e1f")))) + '(org-level-5 + ((t + (:inherit variable-pitch :weight bold :height 1.1 :foreground "#8FA1B3" :background "#1c1e1f")))) + '(org-level-6 + ((t + (:inherit variable-pitch :weight bold :height 1.1 :foreground "#8FA1B3" :background "#1c1e1f")))) + '(org-level-7 + ((t + (:inherit variable-pitch :weight bold :height 1.1 :foreground "#8FA1B3" :background "#1c1e1f")))) + '(org-level-8 + ((t + (:inherit variable-pitch :weight bold :height 1.1 :foreground "#8FA1B3" :background "#1c1e1f")))) + '(org-headline-done + (nil)) + '(org-quote + ((t + (:background "#1c1e1f" :family "Hack")))) + '(org-block + ((t + (:background "#1c1e1f" :family "Hack")))) + '(org-block-begin-line + ((t + (:background "#1c1e1f")))) + '(org-block-end-line + ((t + (:background "#1c1e1f")))) + '(org-meta-line + ((t + (:foreground "#525254")))) + '(org-document-info-keyword + ((t + (:foreground "#525254")))) + '(org-link + ((t + (:underline nil :weight normal :foreground "#8FA1B3")))) + '(org-special-keyword + ((t + (:height 0.9 :foreground "#525254")))) + '(org-property-value + ((t + (:height 0.9 :foreground "#525254")))) + '(org-drawer + ((t + (:height 0.9 :foreground "#525254")))) + '(org-todo + ((t + (:foreground "#fd971f" :background "#1c1e1f")))) + '(org-done + ((t + (:inherit variable-pitch :foreground "#008b8b" :background "#1c1e1f")))) + '(org-agenda-current-time + ((t + (:foreground "#8FA1B3")))) + '(org-hide + ((t nil))) + '(org-indent + ((t + (:inherit org-hide)))) + '(org-time-grid + ((t + (:foreground "#525254")))) + '(org-warning + ((t + (:foreground "#fd971f")))) + '(org-date + ((t nil))) + '(org-agenda-structure + ((t + (:height 1.3 :foreground "#727280" :weight normal :inherit variable-pitch)))) + '(org-agenda-date + ((t + (:foreground "#727280")))) + '(org-agenda-date-today + ((t + (:height 1.5 :foreground "#f92672")))) + '(org-agenda-date-weekend + ((t + (:inherit org-agenda-date)))) + '(org-scheduled + ((t + (:foreground "#bbb")))) + '(org-upcoming-deadline + ((t + (:foreground "#f92672")))) + '(org-scheduled-today + ((t + (:foreground "#ffffff")))) + '(org-scheduled-previously + ((t + (:foreground "#8FA1B3")))) + '(org-agenda-done + ((t + (:inherit nil :foreground "#727280")))) + '(org-ellipsis + ((t + (:underline nil :foreground "#525254")))) + '(org-tag + ((t + (:foreground "#727280")))) + '(org-table + ((t + (:background nil :family "Hack")))) + '(org-code + ((t + (:inherit font-lock-builtin-face)))) + '(font-latex-sectioning-0-face + ((t + (:foreground "#66d9ef" :height 1.2)))) + '(font-latex-sectioning-1-face + ((t + (:foreground "#66d9ef" :height 1.1)))) + '(font-latex-sectioning-2-face + ((t + (:foreground "#66d9ef" :height 1.1)))) + '(font-latex-sectioning-3-face + ((t + (:foreground "#66d9ef" :height 1.0)))) + '(font-latex-sectioning-4-face + ((t + (:foreground "#66d9ef" :height 1.0)))) + '(font-latex-sectioning-5-face + ((t + (:foreground "#66d9ef" :height 1.0)))) + '(font-latex-verbatim-face + ((t + (:foreground "#fd971f")))) + '(spacemacs-normal-face + ((t + (:background "#1c1e1f" :foreground "#ffffff")))) + '(spacemacs-evilified-face + ((t + (:background "#1c1e1f" :foreground "#ffffff")))) + '(spacemacs-lisp-face + ((t + (:background "#1c1e1f" :foreground "#ffffff")))) + '(spacemacs-emacs-face + ((t + (:background "#1c1e1f" :foreground "#ffffff")))) + '(spacemacs-motion-face + ((t + (:background "#1c1e1f" :foreground "#ffffff")))) + '(spacemacs-visual-face + ((t + (:background "#1c1e1f" :foreground "#ffffff")))) + '(spacemacs-hybrid-face + ((t + (:background "#1c1e1f" :foreground "#ffffff")))) + '(bm-persistent-face + ((t + (:background "#008b8b" :foreground "#ffffff")))) + '(helm-selection + ((t + (:background "#39393d")))) + '(helm-match + ((t + (:foreground "#f92672")))) + '(cfw:face-title + ((t + (:height 2.0 :inherit variable-pitch :weight bold :foreground "#727280")))) + '(cfw:face-holiday + ((t + (:foreground "#fd971f")))) + '(cfw:face-saturday + ((t + (:foreground "#727280" :weight bold)))) + '(cfw:face-sunday + ((t + (:foreground "#727280")))) + '(cfw:face-periods + ((t + (:foreground "#008b8b")))) + '(cfw:face-annotation + ((t + (:foreground "#727280")))) + '(cfw:face-select + ((t + (:background "#39393d")))) + '(cfw:face-toolbar-button-off + ((t + (:foreground "#727280")))) + '(cfw:face-toolbar-button-on + ((t + (:foreground "#66d9ef" :weight bold)))) + '(cfw:face-day-title + ((t + (:foreground "#727280")))) + '(cfw:face-default-content + ((t + (:foreground "#008b8b")))) + '(cfw:face-disable + ((t + (:foreground "#727280")))) + '(cfw:face-today + ((t + (:background "#39393d" :weight bold)))) + '(cfw:face-toolbar + ((t + (:inherit default)))) + '(cfw:face-today-title + ((t + (:background "#f92672" :foreground "#ffffff")))) + '(cfw:face-grid + ((t + (:foreground "#525254")))) + '(cfw:face-header + ((t + (:foreground "#f92672" :weight bold)))) + '(cfw:face-default-day + ((t + (:foreground "#ffffff")))) + '(dired-subtree-depth-1-face + ((t + (:background nil)))) + '(dired-subtree-depth-2-face + ((t + (:background nil)))) + '(dired-subtree-depth-3-face + ((t + (:background nil)))) + '(dired-subtree-depth-4-face + ((t + (:background nil)))) + '(dired-subtree-depth-5-face + ((t + (:background nil)))) + '(dired-subtree-depth-6-face + ((t + (:background nil)))) + '(nlinum-current-line + ((t + (:foreground "#fd971f")))) + '(vertical-border + ((t + (:background "#39393d" :foreground "#39393d")))) + '(which-key-command-description-face + ((t + (:foreground "#66d9ef")))) + '(flycheck-error + ((t + (:background nil)))) + '(flycheck-warning + ((t + (:background nil)))) + '(font-lock-string-face + ((t + (:foreground "#b6e63e")))) + '(font-lock-comment-face + ((t + (:foreground "#727280" :slant italic)))) + '(elfeed-search-unread-title-face + ((t + (:weight bold)))) + '(helm-ff-symlink + ((t + (:foreground "#8FA1B3")))) + '(region + ((t + (:background "#39393d"))))) + (provide-theme 'spacemacs-dark-customizations)) +#+end_src + +#+begin_src emacs-lisp :tangle no :results code replace :wrap "src emacs-lisp :tangle tangle/spacemacs-light-customizations-theme.el" :exports both +`(progn + (deftheme spacemacs-light-customizations + "My customizations to spacemacs-light (Created 2020-06-27)") + (custom-theme-set-faces + 'spacemacs-light-customizations + ,@(prep-custom-theme-set-faces + (quote + <<colors>>) + <<faces-spacemacs-light>>)) + (provide-theme 'spacemacs-light-customizations)) +#+end_src + +#+RESULTS: +#+begin_src emacs-lisp :tangle tangle/spacemacs-light-customizations-theme.el +(progn + (deftheme spacemacs-light-customizations "My customizations to spacemacs-light (Created 2020-06-27)") + (custom-theme-set-faces 'spacemacs-light-customizations + '(header-line + ((t + (:background nil :inherit nil)))) + '(show-paren-match + ((t nil))) + '(magit-section-heading + ((t nil))) + '(magit-header-line + ((t + (:background nil :foreground "#fbf8ef" :box nil)))) + '(magit-diff-hunk-heading + ((t nil))) + '(magit-diff-hunk-heading-highlight + ((t nil))) + '(tooltip + ((t nil))) + '(mode-line + ((t + (:background "#fbf8ef" :box nil)))) + '(mode-line-inactive + ((t + (:box nil)))) + '(powerline-active1 + ((t + (:background "#fbf8ef")))) + '(powerline-active2 + ((t + (:background "#fbf8ef")))) + '(powerline-inactive1 + ((t + (:background "#fbf8ef")))) + '(powerline-inactive2 + ((t + (:background "#fbf8ef")))) + '(highlight + ((t + (:background "#efeae9")))) + '(hl-line + ((t nil))) + '(org-document-title + ((t + (:inherit nil :height 1.8 :foreground "#1c1e1f" :underline nil)))) + '(org-document-info + ((t + (:height 1.2 :slant italic)))) + '(org-archived + ((t + (:inherit shadow :height 0.6)))) + '(org-level-1 + ((t + (:height 1.6 :weight normal :slant normal :foreground "#1c1e1f")))) + '(org-level-2 + ((t + (:weight normal :height 1.3 :slant italic :foreground "#1c1e1f")))) + '(org-level-3 + ((t + (:weight normal :slant italic :height 1.2 :foreground "#1c1e1f")))) + '(org-level-4 + ((t + (:weight normal :slant italic :height 1.1 :foreground "#1c1e1f")))) + '(org-level-5 + ((t nil))) + '(org-level-6 + ((t nil))) + '(org-level-7 + ((t nil))) + '(org-level-8 + ((t nil))) + '(org-quote + ((t nil))) + '(org-block + ((t + (:background nil :height 0.9 :foreground "#1c1e1f" :family "Hack")))) + '(org-block-begin-line + ((t + (:background nil :height 0.8 :family "Hack" :foreground "#8FA1B3")))) + '(org-block-end-line + ((t + (:background nil :height 0.8 :family "Hack" :foreground "#8FA1B3")))) + '(org-meta-line + ((t + (:height 0.8 :foreground "#bbb")))) + '(org-document-info-keyword + ((t + (:height 0.8 :foreground "#bbb")))) + '(org-link + ((t + (:foreground "#fd971f")))) + '(org-special-keyword + ((t + (:family "Hack" :height 0.8)))) + '(org-property-value + ((t + (:family "Hack" :height 0.8)))) + '(org-drawer + ((t + (:family "Hack" :height 0.8)))) + '(org-todo + ((t nil))) + '(org-done + ((t nil))) + '(org-agenda-current-time + ((t nil))) + '(org-hide + ((t + (:foreground "#fbf8ef")))) + '(org-indent + ((t + (:inherit + (org-hide fixed-pitch))))) + '(org-time-grid + ((t nil))) + '(org-warning + ((t nil))) + '(org-date + ((t + (:family "Hack" :height 0.8)))) + '(org-agenda-structure + ((t nil))) + '(org-agenda-date + ((t + (:foreground "#727280")))) + '(org-agenda-date-today + ((t + (:height 1.2)))) + '(org-agenda-date-weekend + ((t nil))) + '(org-scheduled + ((t + (:foreground "#4f774f")))) + '(org-upcoming-deadline + ((t nil))) + '(org-scheduled-today + ((t + (:foreground "#1c661c")))) + '(org-scheduled-previously + ((t + (:foreground "#002900")))) + '(org-agenda-done + ((t + (:foreground "#727280")))) + '(org-ellipsis + ((t + (:underline nil :foreground "#525254")))) + '(org-tag + ((t + (:foreground "#727280")))) + '(org-table + ((t + (:inherit fixed-pitch :height 0.9 :background "#fbf8ef")))) + '(org-code + ((t + (:inherit fixed-pitch :foreground "#525254" :height 0.9)))) + '(font-latex-sectioning-0-face + ((t nil))) + '(font-latex-sectioning-1-face + ((t nil))) + '(font-latex-sectioning-2-face + ((t nil))) + '(font-latex-sectioning-3-face + ((t nil))) + '(font-latex-sectioning-4-face + ((t nil))) + '(font-latex-sectioning-5-face + ((t nil))) + '(font-latex-verbatim-face + ((t nil))) + '(spacemacs-normal-face + ((t nil))) + '(spacemacs-evilified-face + ((t nil))) + '(spacemacs-lisp-face + ((t nil))) + '(spacemacs-emacs-face + ((t nil))) + '(spacemacs-motion-face + ((t nil))) + '(spacemacs-visual-face + ((t nil))) + '(spacemacs-hybrid-face + ((t nil))) + '(bm-persistent-face + ((t nil))) + '(helm-selection + ((t nil))) + '(helm-match + ((t nil))) + '(cfw:face-title + ((t nil))) + '(cfw:face-holiday + ((t nil))) + '(cfw:face-saturday + ((t nil))) + '(cfw:face-sunday + ((t nil))) + '(cfw:face-periods + ((t nil))) + '(cfw:face-annotation + ((t nil))) + '(cfw:face-select + ((t nil))) + '(cfw:face-toolbar-button-off + ((t nil))) + '(cfw:face-toolbar-button-on + ((t nil))) + '(cfw:face-day-title + ((t nil))) + '(cfw:face-default-content + ((t nil))) + '(cfw:face-disable + ((t nil))) + '(cfw:face-today + ((t nil))) + '(cfw:face-toolbar + ((t nil))) + '(cfw:face-today-title + ((t nil))) + '(cfw:face-grid + ((t nil))) + '(cfw:face-header + ((t nil))) + '(cfw:face-default-day + ((t nil))) + '(dired-subtree-depth-1-face + ((t + (:background nil)))) + '(dired-subtree-depth-2-face + ((t + (:background nil)))) + '(dired-subtree-depth-3-face + ((t + (:background nil)))) + '(dired-subtree-depth-4-face + ((t + (:background nil)))) + '(dired-subtree-depth-5-face + ((t + (:background nil)))) + '(dired-subtree-depth-6-face + ((t + (:background nil)))) + '(nlinum-current-line + ((t + (:foreground "#1c1e1f")))) + '(vertical-border + ((t nil))) + '(which-key-command-description-face + ((t nil))) + '(flycheck-error + ((t nil))) + '(flycheck-warning + ((t nil))) + '(font-lock-string-face + ((t nil))) + '(font-lock-comment-face + ((t + (:background nil :foreground "#727280" :slant italic)))) + '(elfeed-search-unread-title-face + ((t + (:weight bold)))) + '(helm-ff-symlink + ((t nil))) + '(region + ((t nil)))) + (provide-theme 'spacemacs-light-customizations)) +#+end_src + +Now we just have to link the tangled themes to the ~load-path~ +#+BEGIN_SRC shell :results silent :noweb-ref symlinks :tangle no +ln -siv $(pwd)/tangle/spacemacs-dark-customizations-theme.el ~/.emacs.d/ +ln -siv $(pwd)/tangle/spacemacs-light-customizations-theme.el ~/.emacs.d/ +#+END_SRC +**** Colors +:PROPERTIES: +:ID: 82021d54-89d6-4712-8e5a-df2fc6177c96 +:END: +#+begin_src emacs-lisp :noweb-ref colors :tangle no +((bg-white "#fbf8ef") + (bg-light "#222425") + (bg-dark "#1c1e1f") + (bg-darker "#1c1c1c") + (fg-white "#ffffff") + (shade-white "#efeae9") + (fg-light "#655370") + (dark-cyan "#008b8b") + (light-green "#4f774f") ;;#3f773f + (dark-green "#1c661c") + (dark-green2 "#002900") + (region-dark "#2d2e2e") + (region "#39393d") + (slate "#8FA1B3") + (keyword "#f92672") + (comment "#525254") + (builtin "#fd971f") + (purple "#9c91e4") + (doc "#727280") + (type "#66d9ef") + (string "#b6e63e") + (gray-dark "#999") + (gray "#bbb") + (sans-font "Source Sans Pro") + (serif-font "Merriweather") + (et-font "EtBookOt") + (sans-mono-font "Hack") + ;; (serif-mono-font "Verily Serif Mono") + (serif-mono-font "cmu typewriter text") + ) +#+end_src +**** Faces +:PROPERTIES: +:ID: a3b74d3b-675e-426d-b675-e70dcfd3d2b6 +:END: +#+begin_src emacs-lisp :noweb-ref faces-spacemacs-light :tangle no +;; light +'( + ;; '(default ((t (:family ,sans-mono-font :background ,bg-white :foreground ,bg-dark + ;; ;; :height 75 + ;; )))) + ;; '(variable-pitch ((t (:family ,et-font :background nil :foreground ,bg-dark :height 1.2)))) + '(header-line ((t (:background nil :inherit nil)))) + '(show-paren-match ((t nil))) + '(magit-section-heading ((t nil))) + '(magit-header-line ((t (:background nil :foreground ,bg-white :box nil)))) + '(magit-diff-hunk-heading ((t nil))) + '(magit-diff-hunk-heading-highlight ((t nil))) + '(tooltip ((t nil))) + '(mode-line ((t (:background ,bg-white :box nil)))) + '(mode-line-inactive ((t (:box nil)))) + '(powerline-active1 ((t (:background ,bg-white)))) + '(powerline-active2 ((t (:background ,bg-white)))) + '(powerline-inactive1 ((t (:background ,bg-white)))) + '(powerline-inactive2 ((t (:background ,bg-white)))) + '(highlight ((t (:background ,shade-white)))) + '(hl-line ((t nil))) + '(org-document-title ((t (:inherit nil :height 1.8 :foreground ,bg-dark :underline nil)))) + '(org-document-info ((t (:height 1.2 :slant italic)))) + '(org-archived ((t (:inherit shadow :height 0.6)))) + '(org-level-1 ((t (:height 1.6 :weight normal :slant normal :foreground ,bg-dark)))) + '(org-level-2 ((t (:weight normal :height 1.3 :slant italic :foreground ,bg-dark)))) + '(org-level-3 ((t (:weight normal :slant italic :height 1.2 :foreground ,bg-dark)))) + '(org-level-4 ((t (:weight normal :slant italic :height 1.1 :foreground ,bg-dark)))) + '(org-level-5 ((t nil))) + '(org-level-6 ((t nil))) + '(org-level-7 ((t nil))) + '(org-level-8 ((t nil))) + ;; '(org-headline-done ((t (:family ,et-font)))) + '(org-quote ((t nil))) + '(org-block ((t (:background nil :height 0.9 :foreground ,bg-dark :family ,sans-mono-font)))) + '(org-block-begin-line ((t (:background nil :height 0.8 :family ,sans-mono-font :foreground ,slate)))) + '(org-block-end-line ((t (:background nil :height 0.8 :family ,sans-mono-font :foreground ,slate)))) + '(org-meta-line ((t (:height 0.8 :foreground ,gray)))) + '(org-document-info-keyword ((t (:height 0.8 :foreground ,gray)))) + '(org-link ((t (:foreground ,builtin)))) + '(org-special-keyword ((t (:family ,sans-mono-font :height 0.8)))) + '(org-property-value ((t (:family ,sans-mono-font :height 0.8)))) + '(org-drawer ((t (:family ,sans-mono-font :height 0.8)))) + '(org-todo ((t nil))) + '(org-done ((t nil))) + '(org-agenda-current-time ((t nil))) + '(org-hide ((t (:foreground ,bg-white)))) + '(org-indent ((t (:inherit (org-hide fixed-pitch))))) + '(org-time-grid ((t nil))) + '(org-warning ((t nil))) + '(org-date ((t (:family ,sans-mono-font :height 0.8)))) + '(org-agenda-structure ((t nil))) + '(org-agenda-date ((t (:foreground ,doc)))) + '(org-agenda-date-today ((t (:height 1.2)))) + '(org-agenda-date-weekend ((t nil))) + '(org-scheduled ((t (:foreground ,light-green)))) + '(org-upcoming-deadline ((t nil))) + '(org-scheduled-today ((t (:foreground ,dark-green)))) + '(org-scheduled-previously ((t (:foreground ,dark-green2)))) + '(org-agenda-done ((t (:foreground ,doc)))) + '(org-ellipsis ((t (:underline nil :foreground ,comment)))) + '(org-tag ((t (:foreground ,doc)))) + '(org-table ((t (:inherit fixed-pitch :height 0.9 :background ,bg-white)))) + '(org-code ((t (:inherit fixed-pitch :foreground ,comment :height 0.9)))) + '(font-latex-sectioning-0-face ((t nil))) + '(font-latex-sectioning-1-face ((t nil))) + '(font-latex-sectioning-2-face ((t nil))) + '(font-latex-sectioning-3-face ((t nil))) + '(font-latex-sectioning-4-face ((t nil))) + '(font-latex-sectioning-5-face ((t nil))) + '(font-latex-verbatim-face ((t nil))) + '(spacemacs-normal-face ((t nil))) + '(spacemacs-evilified-face ((t nil))) + '(spacemacs-lisp-face ((t nil))) + '(spacemacs-emacs-face ((t nil))) + '(spacemacs-motion-face ((t nil))) + '(spacemacs-visual-face ((t nil))) + '(spacemacs-hybrid-face ((t nil))) + '(bm-persistent-face ((t nil))) + '(helm-selection ((t nil))) + '(helm-match ((t nil))) + '(cfw:face-title ((t nil))) + '(cfw:face-holiday ((t nil))) + '(cfw:face-saturday ((t nil))) + '(cfw:face-sunday ((t nil))) + '(cfw:face-periods ((t nil))) + '(cfw:face-annotation ((t nil))) + '(cfw:face-select ((t nil))) + '(cfw:face-toolbar-button-off ((t nil))) + '(cfw:face-toolbar-button-on ((t nil))) + '(cfw:face-day-title ((t nil))) + '(cfw:face-default-content ((t nil))) + '(cfw:face-disable ((t nil))) + '(cfw:face-today ((t nil))) + '(cfw:face-toolbar ((t nil))) + '(cfw:face-today-title ((t nil))) + '(cfw:face-grid ((t nil))) + '(cfw:face-header ((t nil))) + '(cfw:face-default-day ((t nil))) + '(dired-subtree-depth-1-face ((t (:background nil)))) + '(dired-subtree-depth-2-face ((t (:background nil)))) + '(dired-subtree-depth-3-face ((t (:background nil)))) + '(dired-subtree-depth-4-face ((t (:background nil)))) + '(dired-subtree-depth-5-face ((t (:background nil)))) + '(dired-subtree-depth-6-face ((t (:background nil)))) + '(nlinum-current-line ((t (:foreground ,bg-dark)))) + '(vertical-border ((t nil))) + '(which-key-command-description-face ((t nil))) + '(flycheck-error ((t nil))) + '(flycheck-warning ((t nil))) + '(font-lock-string-face ((t nil))) + '(font-lock-comment-face ((t (:background nil :foreground ,doc :slant italic)))) + '(elfeed-search-unread-title-face ((t (:weight bold)))) + '(helm-ff-symlink ((t nil))) + '(region ((t nil)))) +#+end_src +#+begin_src emacs-lisp :noweb-ref faces-spacemacs-dark :tangle no +;; dark +'('(default ((t (:family ,sans-mono-font :background ,bg-dark :foreground ,bg-white)))) + '(variable-pitch ((t (:family ,sans-font)))) + '(header-line ((t (:background nil :inherit nil)))) + '(show-paren-match ((t (:background ,keyword :foreground ,bg-dark)))) + '(magit-section-heading ((t (:foreground ,keyword)))) + '(magit-header-line ((t (:background nil :foreground ,bg-dark :box nil)))) + '(magit-diff-hunk-heading ((t (:background ,comment :foreground ,gray)))) + '(magit-diff-hunk-heading-highlight ((t (:background ,comment :foreground ,fg-white)))) + '(tooltip ((t (:foreground ,gray :background ,bg-darker)))) + '(mode-line ((t (:background ,bg-darker)))) + '(mode-line-inactive ((t nil))) + '(powerline-active1 ((t nil))) + '(powerline-active2 ((t nil))) + '(powerline-inactive1 ((t nil))) + '(powerline-inactive2 ((t nil))) + '(highlight ((t (:background ,region :foreground ,fg-white)))) + '(hl-line ((t (:background ,region-dark)))) + '(org-document-title ((t (:inherit variable-pitch :height 1.3 :weight normal :foreground ,gray)))) + '(org-document-info ((t (:foreground ,gray :slant italic)))) + '(org-archived ((t nil))) + '(org-level-1 ((t (:inherit variable-pitch :height 1.3 :weight bold :foreground ,keyword :background ,bg-dark)))) + '(org-level-2 ((t (:inherit variable-pitch :weight bold :height 1.2 :foreground ,gray :background ,bg-dark)))) + '(org-level-3 ((t (:inherit variable-pitch :weight bold :height 1.1 :foreground ,slate :background ,bg-dark)))) + '(org-level-4 ((t (:inherit variable-pitch :weight bold :height 1.1 :foreground ,slate :background ,bg-dark)))) + '(org-level-5 ((t (:inherit variable-pitch :weight bold :height 1.1 :foreground ,slate :background ,bg-dark)))) + '(org-level-6 ((t (:inherit variable-pitch :weight bold :height 1.1 :foreground ,slate :background ,bg-dark)))) + '(org-level-7 ((t (:inherit variable-pitch :weight bold :height 1.1 :foreground ,slate :background ,bg-dark)))) + '(org-level-8 ((t (:inherit variable-pitch :weight bold :height 1.1 :foreground ,slate :background ,bg-dark)))) + '(org-headline-done (nil)) + '(org-quote ((t (:background ,bg-dark :family ,sans-mono-font)))) + '(org-block ((t (:background ,bg-dark :family ,sans-mono-font)))) + '(org-block-begin-line ((t (:background ,bg-dark)))) + '(org-block-end-line ((t (:background ,bg-dark)))) + '(org-meta-line ((t (:foreground ,comment)))) + '(org-document-info-keyword ((t (:foreground ,comment)))) + '(org-link ((t (:underline nil :weight normal :foreground ,slate)))) + '(org-special-keyword ((t (:height 0.9 :foreground ,comment)))) + '(org-property-value ((t (:height 0.9 :foreground ,comment)))) + '(org-drawer ((t (:height 0.9 :foreground ,comment)))) + '(org-todo ((t (:foreground ,builtin :background ,bg-dark)))) + '(org-done ((t (:inherit variable-pitch :foreground ,dark-cyan :background ,bg-dark)))) + '(org-agenda-current-time ((t (:foreground ,slate)))) + '(org-hide ((t nil))) + '(org-indent ((t (:inherit org-hide)))) + '(org-time-grid ((t (:foreground ,comment)))) + '(org-warning ((t (:foreground ,builtin)))) + '(org-date ((t nil))) + '(org-agenda-structure ((t (:height 1.3 :foreground ,doc :weight normal :inherit variable-pitch)))) + '(org-agenda-date ((t (:foreground ,doc)))) + '(org-agenda-date-today ((t (:height 1.5 :foreground ,keyword)))) + '(org-agenda-date-weekend ((t (:inherit org-agenda-date)))) + '(org-scheduled ((t (:foreground ,gray)))) + '(org-upcoming-deadline ((t (:foreground ,keyword)))) + '(org-scheduled-today ((t (:foreground ,fg-white)))) + '(org-scheduled-previously ((t (:foreground ,slate)))) + '(org-agenda-done ((t (:inherit nil :foreground ,doc)))) + '(org-ellipsis ((t (:underline nil :foreground ,comment)))) + '(org-tag ((t (:foreground ,doc)))) + '(org-table ((t (:background nil :family ,sans-mono-font)))) + '(org-code ((t (:inherit font-lock-builtin-face)))) + '(font-latex-sectioning-0-face ((t (:foreground ,type :height 1.2)))) + '(font-latex-sectioning-1-face ((t (:foreground ,type :height 1.1)))) + '(font-latex-sectioning-2-face ((t (:foreground ,type :height 1.1)))) + '(font-latex-sectioning-3-face ((t (:foreground ,type :height 1.0)))) + '(font-latex-sectioning-4-face ((t (:foreground ,type :height 1.0)))) + '(font-latex-sectioning-5-face ((t (:foreground ,type :height 1.0)))) + '(font-latex-verbatim-face ((t (:foreground ,builtin)))) + '(spacemacs-normal-face ((t (:background ,bg-dark :foreground ,fg-white)))) + '(spacemacs-evilified-face ((t (:background ,bg-dark :foreground ,fg-white)))) + '(spacemacs-lisp-face ((t (:background ,bg-dark :foreground ,fg-white)))) + '(spacemacs-emacs-face ((t (:background ,bg-dark :foreground ,fg-white)))) + '(spacemacs-motion-face ((t (:background ,bg-dark :foreground ,fg-white)))) + '(spacemacs-visual-face ((t (:background ,bg-dark :foreground ,fg-white)))) + '(spacemacs-hybrid-face ((t (:background ,bg-dark :foreground ,fg-white)))) + '(bm-persistent-face ((t (:background ,dark-cyan :foreground ,fg-white)))) + '(helm-selection ((t (:background ,region)))) + '(helm-match ((t (:foreground ,keyword)))) + '(cfw:face-title ((t (:height 2.0 :inherit variable-pitch :weight bold :foreground ,doc)))) + '(cfw:face-holiday ((t (:foreground ,builtin)))) + '(cfw:face-saturday ((t (:foreground ,doc :weight bold)))) + '(cfw:face-sunday ((t (:foreground ,doc)))) + '(cfw:face-periods ((t (:foreground ,dark-cyan)))) + '(cfw:face-annotation ((t (:foreground ,doc)))) + '(cfw:face-select ((t (:background ,region)))) + '(cfw:face-toolbar-button-off ((t (:foreground ,doc)))) + '(cfw:face-toolbar-button-on ((t (:foreground ,type :weight bold)))) + '(cfw:face-day-title ((t (:foreground ,doc)))) + '(cfw:face-default-content ((t (:foreground ,dark-cyan)))) + '(cfw:face-disable ((t (:foreground ,doc)))) + '(cfw:face-today ((t (:background ,region :weight bold)))) + '(cfw:face-toolbar ((t (:inherit default)))) + '(cfw:face-today-title ((t (:background ,keyword :foreground ,fg-white)))) + '(cfw:face-grid ((t (:foreground ,comment)))) + '(cfw:face-header ((t (:foreground ,keyword :weight bold)))) + '(cfw:face-default-day ((t (:foreground ,fg-white)))) + '(dired-subtree-depth-1-face ((t (:background nil)))) + '(dired-subtree-depth-2-face ((t (:background nil)))) + '(dired-subtree-depth-3-face ((t (:background nil)))) + '(dired-subtree-depth-4-face ((t (:background nil)))) + '(dired-subtree-depth-5-face ((t (:background nil)))) + '(dired-subtree-depth-6-face ((t (:background nil)))) + '(nlinum-current-line ((t (:foreground ,builtin)))) + '(vertical-border ((t (:background ,region :foreground ,region)))) + '(which-key-command-description-face ((t (:foreground ,type)))) + '(flycheck-error ((t (:background nil)))) + '(flycheck-warning ((t (:background nil)))) + '(font-lock-string-face ((t (:foreground ,string)))) + '(font-lock-comment-face ((t (:foreground ,doc :slant italic)))) + '(elfeed-search-unread-title-face ((t (:weight bold)))) + '(helm-ff-symlink ((t (:foreground ,slate)))) + '(region ((t (:background ,region))))) +#+end_src +*** Misc +**** Diminish buffer-face-mode +=Face-remap= is a library for basic face remapping. =Buffer-face-mode= +is enabled when using =variable-pitch-mode= to show the face defined +in =variable-pitch= instead of =default=. +#+begin_src emacs-lisp +(use-package face-remap + :delight (buffer-face-mode)) +#+end_src +**** Scaling the height of the =default= face. +When switching between monitors with different resolution, scaling the +=default= face can be used to in-/decreases the size of text and UI elements +(modeline, …) to a more readable size. +#+begin_src emacs-lisp +(defun fpi/scale-default-face (&optional arg) + "Increase height of face default." + (interactive "P") + (let* ((height (face-attribute 'default :height)) + (scale (if arg -10 10)) + (new (+ height scale))) + (set-face-attribute 'default nil :height new) + (message "Default height: %s. Use +,- for further adjustment" new) + (set-transient-map + (let ((map (make-sparse-keymap))) + (define-key map (vector '(?-)) (lambda () (interactive) (fpi/scale-default-face t))) + (define-key map (vector '(?+)) (lambda () (interactive) (fpi/scale-default-face nil))) + map)))) +#+end_src +#+begin_src emacs-lisp :tangle no :noweb-ref fpi-bindings +(fpi/define-key fpi-map (kbd "+") #'fpi/scale-default-face "Zoom") +(fpi/define-key fpi-map (kbd "-") (lambda () (interactive) (fpi/scale-default-face t)) "Unzoom") +#+end_src +** User info +Set ~user-full-name~ and ~user-mail-address~. These are set in +[[file:emacs-private.el.gpg::1][emacs-private.el.gpg]]. + +#+begin_src emacs-lisp +(setq user-full-name private/user-full-name + user-mail-address private/user-mail-address) +#+end_src +** Garbage collection +Give a message when Emacs does garbage collection and increase the thresholds for triggering it. +#+begin_src emacs-lisp +(use-package emacs + :custom + (garbage-collection-messages t) + (gc-cons-threshold 80000000) + (gc-cons-percentage 0.3)) +#+end_src +** Desktop module +This saves the state emacs was in. +#+begin_src emacs-lisp +(use-package desktop + :init + (setq desktop-dirname user-emacs-directory) + (setq desktop-base-file-name "desktop") + (setq desktop-globals-to-clear nil) + (setq desktop-missing-file-warning nil) + (setq desktop-restore-eager 5) + (setq desktop-restore-frames nil) + (setq desktop-save 'ask-if-new) + :config + (desktop-save-mode 1)) +#+end_src +** Customize +#+BEGIN_SRC emacs-lisp +(use-package cus-edit + :custom + (custom-file (expand-file-name "custom.el" user-emacs-directory)) + :hook + (after-init . (lambda () + (unless (file-exists-p custom-file) + (write-region "" nil custom-file)) + (load custom-file)))) +#+END_SRC +** File and input history +*** Recentf +#+begin_src emacs-lisp +(use-package recentf + :init + (setq recentf-save-file (expand-file-name "recentf" user-emacs-directory)) + (setq recentf-max-menu-items 10) + (setq recentf-max-saved-items 200) + (setq recentf-show-file-shortcuts-flag nil) + :config + (recentf-mode 1)) +#+end_src +*** Minibuffer +#+begin_src emacs-lisp +(use-package savehist + :init + (setq savehist-file (expand-file-name "savehist" user-emacs-directory)) + (setq history-length 1000) + (setq savehist-save-minibuffer-history t) + :config + (savehist-mode 1)) +#+end_src +*** Point +Remember where point is in a file. +#+begin_src emacs-lisp +(use-package saveplace + :init + (setq save-place-file (expand-file-name "saveplace" user-emacs-directory)) + :config + (save-place-mode 1)) +#+end_src +*** Backups +#+begin_src emacs-lisp +(use-package emacs + :custom + (backup-directory-alist '(("." . "~/.emacs.d/backups"))) + (version-control t) + (delete-old-versions t) + (kept-new-versions 6) + (kept-old-versions 2) + (create-lockfiles nil)) +#+end_src +** Local variables +#+begin_src emacs-lisp +(use-package files + :custom + <<files-custom>> + ) +#+end_src + +[[info:emacs#File Variables][File Variables]] are useful to ensure same behaviour in some files with different emacs configurations or to change behaviour from the default for one file. +Some settings could be harmful to emacs and the underlying system. Therefore many settings have to be declared as safe before using them. +#+begin_src emacs-lisp :tangle no :noweb-ref files-custom +(safe-local-variable-values + '((whitespace-style face trailing space-before-tab indentation empty space-after-tab newline-mark) + (whitespace-style face trailing space-before-tab indentation empty space-after-tab) + (eval set-window-buffer nil (current-buffer)) + (eval add-hook 'before-save-hook (lambda nil (fpi/tangle-async)) nil t) + (org-attach-preferred-new-method . dir) + (org-attach-use-inheritance . t) + (right-margin-width . 2) + (left-margin-width . 2) + (line-spacing . 0.2) + (after-save-hook org-babel-tangle) + (header-line-format . " ") + (after-save-hook . (org-babel-tangle)) + <<safe-local-variable-values>> +)) +#+end_src +** Personal keymap + +Unfortunately =C-c [a-z]= is not always a safe place for user-defined +key bindings. I use a special keymap to aggregate common functions. I +rebind the =C-z= binding for this. + +Here is a helper macro to define keys including keymap prompts as described [[https://www.olivertaylor.net/emacs/keymap-prompt.html][here]]. This macro has a signature very similar to the regular ~define-key~ function. +#+begin_src emacs-lisp +(defmacro fpi/define-key (map key func &optional desc) + "Define KEY in MAP with FUNC. Optionally provide DESC." + (if desc + `(define-key ,map ,key (cons ,desc ,func)) + `(define-key ,map ,key ,func))) +#+end_src + +*** Toggle map to toggle common options +This was inspired from [[http://endlessparentheses.com/the-toggle-map-and-wizardry.html][this post]] and I bind it to a key on my personal keymap. +#+BEGIN_SRC emacs-lisp :results silent +(define-prefix-command 'fpi/toggle-map nil "Toggle") +(fpi/define-key fpi/toggle-map "c" #'column-number-mode "Column") +;;(define-key fpi/toggle-map "d" #'toggle-debug-on-error) +(fpi/define-key fpi/toggle-map "f" #'auto-fill-mode "Fill") +(fpi/define-key fpi/toggle-map "l" #'scroll-lock-mode "Lock scrolling") +(fpi/define-key fpi/toggle-map "s" #'flyspell-mode "Spelling") +(fpi/define-key fpi/toggle-map "t" #'toggle-truncate-lines "Truncate lines") +(fpi/define-key fpi/toggle-map "q" #'toggle-debug-on-quit "Quit trigger debug") +(fpi/define-key fpi/toggle-map "r" #'dired-toggle-read-only "Read only") +(autoload 'dired-toggle-read-only "dired" nil t ) +(fpi/define-key fpi/toggle-map "v" #'visible-mode "Visible") +(fpi/define-key fpi/toggle-map "w" #'whitespace-mode "Whitespace") +(fpi/define-key fpi/toggle-map "W" #'whitespace-toggle-options "Whitespace Options") +#+END_SRC +*** fpi-map +#+BEGIN_SRC emacs-lisp :noweb yes +(define-prefix-command 'fpi-map nil "fpi-map") +(unbind-key (kbd "C-z")) +(global-set-key (kbd "C-z") 'fpi-map) + +(fpi/define-key fpi-map (kbd "a") #'org-agenda-show-agenda-and-todo "Agenda") +(fpi/define-key fpi-map (kbd "b") #'bury-buffer "Bury") +(fpi/define-key fpi-map (kbd "c") #'compile "Compile") +;;(define-key fpi-map (kbd "u") 'multiple-cursors-hydra/body) +(fpi/define-key fpi-map (kbd "h") #'dfeich/context-hydra-launcher "Hydra") +;; (define-key fpi-map (kbd "m") 'notmuch) +(fpi/define-key fpi-map (kbd "t") #'fpi/toggle-map "Toggle") +(fpi/define-key fpi-map (kbd "n") #'sauron-toggle-hide-show "Notifications") +(fpi/define-key fpi-map (kbd "j") (lambda () (interactive) (find-file org-journal-file)) "Journal") + +<<fpi-bindings>> +#+END_SRC +** Base commands (simple.el) +#+begin_src emacs-lisp +(use-package simple + :delight (visual-line-mode) + :config + (defun zap-up-to-char (arg char) + "Kill up to and excluding ARGth occurrence of CHAR. +Case is ignored if `case-fold-search' is non-nil in the current buffer. +Goes backward if ARG is negative; error if CHAR not found." + (interactive (list (prefix-numeric-value current-prefix-arg) + (read-char "Zap to char: " t))) + ;; Avoid "obsolete" warnings for translation-table-for-input. + (with-no-warnings + (if (char-table-p translation-table-for-input) + (setq char (or (aref translation-table-for-input char) char)))) + (kill-region (point) (progn + (search-forward (char-to-string char) nil nil arg) + (if (>= arg 0) + (backward-char) + (forward-char)) + (point)))) + <<simple-config>> + :bind (:map global-map + ("M-z" . zap-up-to-char) + <<simple-bindings>> + )) +#+end_src +Use a hard ~keyboard-quit~. This is from Jeff Norden ([[https://lists.gnu.org/archive/html/emacs-devel/2020-07/msg00326.html][Message on emacs-devel]]). +#+begin_src emacs-lisp :tangle no :noweb-ref simple-config +(defun keyboard-quit-strong () + "Run `keyboard-quit' to return emacs to a more responsive state. +If repeated twice in a row, run `top-level' instead, to also exit +any recursive editing levels." + (interactive) + (when (eq last-command 'keyboard-quit-strong) + (setq this-command 'top-level) ;dis-arm a 3rd C-g + (ding) + (top-level)) + ;; Not reached after `top-level'. (A rare behavior in lisp.) + (keyboard-quit)) +#+end_src + +#+begin_src emacs-lisp :tangle no :noweb-ref simple-bindings +("C-g" . keyboard-quit-strong) +#+end_src +* Selection and search methods +** Completion frameworks +Having used ido, ivy, icicles and helm in the past, I'm trying to +settle for something simple. + +For =vertico= use =M-RET= to end repeated minibuffer reads instead of =RET=. +#+begin_src emacs-lisp +;; Vertico & Marginalia +(use-package vertico + :straight t + :init (vertico-mode 1)) +(use-package vertico-posframe + :straight t + :config + (defun fpi/vertico-posframe-toggle () + (interactive) + (if vertico-posframe-mode + (progn + (vertico-posframe-cleanup) + (vertico-posframe-mode -1)) + (vertico-posframe-mode 1))) + :bind (:map vertico-map + ("C-," . fpi/vertico-posframe-toggle)) + :init (vertico-posframe-mode 1)) +(use-package marginalia + :straight t + :bind (:map minibuffer-local-map + ("M-A" . marginalia-cycle)) + :init (marginalia-mode 1)) + +;; Orderless & minibuffer settings +(use-package orderless + :straight t + :config + (setq orderless-matching-styles + '(orderless-regexp + orderless-initialism)) + (defmacro fpi/orderless-dispatcher (name suffix style) + "Define a orderless dispatcher function NAME using key SUFFIX to +call STYLE." + (backquote + (defun ,name (pattern _index _total) + (when (string-suffix-p ,suffix pattern) + (backquote (,style ,backquote-unquote-symbol(substring pattern 0 -1))))))) + (fpi/orderless-dispatcher + fpi/orderless-literal-dispatcher "=" orderless-literal) + (fpi/orderless-dispatcher + fpi/orderless-initialism-dispatcher "," orderless-initialism) + (fpi/orderless-dispatcher + fpi/orderless-flex-dispatcher "~" orderless-flex) + (setq orderless-style-dispatchers + '(fpi/orderless-literal-dispatcher + fpi/orderless-initialism-dispatcher + fpi/orderless-flex-dispatcher))) +(use-package minibuffer + :after (consult orderless) + :custom + ;; Make tramp host completion work. See vertico documentation. + (completion-styles '(orderless basic)) + (completion-category-overrides '((file (styles basic partial-completion)))) + + ;; Make completion-at-point use vertico + (completion-in-region-function + (lambda (&rest args) + (apply (if vertico-mode + #'consult-completion-in-region + #'completion--in-region) + args)))) + +;; General settings +(setq enable-recursive-minibuffers t) +(setq read-answer-short t) +(file-name-shadow-mode 1) +(minibuffer-depth-indicate-mode 1) +(minibuffer-electric-default-mode 1) +#+end_src +** isearch enhancements + +Once again this is mostly taken from [[https://gitlab.com/protesilaos/dotemacs/][Protesilaos Stavrou]]. + +#+BEGIN_SRC emacs-lisp +(use-package isearch + :init + (setq search-whitespace-regexp ".*") + ;; Or use the following for non-greedy matches + ;; (setq search-whitespace-regexp ".*?") + (setq isearch-lax-whitespace t) + (setq isearch-regexp-lax-whitespace nil) + :config + (defun prot/isearch-mark-and-exit () + "Marks the current search string. Can be used as a building +block for a more complex chain, such as to kill a region, or +place multiple cursors." + (interactive) + (push-mark isearch-other-end t 'activate) + (setq deactivate-mark nil) + (isearch-done)) + + (defun stribb/isearch-region (&optional not-regexp no-recursive-edit) + "If a region is active, make this the isearch default search +pattern." + (interactive "P\np") + (when (use-region-p) + (let ((search (buffer-substring-no-properties + (region-beginning) + (region-end)))) + (message "stribb/ir: %s %d %d" search (region-beginning) (region-end)) + (setq deactivate-mark t) + (isearch-yank-string search)))) + (advice-add 'isearch-forward-regexp :after 'stribb/isearch-region) + (advice-add 'isearch-forward :after 'stribb/isearch-region) + (advice-add 'isearch-backward-regexp :after 'stribb/isearch-region) + (advice-add 'isearch-backward :after 'stribb/isearch-region) + + (defun contrib/isearchp-remove-failed-part-or-last-char () + "Remove failed part of search string, or last char if successful. +Do nothing if search string is empty to start with." + (interactive) + (if (equal isearch-string "") + (isearch-update) + (if isearch-success + (isearch-delete-char) + (while (isearch-fail-pos) (isearch-pop-state))) + (isearch-update))) + + (defun contrib/isearch-done-opposite-end (&optional nopush edit) + "End current search in the opposite side of the match. +Particularly useful when the match does not fall within the +confines of word boundaries (e.g. multiple words)." + (interactive) + (funcall #'isearch-done nopush edit) + (when isearch-other-end (goto-char isearch-other-end))) + + :bind (:map isearch-mode-map + ("C-SPC" . prot/isearch-mark-and-exit) + ("DEL" . contrib/isearchp-remove-failed-part-or-last-char) + ("<C-return>" . contrib/isearch-done-opposite-end))) +#+END_SRC +* Directory, project, buffer, window management +** Dired +*** Base settings +- Always do recursive copies and deletions. +- Be smart about searching file names or the whole buffer. +- Use the system trash for now. +- Customize dired output switches. +- Dont try to be smart about rename and copy target locations when + having two open dired buffers. Setting the target to the other + directory is just as easy using =M-n= twice. +- Hide details by default. =(= to toggle. +- Highlight current line. +- Let the relevant =find= commands use case-insensitive names. +- Enable asynchronous mode for copying/renaming. +#+BEGIN_SRC emacs-lisp +(use-package dired + :custom + (dired-recursive-copies 'always) + (dired-recursive-deletes 'always) + (dired-isearch-filenames 'dwim) + (delete-by-moving-to-trash t) + (dired-listing-switches "-AFlh --group-directories-first") + (dired-dwim-target nil) + :hook + (dired-mode . dired-hide-details-mode) + (dired-mode . hl-line-mode) + (dired-mode . auto-revert-mode) + :bind (:map dired-mode-map + <<dired-bindings>> + )) + +(use-package find-dired + :after dired + :custom + (find-ls-option ;; applies to `find-name-dired' + '("-ls" . "-AFlv --group-directories-first")) + (find-name-arg "-iname")) + +(use-package async + :straight t) + +(use-package dired-async + :after (dired async) + :config + (dired-async-mode 1)) +#+END_SRC +*** Narrowing +#+BEGIN_SRC emacs-lisp +(use-package dired-narrow + :straight t + :after dired + :bind (:map dired-mode-map + ("SPC" . dired-narrow-regexp))) +#+END_SRC +*** wdired +Start with =C-x C-q=. +- Allow to change permissions. +- Interpret forward slash in renamed files as new subdirectory to + create. + +#+BEGIN_SRC emacs-lisp +(use-package wdired + :after dired + :init + (setq wdired-allow-to-change-permissions t) + (setq wdired-create-parent-directories t)) +#+END_SRC +*** peep-dired (file previews including images) +By default, dired does not show previews of files, while =image-dired= +is intended for a different purpose. We just want to toggle the +behaviour while inside a regular dired buffer. + +#+BEGIN_SRC emacs-lisp +(use-package peep-dired + :straight t + :after dired + :bind (:map dired-mode-map + ("P" . peep-dired)) + :custom + (peep-dired-cleanup-on-disable t) + (peep-dired-ignored-extensions + '("mkv" "webm" "mp4" "mp3" "ogg" "iso"))) +#+END_SRC +*** dired git info +#+begin_src emacs-lisp +(use-package dired-git-info + :straight t + :bind (:map dired-mode-map + (")" . dired-git-info-mode))) +#+end_src +*** dired-x +Some additional features that are shipped with Emacs. + +#+BEGIN_SRC emacs-lisp +(use-package dired-x + :after dired + :bind (("C-x C-j" . dired-jump) + ("C-x 4 C-j" . dired-jump-other-window)) + :hook + (dired-mode . (lambda () + (setq dired-clean-confirm-killing-deleted-buffers t)))) +#+END_SRC +*** dired-subtree ++ The tab key will expand or contract the subdirectory at point. ++ =C-TAB= will behave just like org-mode handles its headings: hit it + once to expand a subdir at point, twice to do it recursively, thrice + to contract the tree. ++ I also have Shift-TAB for contracting the subtree /when the point is + inside of it/. + +At any rate, this does not override the action of inserting a +subdirectory listing in the current dired buffer (with =i= over the +target dir). + +#+BEGIN_SRC emacs-lisp +(use-package dired-subtree + :straight t + :after dired + :bind (:map dired-mode-map + ("<tab>" . dired-subtree-toggle) + ("<C-tab>" . dired-subtree-cycle) + ("<S-iso-lefttab>" . dired-subtree-remove))) +#+END_SRC +*** dired-sidebar +Open a small sidebar window showing the current directory. +#+BEGIN_SRC emacs-lisp +(use-package dired-sidebar + :bind (("C-x C-n" . dired-sidebar-toggle-sidebar)) + :straight t + :commands (dired-sidebar-toggle-sidebar) + :hook + (dired-sidebar-mode . (lambda () + (unless (file-remote-p default-directory) + (auto-revert-mode)))) + :config + ;; (setq dired-sidebar-theme 'vscode) + (setq dired-sidebar-use-term-integration t)) +#+END_SRC + +*** dired-du +Recursive directory sizes. Toggle with =C-x M-r=. This will take a +while for directories with lots of nested files. +#+BEGIN_SRC emacs-lisp +(use-package dired-du + :straight t + :config (setq dired-du-size-format 't)) +#+END_SRC +** Tramp +Set Tramp to prefer the path settings in =~/.profile= over the value +of src_shell{getconf "PATH"}. See [[elisp:(describe-variable +'tramp-remote-path)]] for more info. +#+begin_src emacs-lisp +(use-package tramp + :config + (add-to-list 'tramp-remote-path 'tramp-own-remote-path)) +#+end_src +** Git +*** Git annex +There are some great resources on [[https://git-annex.branchable.com/][git-annex]] integration in emacs in [[https://github.com/mm--/dot-emacs/blob/master/jmm-emacs.org][Josh's config]]. Most of my configuration is copied from there. +Or use magit-annex instead? +#+begin_src emacs-lisp :noweb-ref straight-recipe-overrides :tangle no :eval never +(git-annex :type git :flavor melpa :host github :repo "jwiegley/git-annex-el") +#+end_src +#+begin_src emacs-lisp +(use-package git-annex + :straight (:host github :repo "fpiper/git-annex-el" :branch "master") + :config + <<git-annex-config>> + :after dired + :bind + (:map git-annex-dired-map + <<git-annex-dired-bindings>>) + (:map dired-mode-map + <<git-annex-dired-map-bindings>> + ) + ) +#+end_src +**** Actions to lock/unlock files +#+begin_src emacs-lisp :tangle no :noweb-ref git-annex-dired-bindings +("l" . git-annex-dired-lock-files) +("u" . git-annex-dired-unlock-files) +#+end_src +=git-annex.el= defines a handy macro to define generic =git-annex= CLI calls. +#+begin_src emacs-lisp :tangle no :noweb-ref git-annex-config +(git-annex-dired-do-to-files "lock" "Annex: locked %d file(s)") +(git-annex-dired-do-to-files "unlock" "Annex: unlocked %d file(s)") +#+end_src +**** Fix faces +=git-annex.el= kinda clobbers ~dired-marked-face~ and ~dired-flagged-face~. This fixes that. +#+begin_src emacs-lisp :tangle no :noweb-ref git-annex-config +(progn + (add-to-list 'dired-font-lock-keywords + (list "^[*].+ -> .*\\.git/annex/" + '("\\(.+\\)\\( -> .+\\)" (dired-move-to-filename) nil + (1 dired-marked-face) + (2 git-annex-dired-annexed-invisible)))) + (add-to-list 'dired-font-lock-keywords + (list "^[D].+ -> .*\\.git/annex/" + '("\\(.+\\)\\( -> .+\\)" (dired-move-to-filename) nil + (1 dired-flagged-face) + (2 git-annex-dired-annexed-invisible))))) +#+end_src +**** Make it easy to add metadata tags in git-annex +#+begin_src emacs-lisp :tangle no :noweb-ref git-annex-dired-bindings +("t" . jmm/dired-git-annex-tag) +#+end_src +Git-annex has a pretty cool ability to tag files and filter directory views based on metadata. It's kind of a pain to tag files, though, so here's a function that adds some autocompletion to tagging files. +#+BEGIN_SRC emacs-lisp :tangle no :noweb-ref git-annex-config +(defvar-local jmm/git-annex-directory-tags nil + "Current git-annex tags set in the directory, as a list.") + +(defun jmm/dired-git-annex-current-tags (file-list &optional intersection) + "Get current git-annex tag for each file in FILE-LIST. With + optional argument INTERSECTION, only show tags all files share in common." + (let* ((metadata (with-output-to-string + (with-current-buffer + standard-output + (apply #'process-file "git" nil t nil "annex" "metadata" "--json" file-list)))) + (json-array-type 'list) + (jsonout (-map 'json-read-from-string (split-string metadata "\n" t)))) + (-reduce (if intersection '-intersection '-union) (--map (cdr (assoc 'tag (cdr (assoc 'fields it)))) jsonout)))) + +(defun jmm/dired-git-annex-tag (file-list tags &optional arg) + "Add git-annex TAGS to each file in FILE-LIST. +Used as an interactive command, prompt for a list of tags for all +files, showing the current tags all files currently have in common." + (interactive + (let* ((files (dired-get-marked-files t current-prefix-arg)) + (shared-tags (jmm/dired-git-annex-current-tags files t)) + ;; Cache directory tags + (current-tags (or jmm/git-annex-directory-tags + (setq jmm/git-annex-directory-tags + (or (jmm/dired-git-annex-current-tags '("--all")) '(""))))) + (crm-separator " ") + (crm-local-completion-map + (let ((map (make-sparse-keymap))) + (set-keymap-parent map crm-local-completion-map) + (define-key map " " 'self-insert-command) + map)) + (tags (completing-read-multiple + "Tags: " (--map (concat it crm-separator) current-tags) + nil nil + (when shared-tags (mapconcat 'identity shared-tags " "))))) + (setq jmm/git-annex-directory-tags (-union tags jmm/git-annex-directory-tags)) + (list files tags current-prefix-arg))) + (let ((args (cl-loop for x in tags + append (list "-t" x)))) + (-each file-list + (lambda (file) + (apply #'call-process "git" nil nil nil "annex" "metadata" (append args (list file))))) + (message (format "Tagged %d file(s)" (length file-list))))) +#+END_SRC +**** Mark unavailable files +#+begin_src emacs-lisp :tangle no :noweb-ref git-annex-dired-bindings +("*") +("* a" . jmm/dired-mark-git-annex-available-files) +("* u" . jmm/dired-mark-git-annex-unavailable-files) +#+end_src + +When you use this in combination with ~dired-do-kill-lines~ (by default bound to ~k~), it's easy to hide files that aren't present in the current annex repository. +#+BEGIN_SRC emacs-lisp :tangle no :noweb-ref git-annex-config +(defun jmm/dired-mark-git-annex-unavailable-files () + "Mark git-annex files that are not present." + (interactive) + (dired-mark-if + (and (looking-at-p ".* -> \\(.*\\.git/annex/.+\\)") + (not (file-exists-p (file-truename (dired-get-filename t))))) + "unavailable file")) + +(defun jmm/dired-mark-git-annex-available-files () + "Mark git-annex files that are present." + (interactive) + (dired-mark-if + (and (looking-at-p ".* -> \\(.*\\.git/annex/.+\\)") + (file-exists-p (file-truename (dired-get-filename t)))) + "available file")) +#+END_SRC +**** Mark git-annex files with git-annex-matching-options +#+BEGIN_SRC emacs-lisp :tangle no :noweb-ref git-annex-dired-map-bindings +("% a" . jmm/dired-mark-files-git-annex-matching) +#+END_SRC + +This command makes it easy to mark dired files using ~git-annex-matching-options~. + +For instance, you could find files that are in a certain remote using ~--in=remote~ or mark/unmark files that have a certain tag using ~--metadata tag=sometag~. +#+BEGIN_SRC emacs-lisp :tangle no :noweb-ref git-annex-config +(defun jmm/dired-mark-files-git-annex-matching (matchingoptions &optional marker-char) + "Mark all files that match git annex's MATCHINGOPTIONS for use in later commands. +A prefix argument means to unmark them instead. +`.' and `..' are never marked." + (interactive + (list (read-string (concat (if current-prefix-arg "Unmark" "Mark") + " files matching (git annex match expression): ") + nil 'jmm-dired-annex-matchingoptions-history) + (if current-prefix-arg ?\040))) + (let ((dired-marker-char (or marker-char dired-marker-char))) + (dired-mark-if + (and (not (looking-at-p dired-re-dot)) + (not (eolp)) ; empty line + (let ((fn (dired-get-filename nil t))) + (when (and fn (not (file-directory-p fn))) + (message "Checking %s" fn) + (s-present? (shell-command-to-string + (mapconcat + #'identity + (list "git annex find" matchingoptions (shell-quote-argument fn)) + " ")))))) + "matching file"))) +#+END_SRC +**** Real file size +:PROPERTIES: +:header-args:emacs-lisp: :tangle no +:END: +Dired by default only shows the symlink file size. While it can be told to dereference symbolic links with the =-L= flag this only works on annexed files if they are present on the current machine. +Settings this flag causes more problems than it solves. Instead Josh has derived the functions below to determine the file size. I do not use them for now, but copied them here for future reference/usage. +***** Get git-annex file sizes +#+begin_src emacs-lisp :tangle no :noweb-ref git-annex-dired-bindings +("s" . jmm/dired-git-annex-print-human-file-size) +#+end_src +#+BEGIN_SRC emacs-lisp :tangle no :noweb-ref git-annex-config +(defun jmm/git-annex-file-target (filename) + "If FILENAME is a git annex file, return its symlink target." + (-when-let (symname (and filename + (file-symlink-p filename))) + (when (string-match-p ".*\\.git/annex/.+" symname) + symname))) + +(defun jmm/dired-git-annex-file-target () + "If the dired file at point is a git annex file, return its symlink target." + (jmm/git-annex-file-target (dired-get-filename nil t))) + +(defun jmm/git-annex-file-size (filename) + "Try to determine the size of the git annex file FILENAME." + (-when-let (target (jmm/git-annex-file-target filename)) + (or (save-match-data + (when (string-match "SHA256E-s\\([0-9]+\\)--" target) + (string-to-number (match-string 1 target)))) + (-some-> (expand-file-name target (file-name-directory filename)) + file-attributes + file-attribute-size)))) + +(defun jmm/dired-git-annex-print-human-file-size () + "Try to print the human readable file size of the dired git-annex file at point." + (interactive) + (let* ((filename (dired-get-filename nil t)) + (string-file (file-name-nondirectory filename))) + (-if-let (filesize (-some-> (jmm/git-annex-file-size filename) + file-size-human-readable)) + (message "%s - %s" filesize string-file) + (message "Can't determine git annex file size of %s" string-file)))) +#+END_SRC +***** Show git-annex file sizes in dired +#+begin_src emacs-lisp :tangle no :noweb-ref git-annex-dired-bindings +("S" . jmm/dired-git-annex-add-real-file-sizes) +#+end_src + +#+BEGIN_SRC emacs-lisp :tangle no :noweb-ref git-annex-config +;; Based off of `dired--align-all-files' +(defun jmm/dired-git-annex-add-real-file-sizes () + "Go through all the git-annex files in dired, replace the +symlink file size with the real file size, then try to align +everything." + (interactive) + (require 'dired-aux) + (let ((regexp directory-listing-before-filename-regexp)) + (save-excursion + (goto-char (point-min)) + (dired-goto-next-file) + (while (or (dired-move-to-filename) + (progn (save-restriction + (narrow-to-region (dired-subdir-min) (dired-subdir-max)) + (dired--align-all-files)) + (dired-next-subdir 1 t) + (dired-goto-next-file) + (dired-move-to-filename))) + (let ((inhibit-read-only t)) + (when (and (jmm/dired-git-annex-file-target) + (re-search-backward regexp (line-beginning-position) t)) + (goto-char (match-beginning 0)) + (-when-let (newsize (-some-> (jmm/git-annex-file-size (dired-get-filename nil t)) + file-size-human-readable)) + (search-backward-regexp "[[:space:]]" nil t) + (when (re-search-forward "[[:space:]]+\\([^[:space:]]+\\)[[:space:]]" nil t) + (goto-char (match-beginning 1)) + (delete-region (point) (match-end 1)) + (insert-and-inherit newsize)))) + (forward-line)))))) +#+END_SRC + +#+BEGIN_SRC emacs-lisp :tangle no +;; (add-hook 'dired-mode-hook #'jmm/dired-git-annex-add-real-file-sizes) +;; (add-hook 'dired-after-readin-hook #'jmm/dired-git-annex-add-real-file-sizes) +#+END_SRC +***** Sort dired by file size +#+BEGIN_SRC emacs-lisp :tangle no :noweb-ref git-annex-config +(defun jmm/dired-dir-files-beginning () + "First point where there's a filename on the line. Beginning of line." + (save-excursion + (goto-char (dired-subdir-min)) + (dired-goto-next-file) + (beginning-of-line) + (point))) + +(defun jmm/dired-dir-files-end () + "Last point where there's a filename. End of line." + (save-excursion + (goto-char (dired-subdir-max)) + (while (not (dired-get-filename nil t)) + (dired-previous-line nil)) + (end-of-line) + (point))) + +(defun jmm/dired-file-size () + "Return the file size of a file at point (for sorting). Takes +into account git-annex files." + (let* ((filename (dired-get-filename nil t)) + (string-file (file-name-nondirectory filename))) + (or (jmm/git-annex-file-size filename) + (file-attribute-size (file-attributes filename))))) + +;; TODO: Should just try to directly use the field listed. +(defun jmm/dired-sort-size (&optional ascending) + "Sort some dired lines by size (consider annex sizes). +With optional argument ASCENDING, sort by ascending file size. (I +like going the other way around usually.)" + (interactive "P") + (let (buffer-read-only + (beg (jmm/dired-dir-files-beginning)) + (end (jmm/dired-dir-files-end))) + (save-excursion + (save-restriction + (narrow-to-region beg end) + (goto-char (point-min)) + (sort-subr (not ascending) + 'forward-line 'end-of-line + #'jmm/dired-file-size nil))))) +#+END_SRC +**** Browsing URLs for git-annex files +#+begin_src emacs-lisp :tangle no :noweb-ref git-annex-dired-bindings +("b" . jmm/git-annex-browse-url) +#+end_src +#+BEGIN_SRC emacs-lisp +;; TODO: Process multiple files at once? +(defun jmm/git-annex-whereis-info (filename) + "Get information about where a git-annex file exists. +Returns a parsed json list from whereis." + (let* ((json-array-type 'list) + (whereisdata (shell-command-to-string + (mapconcat + #'identity + (list "git annex whereis --json" (shell-quote-argument filename)) + " ")))) + (when (s-present? whereisdata) + (json-read-from-string whereisdata)))) + +(defun jmm/git-annex-urls (filename) + "Get the git-annex web urls for FILENAME." + (-some->> (jmm/git-annex-whereis-info filename) + (assoc-default 'whereis) + (-mapcat (lambda (x) (assoc-default 'urls x))) + (-map (lambda (s) (s-chop-prefix "yt:" s))))) + +(defun jmm/git-annex-browse-url () + "Browse the first git-annex web urls for file at point." + (interactive) + (let* ((filename (dired-get-filename nil t)) + (filestr (file-name-nondirectory filename))) + (-if-let (url (car (jmm/git-annex-urls filename))) + (progn + (message "Opening url: %s" url) + (jmm/org-open-link-alternate-browser #'browse-url url)) + (user-error "No url found for %s" filestr)))) +#+END_SRC +**** Eshell helper functions +Helper functions to open dired view from eshell or list =git-annex= files which match a search. +#+BEGIN_SRC emacs-lisp +(defun jmm/git-annex-find-files (&rest args) + "Generate a list of git annex files that match ARGS. +For example, ARGS could be \"--in=here\"" + (-remove #'s-blank? + (s-split "\0" + (shell-command-to-string (mapconcat #'identity + (append '("git annex find --print0") args) + " "))))) +(defun eshell/dga (&rest args) + "Show a `dired' buffer of git annex files that match ARGS. +For example, ARGS could be \"--in=here\"" + (dired (cons "." (apply #'jmm/git-annex-find-files args)))) + +(defun eshell/gaf (&rest args) + "Return a list of git annex files that match ARGS. +For example, ARGS could be \"--in=here\"" + (apply #'jmm/git-annex-find-files args)) +#+END_SRC +*** Magit +#+BEGIN_SRC emacs-lisp +(use-package magit + :straight t + :custom (magit-completing-read-function 'magit-builtin-completing-read)) +#+END_SRC + +The following package is configured in accordance with the guidelines +provided by this article on [[https://chris.beams.io/posts/git-commit/][writing a Git commit message]]. + +#+BEGIN_SRC emacs-lisp +(use-package git-commit + :after magit + :custom + (git-commit-fill-column 72) + (git-commit-summary-max-length 50) + (git-commit-known-pseudo-headers + '("Signed-off-by" + "Acked-by" + "Modified-by" + "Cc" + "Suggested-by" + "Reported-by" + "Tested-by" + "Reviewed-by")) + (git-commit-style-convention-checks + '(non-empty-second-line + overlong-summary-line))) +#+END_SRC + +Only highlight the changes within a line, not the whole line. + +#+BEGIN_SRC emacs-lisp +(use-package magit-diff + :after magit + :custom + (magit-diff-refine-hunk 'all)) +#+END_SRC +**** Forge +#+begin_src emacs-lisp +(use-package forge + :after magit + :straight t + :config + <<forge-config>>) +#+end_src +Non-standard forges need to be added to ~forge-alist~ manually. +#+begin_src emacs-lisp :tangle no :noweb-ref forge-config +(append forge-alist private/magit-forges) +#+end_src +**** gitflow +Add support for [[https://nvie.com/posts/a-successful-git-branching-model/][gitflow]]. +#+begin_src emacs-lisp +(use-package magit-gitflow + :straight t + :hook (magit-mode . turn-on-magit-gitflow)) +#+end_src +*** git-identity +Found it in this [[https://www.manueluberti.eu/emacs/2020/03/30/lockdown-beam-git-identity/][blog post]] from Manuel Uberti. An easy way to handle multiple git identities. + +#+begin_src emacs-lisp +(use-package git-identity + :straight t + :init (git-identity-magit-mode 1) + :custom + (git-identity-verify t) + (git-identity-list private/git-identity-list) + :bind (:map magit-status-mode-map ("I" . git-identity-info))) +#+end_src +*** diff-hl +Indicates changed lines in the left fringe. The Hydra can be used to +navigate and revert hunks directly from the buffer. Use =g= to open +=magit-status=. I also bind this hydra to =g= in my personal keymap. + +#+begin_src emacs-lisp +(use-package diff-hl + :straight t + :init (global-diff-hl-mode 1) + :config (defhydra hydra-diff-hl (:body-pre (diff-hl-mode 1) + :hint nil) + " + Diff-hl: + _n_: next hunk _s_tage hunk _g_: Magit status + _p_: previous hunk _r_evert hunk _b_: Magit blame popup + ^ ^ _P_opup hunk ^ ^ + _a_: first hunk ^ ^ _q_uit + _e_: last hunk _A_mend mode _Q_uit and deactivate git-gutter + " + ("n" diff-hl-next-hunk) + ("p" diff-hl-previous-hunk) + ("a" (progn (goto-char (point-min)) + (diff-hl-next-hunk))) + ("e" (progn (goto-char (point-max)) + (diff-hl-previous-hunk))) + ("s" git-gutter:stage-hunk) + ("r" diff-hl-revert-hunk) + ("P" diff-hl-diff-goto-hunk) + ("A" diff-hl-amend-mode) + ("g" magit-status :color blue) + ("b" magit-blame :color blue) + ("q" nil :color blue) + ("Q" (diff-hl-mode -1) + :color blue)) +) +#+end_src + +#+begin_src emacs-lisp :noweb-ref fpi-bindings :tangle no +(fpi/define-key fpi-map "g" #'hydra-diff-hl/body "Git diff") +#+end_src +*** git-auto-commit +Mode to automatically commit on file save. Ensure that automatic +pushing is always turned off. To enable this with [[info:emacs#File Variables][File Variables]] set +some safe local variable values. +#+begin_src emacs-lisp +(use-package git-auto-commit-mode + :delight + :straight t + :custom + (gac-automatically-push-p nil)) +#+end_src + +#+begin_src emacs-lisp :tangle no :noweb-ref safe-local-variable-values +(git-auto-commit-mode . t) +(gac-debounce-interval . 600) +#+end_src +** Projects +#+begin_src emacs-lisp +(use-package project + :init + (defun fpi/project-magit () + (interactive) + (magit-status (project-root (project-current t)))) + :custom + (project-switch-commands + '((?f "Find file" project-find-file) + (?g "Find regexp" project-find-regexp) + (?d "Dired" project-dired) + (?m "Magit" fpi/project-magit) + (?v "VC-Dir" project-vc-dir) + (?e "Eshell" project-eshell)))) +#+end_src +** Consult +A bundle of common functions. Mostly drop in replacements for ~find-file~, ~grep~, ~find~, etc. +#+begin_src emacs-lisp +(define-prefix-command 'fpi/consult-map nil "consult-map") +(use-package consult + :straight t + :bind + ;; C-x bindings (ctl-x-map) + (("C-x b" . consult-buffer) ;; orig. switch-to-buffer + ("C-x 4 b" . consult-buffer-other-window) ;; orig. switch-to-buffer-other-window + ("C-x 5 b" . consult-buffer-other-frame) ;; orig. switch-to-buffer-other-frame + ("C-x r b" . consult-bookmark) ;; orig. bookmark-jump + ("C-x p b" . consult-project-buffer) ;; orig. project-switch-to-buffer + ) + ;; M-g, M-s + (("<help> a" . consult-apropos) ;; orig. apropos-command + ;; M-g bindings (goto-map) + ("M-g e" . consult-compile-error) + ("M-g f" . consult-flymake) ;; Alternative: consult-flycheck + ("M-g g" . consult-goto-line) ;; orig. goto-line + ("M-g M-g" . consult-goto-line) ;; orig. goto-line + ("M-g o" . consult-outline) ;; Alternative: consult-org-heading + ("M-g m" . consult-mark) + ("M-g k" . consult-global-mark) + ;; M-s bindings (search-map) + ("M-s d" . consult-find) + ("M-s D" . consult-locate) + ("M-s g" . consult-grep) + ("M-s G" . consult-git-grep) + ("M-s r" . consult-ripgrep) + ("M-s l" . consult-line) + ("M-s L" . consult-line-multi) + ("M-s m" . consult-multi-occur) + ("M-s u" . consult-focus-lines) + ;; Isearch integration + ("M-s e" . consult-isearch-history) + :map isearch-mode-map + ("M-s e" . consult-isearch-history) ;; orig. isearch-edit-string + ("M-s l" . consult-line) ;; needed by consult-line to detect isearch + ("M-s L" . consult-line-multi) ;; needed by consult-line to detect isearch + ;; Minibuffer history + :map minibuffer-local-map + ("M-s" . consult-history) ;; orig. next-matching-history-element + ("M-r" . consult-history)) ;; orig. previous-matching-history-element + (:map fpi/consult-map + ;; C-c bindings (mode-specific-map) + ("h" . consult-history) + ("m" . consult-mode-command) + ) + :config + ;; Optionally configure preview. The default value + ;; is 'any, such that any key triggers the preview. + ;; (setq consult-preview-key 'any) + ;; (setq consult-preview-key (kbd "M-.")) + ) +(use-package consult-flyspell + :after consult + :bind (("M-s s" . consult-flyspell))) +(use-package consult-org-roam + :straight t + :after (consult org-roam) + :custom + (consult-org-roam-grep-func #'consult-ripgrep) + :config + ;; Eventually suppress previewing for certain functions + ;; (consult-customize + ;; consult-org-roam-forward-links + ;; :preview-key (kbd "M-.")) + :bind + ("C-c n e" . consult-org-roam-file-find) + ("C-c n b" . consult-org-roam-backlinks) + ("C-c n r" . consult-org-roam-search)) +#+end_src + +Fix pdf-tools =goto-page= command: +#+begin_src emacs-lisp :noweb-ref pdf-tools-config :tangle no +(define-key pdf-view-mode-map [remap consult-goto-line] 'pdf-view-goto-page) +#+end_src + +#+begin_src emacs-lisp :noweb-ref fpi-bindings :tangle no +(fpi/define-key fpi-map (kbd ".") #'fpi/consult-map "Consult") +#+end_src +** Working with buffers + +This renames buffers with the same name and uniqifies them using angled +brackets containing their path. +#+BEGIN_SRC emacs-lisp +(use-package uniquify + :custom + (uniquify-buffer-name-style 'forward) + (uniquify-strip-common-suffix t) + (uniquify-after-kill-buffer-p t)) +#+END_SRC +#+begin_src emacs-lisp +(use-package autorevert + :delight (auto-revert-mode)) +#+end_src +*** ibuffer + +#+BEGIN_SRC emacs-lisp +(use-package ibuffer + :custom + (ibuffer-display-summary nil) + (ibuffer-use-other-window nil) + (ibuffer-auto-mode -1) + :hook + (ibuffer-mode . ibuffer-auto-mode)) +#+END_SRC + +Sort buffers in project groups using projectile. +#+BEGIN_SRC emacs-lisp :tangle no +(use-package ibuffer-projectile + :straight t + :after (ibuffer projectile) + :hook + (ibuffer-mode . (lambda () + (ibuffer-projectile-set-filter-groups) + (unless (eq ibuffer-sorting-mode 'recency) + (ibuffer-do-sort-by-recency))))) +#+END_SRC +=ibuffer-projectile= updates can be fairly slow. =ibuffer-vc= provides +better performance. +#+begin_src emacs-lisp +(use-package ibuffer-vc + :straight t + :custom + (ibuffer-formats + '((mark modified read-only vc-status-mini " " + (name 18 18 :left :elide) + " " + (size 9 -1 :right) + " " + (mode 16 16 :left :elide) + " " + (vc-status 16 16 :left) + " " + vc-relative-file))) + :hook + (ibuffer . (lambda () + (ibuffer-vc-set-filter-groups-by-vc-root) + (unless (eq ibuffer-sorting-mode 'alphabetic) + (ibuffer-do-sort-by-alphabetic))))) +#+end_src +** Window configuration +:PROPERTIES: +:ID: 99f1af26-1383-43c1-8408-9a13c495925e +:END: +=fit-window-to-buffer= automatically shrinks the current buffer based +on the amount of displayed text. +#+begin_src emacs-lisp +(use-package emacs ;; windows.el does not (provide 'windows) + :init + <<window>> + :custom + (fit-window-to-buffer-horizontally t) + :config + (defun split-window-left (&optional size) + (interactive "P") + (split-window-right size) + (other-window 1)) + (defun split-window-above (&optional size) + (interactive "P") + (split-window-below size) + (other-window 1)) + :bind + (:map global-map ("C-x C-3" . split-window-left)) + (:map global-map ("C-x C-2" . split-window-above)) + <<window-bindings>> + ) +#+end_src +*** Window rules +#+begin_src emacs-lisp :noweb-ref window +(setq display-buffer-alist + '(("\\*\\(Backtrace\\|Warnings\\|Compile-Log\\|Messages\\)\\*" + (display-buffer-in-side-window) + (window-height . 0.16) + (side . top) + (slot . 0) + (window-parameters . ((no-other-window t)))) + (".*\\*Completions.*" + (display-buffer-in-side-window) + (window-height . 0.16) + (side . bottom) + (slot . 0)) + ("\\*Help.*" + (display-buffer-in-side-window) + (window-width . 0.2) + (side . left) + (slot . 0) + (window-parameters . ((no-other-window . t) + (mode-line-format . (" " + mode-line-buffer-identification))))) + )) +#+end_src +*** window-numbering +This is a nice package for easy window focus switching. I prefer it +over =windmove=, as it does not interfere with org keybindings. +#+begin_src emacs-lisp +(use-package window-numbering + :straight t + :config (window-numbering-mode 1)) +#+end_src +*** Winner-mode +#+begin_src emacs-lisp +(use-package winner + :hook (after-init . winner-mode) + :hydra (winner-hydra + (global-map "C-c" :color red) + "Winner undo/redo" + ("<left>" winner-undo "undo") + ("<right>" winner-redo "redo")) + :bind (:map winner-mode-map + ("C-c <left>" . winner-hydra/winner-undo) + ("C-c <right>" . winner-hydra/winner-redo))) +#+end_src +** File encryption +=epa= handles en-/decryption with =gnupg=. Setting ~'loopback~ pinentry mode will ask for the key passphrase in the emacs minibuffer. For this the =pinentry= package is needed, as well as setting =allow-emacs-pinentry= in the =gnupg= configuration. + +#+begin_src emacs-lisp +(use-package epa + :custom (epa-pinentry-mode (if (equal (fpi/current-device-info :os) 'win10) + nil + 'loopback))) +(use-package pinentry + :straight t + :config (pinentry-start) + :after epa) +#+end_src +* Applications and utilities +** Calendar +Some basic calendar options for date format und location to provide +correct sunrise/-set times. +#+begin_src emacs-lisp +(use-package calendar + :custom + (calendar-date-style 'european) + (calendar-latitude 52.3667) + (calendar-longitude 9.7167)) +#+end_src + +Set the holidays to consider. I only use german and christian +holidays. Note the =:init= keyword. The individual holiday lists have +to be set before =holidays= is loaded and ~calendar-holidays~ is +initialized. +#+begin_src emacs-lisp +(use-package holidays + :init + (setq holiday-bahai-holidays nil + holiday-christian-holidays + (quote + ((holiday-float 12 0 -4 "1. Advent" 24) + (holiday-float 12 0 -3 "2. Advent" 24) + (holiday-float 12 0 -2 "3. Advent" 24) + (holiday-float 12 0 -1 "4. Advent" 24) + (holiday-fixed 12 25 "1. Weihnachtstag") + (holiday-fixed 12 26 "2. Weihnachtstag") + (holiday-fixed 1 6 "Heilige Drei Könige") + (holiday-easter-etc -48 "Rosenmontag") + (holiday-easter-etc -2 "Karfreitag") + (holiday-easter-etc 0 "Ostersonntag") + (holiday-easter-etc 1 "Ostermontag") + (holiday-easter-etc 39 "Christi Himmelfahrt") + (holiday-easter-etc 49 "Pfingstsonntag") + (holiday-easter-etc 50 "Pfingstmontag") + (holiday-easter-etc 60 "Fronleichnam") + (holiday-fixed 8 15 "Mariae Himmelfahrt") + (holiday-fixed 11 1 "Allerheiligen") + (holiday-float 11 0 1 "Totensonntag" 20))) + holiday-general-holidays + (quote + ((holiday-fixed 1 1 "Neujahr") + (holiday-fixed 2 14 "Valentinstag") + (holiday-fixed 5 1 "1. Mai") + (holiday-float 5 0 2 "Muttertag") + (holiday-fixed 10 3 "Tag der Deutschen Einheit"))) + holiday-hebrew-holidays nil + holiday-islamic-holidays nil + holiday-oriental-holidays nil)) +(use-package solar + :custom + (solar-n-hemi-seasons '("Frühlingsanfang" "Sommeranfang" "Herbstanfang" "Winteranfang"))) +#+end_src +** PDFs +=PDF-Tools= provides better rendering than =DocView=, which is only +png based. It also provides pdf syncing with a tex source. To use this +make sure to compile the tex document with the option ~--synctex=1~. + +#+BEGIN_SRC emacs-lisp +(use-package pdf-tools + :straight t + :config + (setq pdf-info-epdfinfo-program (concat user-emacs-directory "epdfinfo")) + (pdf-tools-install) + <<pdf-tools-config>> + ) +#+END_SRC + +Add support for pdf annotations. Rebind ~pdf-annot-minor-mode-map~ to +an easier prefix and undefine the bindings of ~image-mode~ for this +prefix. For now they are unbound globally as I never use them. It +would be better to unbind them only when in ~pdf-view-mode~. +#+BEGIN_SRC emacs-lisp +(use-package image-mode + :config + (define-key image-mode-map "a+" nil) + (define-key image-mode-map "a-" nil) + (define-key image-mode-map "a0" nil) + (define-key image-mode-map "ar" nil)) + +(use-package pdf-annot + :init (setq pdf-annot-minor-mode-map-prefix "a") + :bind (:map pdf-annot-minor-mode-map ("a d" . pdf-annot-delete))) +#+END_SRC + +Advice =load-theme= to update the colors for =pdf-view-midnight-mode= +after the theme changes. +#+NAME: theme-dependent-vars +#+begin_src emacs-lisp :tangle no +(defun update-pdf-view-midnight-color (&rest arg) + (customize-save-variable + 'pdf-view-midnight-colors + `(,(face-attribute 'default :foreground) . ,(face-attribute 'default :background)))) +(advice-add 'load-theme :after + #'update-pdf-view-midnight-color) +#+end_src + +** Latex +#+begin_src emacs-lisp +(use-package tex-site + :straight auctex) +#+end_src + +=cdlatex= depends on =texmath.el=. The docstring of =cdlatex= says +=texmath= is supposed to be part of Emacs. However my installation +does not have it. So =auctex= has to deliver this dependency instead. +#+begin_src emacs-lisp +(use-package cdlatex + :straight t + :custom + (cdlatex-env-alist + (list '("equation*" "\\begin{equation*}\nAUTOLABEL\n?\n\\end{equation*}" nil) + '("tikzpicture" "\\begin{tikzpicture}\nAUTOLABEL\n?\n\\end{tikzpicture}" nil) + '("circuitikz" "\\begin{circuitikz}\nAUTOLABEL\n?\n\\end{circuitikz}" nil)))) +#+end_src +** Programming languages +*** Utilities +Various utilities which ease programming in some languages. +#+begin_src emacs-lisp +(use-package yasnippet + :straight t) +(use-package yasnippet-snippets + :straight t) +(use-package company + :straight t) +#+end_src + +#+begin_src emacs-lisp +(use-package lsp-mode + :straight t) +#+end_src +*** Emacs lisp +Remap ~eval-last-sexp~ to a pretty print version. Then you can use =C-0 C-x C-e= to insert the values of the last sexp. Use ~pp-macroexpand-last-sexp~ to print a macro expanded version of the last sexp (but not eval it). +#+begin_src emacs-lisp +(global-set-key [remap eval-last-sexp] 'pp-eval-last-sexp) +#+end_src + +=Speed of thought= makes writing lisp so easy. No more snippets +needed. +#+begin_src emacs-lisp +(use-package sotlisp + :straight t + :init + (add-hook 'emacs-lisp-mode-hook 'speed-of-thought-mode)) +#+end_src +=Eldoc= displays information on variables and functions in the echo +area. +#+begin_src emacs-lisp +(use-package eldoc + :delight) +#+end_src +*** Matlab +#+begin_src emacs-lisp +(use-package matlab + :straight matlab-mode + :config + (unbind-key "M-s" matlab-mode-map)) +#+end_src +*** Rust +#+begin_src emacs-lisp +(use-package rustic + :straight t + :after org) +#+end_src +** CAD +[[https://www.openscad.org/][OpenSCAD]] is a programmable CAD Modeller. +#+begin_src emacs-lisp +(use-package scad-mode + :straight t) +#+end_src +** Calc +#+begin_src emacs-lisp +(use-package calc + :custom + (calc-lu-field-reference "1 V") + (calc-lu-power-reference "1 mW")) +#+end_src +** Org mode +Org is the mode you never need to leave, if you do not want to. My org +TODO and clocking setup is largely inspired by [[http://doc.rix.si/cce/cce-org.html][Ryan Rix's]] and [[http://doc.norang.ca/org-mode.html][Bernt +Hansen's]] configs. +- Scale latex previews :: The default is just a little bit too + small +- org-plus-contrib :: Install the =org-plus-contrib= package which + contains many extra org-modules. +- Startup indented :: Enable =org-indent-mode= in every org file. This + shows the content of headings indented to the headings level, but + does not actually insert whitespace at the start of the line. +- Enable Speed commands :: With the custom function speed commands are + enabled on any star of an headline. +- Set fast tag selection :: By defining default tags they can be set + just with one key press, similar to TODO states. +- Code blocks :: Open code blocks in the current window and use native + settings for the code blocks. +- Custom link abbrevs :: Define any expansion and use them as normal + org links like [[ddg:emacs]]. +- Babel languages :: Enable more languages to use in org-babel blocks. +- Youtube links :: See [[http://endlessparentheses.com/embedding-youtube-videos-with-org-mode-links.html][this blog post]] for more info. +- Ellipsis :: I currently use =" "= and previously used ="⚡⚡⚡"=. +- Drawer for Notes :: Notes go into the =NOTES= drawer. Clocking + times should stay separate in the =LOGBOOK= drawer. +- Track state changes :: Notes when an entry is switched to done when + the deadline or scheduled time change +- TODO Keywords :: Set my todo keywords, enable fast selection & some + custom faces for the todo keywords +- Change todo state on clock-in :: Switch entries automatically from + NEXT to INPROGRESS +- Align tags left :: Fixes problems with line breaking on small + window width. + +I use a org version with some custom patches. Rather than using something like =el-patch=, I host my version on github for now and update it every so often. +#+begin_src emacs-lisp :noweb-ref org-recipe :tangle no +(org :host github :repo "fpiper/org-mode" :branch "develop" + ;;:local-repo "org" :files (:defaults "contrib/lisp/*.el") + ) +#+end_src + +#+begin_src emacs-lisp +(use-package org + :straight + <<org-recipe>> + :delight (org-cdlatex-mode) + :bind + (("C-c c" . org-capture) + ("C-c a" . org-agenda) + ("C-c l" . org-store-link)) + :custom + (org-catch-invisible-edits 'smart) + (org-agenda-diary-file "~/sync/diary.org") + (org-use-speed-commands (lambda () (and (looking-at org-outline-regexp) (looking-back "^\**")))) + (org-pretty-entities t) + (org-fast-tag-selection-single-key t) + (org-link-abbrev-alist + '(("google" . "http://www.google.com/search?q=") + ("ddg" . "https://duckduckgo.com/?q=") + ("gmap" . "http://maps.google.com/maps?q=%s") + ("omap" . "http://nominatim.openstreetmap.org/search?q=%s&polygon=1"))) + (org-ellipsis " ") + (org-outline-path-complete-in-steps nil) + (org-log-into-drawer "NOTES") + (org-tags-column 0) + (org-tags-exclude-from-inheritance '( + <<org-custom-no-inheritance-tags>> + )) + <<org-custom>> + :hook + <<org-hook>> + :config + (add-to-list 'org-structure-template-alist (cons "f" "figure")) + ;; (add-to-list 'org-tags-exclude-from-inheritance "MARKED") + <<org-config>> + ) + +<<org-crypt>> +<<tangle-hook>> +<<org-crypt-tangle-setup>> +#+end_src +#+begin_src emacs-lisp +(use-package org-indent + :delight + :custom + (org-startup-indented t) + <<org-indent-custom>> + ) +#+end_src +#+begin_src emacs-lisp +(use-package ob-spice + :straight (:host github :repo "fpiper/ob-spice" + :branch "master")) +#+end_src + +#+begin_src emacs-lisp +(use-package ob-spectre + :load-path "~/git/projects/ob-spectre") +#+end_src +#+begin_src emacs-lisp +(use-package ob + :after org-roam + :config + (org-babel-do-load-languages + 'org-babel-load-languages + '((ruby . t) + (python . t) + ;;(ipython . t) + (emacs-lisp . t) + (octave . t) + (gnuplot . t) + (dot . t) + (spice . t) + (spectre . t) + (C . t) + (calc . t) + (latex . t) + (matlab . t) + (shell . t) + (lua . t) + (org . t) + (js . t) + (ditaa . t) + (plantuml . t) + ;; (hvm . t) + (ledger . t))) + :hook + <<ob-hooks>>) +#+end_src +#+BEGIN_SRC emacs-lisp +(use-package org-noter + :straight t + :bind (:map org-mode-map ("C-c o" . org-noter)) + :custom (org-noter-default-notes-file-names '("notes.org")) + ) +#+END_SRC + +#+begin_src emacs-lisp +(use-package org-pdftools + :straight t + :after (org pdf-tools) + :init (org-pdftools-setup-link)) +(use-package org-id + :custom + (org-id-link-to-org-use-id 'create-if-interactive-and-no-custom-id) + <<org-id-custom>>) +#+end_src +I prefer to use timestamp based ID's as they are +#+begin_src emacs-lisp :tangle no :noweb-ref org-id-custom +(org-id-method 'ts) +(org-id-ts-format "%FT%T%z.%6N") +#+end_src + +#+begin_src emacs-lisp +(use-package org-src + :custom + (org-src-window-setup 'other-window) + (org-src-fontify-natively t) + (org-src-tab-acts-natively t) + (org-edit-src-content-indentation 0)) +#+end_src + +#+begin_src emacs-lisp +(defun fpi/collect-org-directories-recursively (dir) + "Return list of all directories which contain .org files of DIR and its subdirectories" + (delete-dups (mapcar 'file-name-directory (directory-files-recursively dir "\.org$")))) +(use-package org-agenda + :custom + (org-agenda-files (fpi/collect-org-directories-recursively "~/sync")) + (org-deadline-warning-days 14) + (org-agenda-start-on-weekday nil) + (org-agenda-span 'day) + (org-agenda-start-day "+0d") + (org-agenda-include-diary nil) + (org-agenda-sticky t) + (org-agenda-todo-ignore-deadlines 'near) ;; or future? + (org-agenda-todo-ignore-scheduled 'future) + (org-agenda-skip-deadline-prewarning-if-scheduled t) + (org-agenda-tags-todo-honor-ignore-options t) + (org-agenda-todo-list-sublevels t) ;; nil to exclude sublevels of todos + (org-agenda-sorting-strategy '((agenda habit-down time-up priority-down category-keep) + (todo priority-down category-keep) + (tags priority-down category-keep) + (search category-keep))) + (org-agenda-skip-scheduled-if-done t) + (org-agenda-dim-blocked-tasks t) + (org-sort-agenda-notime-is-late t) + (org-agenda-scheduled-leaders '(" ➫" "➫ ")) ;; alternatives if font supports them: 👉🖝🕣🕣 + ;; See emacs.christianbaeuerlein.com/my-org-config.html + (org-agenda-block-separator 9472) + (org-agenda-custom-commands + `( + <<org-agenda-custom-commands>> + )) + <<org-agenda-custom>> + :config + <<org-agenda-config>> + ) +#+end_src + +#+begin_src emacs-lisp +(use-package ob-core + :custom + (org-confirm-babel-evaluate nil)) +(use-package org-screenshot) +(use-package org-collector) +(use-package ox) +(use-package ol-notmuch) +(use-package org-habit) +#+end_src + +#+begin_src emacs-lisp +(use-package org-inlinetask) +#+end_src +=org-bullets= provides better headline bullets. +Here is a list of nice ones: ◉, ○, ►, •. The default ones are ~'("◉" "○" "✸" "✿")~. +#+begin_src emacs-lisp +(use-package org-bullets + :straight t + :custom (org-bullets-bullet-list '(" ")) + :config (add-hook 'org-mode-hook (lambda () (org-bullets-mode 1)))) +#+end_src +#+begin_src emacs-lisp +(use-package org-num + :delight + :after org + :hook (org-mode . org-num-mode)) +#+end_src +*** Org & Latex +:PROPERTIES: +:header-args:emacs-lisp: :tangle no +:END: + +#+begin_src emacs-lisp :noweb-ref org-custom +(org-format-latex-header +"\\documentclass{standalone} +\\usepackage[usenames]{color} +[PACKAGES] +[DEFAULT-PACKAGES] +\\pagestyle{empty} % do not remove") +#+end_src + +#+begin_src emacs-lisp :noweb-ref org-custom +(org-latex-default-packages-alist + '(("mathletters" "ucs") + ("AUTO" "inputenc" t ("pdflatex")) + ("T1" "fontenc" t ("pdflatex")) + ("" "graphicx" t) + ("" "grffile" t) + ("" "longtable" nil) + ("" "wrapfig" nil) + ("" "rotating" nil) + ("normalem" "ulem" t) + ("" "amsmath" t) + ("" "textcomp" t) + ("" "amssymb" t) + ("" "capt-of" nil) + ("" "hyperref" nil))) +#+end_src + +#+begin_src emacs-lisp :noweb-ref org-config +(add-to-list 'org-latex-packages-alist '("" "siunitx")) +(add-to-list 'org-latex-packages-alist '("" "personal")) +(add-to-list 'org-latex-packages-alist '("" "svg")) +(add-to-list 'org-latex-packages-alist '("" "tikz")) +(add-to-list 'org-latex-packages-alist '("" "circuitikz")) +#+end_src + +#+begin_src emacs-lisp :noweb-ref org-hook +(org-mode . turn-on-org-cdlatex) +#+end_src +*** Org Exporter =ox= +#+begin_src emacs-lisp +(use-package ox + :custom + (org-export-with-broken-links 'match) + (org-export-backends '(ascii beamer html icalendar latex man md odt org groff koma-letter))) +#+end_src +**** Latex & Beamer +#+begin_src emacs-lisp +(use-package ox-latex + :custom + (org-latex-compiler "lualatex") + (org-latex-pdf-process + '("latexmk -f -pdf -%latex -shell-escape -interaction=nonstopmode -output-directory=%o %f"))) +#+end_src +Allow ~\framebreak{}~ by default, set a default theme and we also redefine the beamer latex class to use an aspect ratio of 16:9. The frame size will then be 160 mm by 90 mm. +#+begin_src emacs-lisp +(use-package ox-beamer + :custom + (org-beamer-frame-default-options "allowframebreaks") + (org-beamer-theme "Hannover") + :config + (remove (assoc "beamer" org-latex-classes) org-latex-classes) + (add-to-list 'org-latex-classes + '("beamer" + "\\documentclass[presentation,aspectratio=169]{beamer}" + ("\\section{%s}" . "\\section*{%s}") + ("\\subsection{%s}" . "\\subsection*{%s}") + ("\\subsubsection{%s}" . "\\subsubsection*{%s}"))) + ) +#+end_src +Latex preview +#+begin_src emacs-lisp :tangle no :noweb-rew org-custom +(org-preview-latex-default-process 'imagemagick) +(org-format-latex-options + '(:foreground default :background default :scale 1.5 :html-foreground "Black" :html-background "Transparent" :html-scale 1.0 :matchers ("begin" "$1" "$" "$$" "\\(" "\\["))) +(org-preview-latex-process-alist +'( +(dvipng :programs ("latex" "dvipng") :description "dvi > png" :message "you need to install the programs: latex and dvipng." :image-input-type "dvi" :image-output-type "png" :image-size-adjust (1.0 . 1.0) :latex-compiler ("latex -interaction nonstopmode -output-directory %o %f") :image-converter ("dvipng -D %D -T tight -bg Transparent -o %O %f")) +(dvisvgm :programs ("latex" "dvisvgm") :description "dvi > svg" :message "you need to install the programs: latex and dvisvgm." :image-input-type "dvi" :image-output-type "svg" :image-size-adjust (1.7 . 1.5) :latex-compiler ("latex -interaction nonstopmode -output-directory %o %f") :image-converter ("dvisvgm %f -n -b min -c %S -o %O")) +(imagemagick :programs ("latex" "convert") :description "pdf > png" :message "you need to install the programs: latex and imagemagick." :image-input-type "pdf" :image-output-type "png" :image-size-adjust (1.0 . 1.0) :latex-compiler ("lualatex -interaction nonstopmode -output-directory %o %f") :image-converter ("convert -density %D -trim -antialias %f -quality 100 %O")) +(pdf2svg :programs ("lualatex" "pdf2svg") :description "pdf > svg" :message "" :image-input-type "pdf" :image-output-type "svg" :image-size-adjust (2.0 . 2.0) :latex-compiler ("lualatex -interaction nonstopmode -output-directory %o %f") :image-converter ("pdf2svg %f %O")))) +#+end_src +**** ox-reveal +#+BEGIN_SRC emacs-lisp +(use-package ox-reveal + :straight t) +(use-package reveal) +(setq org-reveal-root "http://cdn.jsdelivr.net/reveal.js/3.0.0/") +#+END_SRC +*** Timekeeping & Clocking +- Remove clocks with zero time. +- Save a clocking history of the list 50 clocked items. +- Clock into the =LOGBOOK= drawer (as opposed to log entries going into ~org-log-into-drawer~) +#+begin_src emacs-lisp +(use-package org-clock + :custom + (org-clock-out-remove-zero-time-clocks t) + (org-clock-persist 'history) + (org-clock-history-length 50) + (org-clock-into-drawer "LOGBOOK") + :init + (org-clock-persistence-insinuate) + ) +#+end_src +Even with the history clocking into the correct item is sometimes difficult. So why not clock in any refile target: +#+begin_src emacs-lisp +(defun fpi/org-clock-in-heading (&optional prompt) + (interactive) + (let* ((location (org-refile-get-location (or prompt "Clock in on"))) + (file (cadr location)) + (marker (car (last location)))) + (save-excursion + (save-restriction + (find-file file) + (goto-char marker) + (org-clock-in) + (current-buffer))))) +#+end_src +**** Durations +#+begin_src emacs-lisp +(use-package org-duration + :after org + :custom + (org-duration-format '(("h" . t) ("min" . t) (special . h:mm)))) +#+end_src +*** Task organization +Much of my current task workflow is largely inspired by [[http://doc.rix.si/cce/cce-org.html][Ryan Rix's]] and [[http://doc.norang.ca/org-mode.html][Bernt +Hansen's]] configs. +**** =[WIP]= Task Setup +***** Todos +- WAITING tasks are waiting on the completion of other tasks +- NEXT tasks can be picked up +- INPROGRESS are current tasks with time clocked +- DONE are complete tasks +- ICEBOX tasks are on ice for whatever reason + +TODO->DONE cycle is for habits.\\ +Idle states cover things to do for time in between, checking the +inbox, reading news, … + +#+BEGIN_SRC dot :file /tmp/todo.png +digraph hierarch { + node [shape=box] + // Projects + PLANNING -> READY -> ACTIVE -> DONE, ICEBOX + // Tasks + HOLD -> NEXT -> INPROGRESS -> DONE, ICEBOX + NEXT -> ICEBOX, DONE + NEXT -> WAITING -> NEXT + INPROGRESS -> WAITING -> INPROGRESS + + IDLE -> IDLE + TODO -> DONE -> TODO + INPROGRESS -> REVIEW -> DONE + + { rank = source; PLANNING; HOLD } + { rank = same; READY; NEXT; TODO; IDLE } + { rank = same; ACTIVE; INPROGRESS } + { rank = sink; ICEBOX; DONE } +} +#+END_SRC + +#+RESULTS: +[[file:/tmp/todo.png]] + +#+begin_src emacs-lisp :noweb-ref org-config :tangle no +(defvar org-task-keywords + '("HOLD" "NEXT" "INPROGRESS" "REVIEW" "WAITING") + "Org todo keywords to demark tasks") +(defvar org-project-keywords + '("PLANNING" "READY" "ACTIVE") + "Org todo keywords to demark projects") +#+end_src + +#+begin_src emacs-lisp :noweb-ref org-custom :tangle no +(org-todo-keywords '((sequence "HOLD(h)" "NEXT(n)" "INPROGRESS(i!)" "WAITING(w@/!)" "REVIEW(r!)" "|" "ICEBOX(x@)" "DONE(d)") ;;todos + (sequence "PLANNING(p)" "READY(r)" "ACTIVE(a!)" "|" "ICEBOX(x@)" "DONE(d)") ;;projects + ;; (sequence "PHONE(P)" "MEETING(m)" "|" "CANCELED(c)" "DONE(d)") + (sequence "TODO(t)" "|" "DONE(d)") + (sequence "IDLE(b)" "|"))) +(org-use-fast-todo-selection t) +(org-todo-keyword-faces + '(("HOLD" :foreground "light gray" :weight bold) + ("NEXT" :foreground "light blue" :weight bold) + ("INPROGRESS" :foreground "burlywood" :weight bold) + ("REVIEW" :foreground "light goldenrod" :weight bold) + ("ACTIVE" :foreground "chocolate" :weight bold) + ("DONE" :foreground "forest green" :weight bold) + ("WAITING" :foreground "orange" :weight bold) + ("ICEBOX" :foreground "orange" :weight normal) + ;; ("CANCELLED" :foreground "forest green" :weight bold) + ;; ("MEETING" :foreground "yellow3" :weight bold) + ;; ("PHONE" :foreground "yellow3" :weight bold) + ("IDLE" :foreground "magenta" :weight bold))) +#+end_src +****** Automatically do =NEXT→INPROGRESS= / =READY→ACTIVE= +Switch a todo entry from NEXT to INPROGRESS when clocking in. +#+begin_src emacs-lisp :tangle no :noweb-ref org-config +(defun bh/clock-in-to-inprogress (kw) + "Switch a task from NEXT to INPROGRESS when clocking in. +Switch projects from READY to ACTIVE." + (when (not (and (boundp 'org-capture-mode) org-capture-mode)) + (cond + ((member (org-get-todo-state) (list "NEXT")) + "INPROGRESS") + ((member (org-get-todo-state) (list "READY")) + "ACTIVE")))) +#+end_src +#+begin_src emacs-lisp :tangle no :noweb-ref org-custom +(org-clock-in-switch-to-state 'bh/clock-in-to-inprogress) +#+end_src +****** State changes +Track state changes to done & changes to schedules and deadlines. +#+begin_src emacs-lisp :tangle no :noweb-ref org-custom +(org-log-done 'time) +(org-log-redeadline 'time) +(org-log-reschedule 'time) +#+end_src +***** Tags +Inspired by [[https://bzg.fr/en/some-emacs-org-mode-features-you-may-not-know.html/][Bastien Guerry]], [[https://github.com/jwiegley/dot-emacs][John Wiegley]]. +#+begin_src emacs-lisp :tangle no :noweb-ref org-custom +(org-tag-alist (quote (("HOT" . ?h) + (:startgroup) ;; Location + ("@errand" . ?E) ("@office" . ?O) ("@home" . ?H) + (:endgroup) + (:startgrouptag) ;; context tags + ("net" . ?n) ("call" . ?c) ("reply" . ?R) + (:endgrouptag) + (:startgroup) + ("handson" . ?o) ;; For focused/active tasks + (:grouptags) + ;; ("code" . ?c) ("design" . ?d) ("review" . ?v) + (:endgroup) + (:startgroup) + ("handsoff" . ?f) ;; For listening/passive tasks + (:grouptags) + ("read" . ?r) ("watch" . ?w) + (:endgroup) + ("crypt" . ?E) + ("FLAGGED" . ??) + ))) +#+end_src +Exclude =HOT= from inheritance +#+begin_src emacs-lisp :tangle no :noweb-ref org-custom-no-inheritance-tags +"HOT" +#+end_src +***** Creating projects +#+begin_src emacs-lisp +(defun fpi/make-parent-project () + (when (or (string-equal org-state "NEXT") + (string-equal org-state "HOLD") + (string-equal org-state "INPROGRESS") + (string-equal org-state "WAITING")) + ;; Activate parent + (org-up-element) + (let ((todo (org-entry-is-todo-p))) + (when todo + (org-todo "ACTIVE") + ;; (end-of-line) + ;; (insert " [0/0]") + (org-update-statistics-cookies nil) + )) + )) +#+end_src +***** INPROGRESS Custom Agendas +- John Wiegley: Different background colors for different source files +****** General +- "h": Next action for hot projects +- Project Next actions agenda +- "P": All Projects +- "r": uncategorized items (CATEGORY="Inbox"&LEVEL=2) +- "w": waiting/delegated tasks (W-TODO="DONE"|TODO={WAITING\|DELEGATED}) +- Unscheduled tasks (TODO<>""&TODO<>{DONE\|CANCELED\|NOTE\|PROJECT\|DEFERRED\|SOMEDAY}) +- "c": Appointment calendar +****** Task-related agendas +Simple day agenda with =INPROGRESS= tasks +******* Hot Projects +#+begin_src emacs-lisp :tangle no :noweb-ref org-agenda-custom-commands +("h" "Current Hotlist" tags "TODO={NEXT\\|INPROGRESS}" + ((org-agenda-overriding-header "Current Hotlist") + (org-agenda-skip-function (function fpi/org-agenda-skip-all-not-hot)) + (org-agenda-sorting-strategy + '(priority-down category-keep user-defined-down)) + (org-agenda-cmp-user-defined #'fpi/org-agenda-compare-hotness) + (org-agenda-prefix-format "%-12:c %-45(fpi/org-breadcrumbs)") + ;; (org-agenda-prefix-format " %-3i %-12:c%30b %s") + )) +#+end_src +#+begin_src emacs-lisp :tangle no :noweb-ref org-agenda-config +(defun fpi/org-breadcrumbs () + "Return projects over current entry. + +Similar to %b in `org-agenda-prefix-format'." + (org-with-wide-buffer + (let ((depth (fpi/org-project-depth 10)) + result) + (while (< (length result) depth) + (fpi/org-goto-parent-project 10) + (add-to-list 'result + (org-trim + (org-link-display-format + (replace-regexp-in-string + "\\[[0-9]+%\\]\\|\\[[0-9]+/[0-9]+\\]" "" + (nth 4 (org-heading-components)) ;; get entry title + ))))) + (if result + (reduce + (lambda (a b) (format "%s/%s" a b)) + (mapcar (lambda (s) (format "%.12s" s)) result) + ) + "") + ))) +(defun fpi/org-goto-parent-project (depth) + "Goto first project over current entry." + (when (fpi/parent-is-not-done-project-p) + (org-up-heading-safe)) + (while (and (> depth 0) + (not (fpi/is-not-done-project-p)) + (org-up-heading-safe)) + )) +(defun fpi/org-agenda-compare-hotness (a b) + "Compare level of hot headlines over entries A and B." + (let ((ha (fpi/org-agenda-hotness a)) + (hb (fpi/org-agenda-hotness b))) + (cond + ((> ha hb) +1) + ((< ha hb) -1) + (t nil)))) +(defun fpi/org-agenda-hotness (&optional entry) + "Return level of hot headlines over ENTRY." + (org-agenda-with-point-at-orig-entry entry (fpi/org-hotness))) +(defun fpi/org-hotness () + "Return level of hot headlines over current entry." + (let* ((tags (my-org-current-tags (fpi/org-project-depth 10))) + (l1 (length tags)) + (l2 (length (remove "HOT" tags)))) + (- l1 l2))) +(defun fpi/org-agenda-skip-all-not-hot-and-active () + "Skip all not hot entries and not active entries." + (when (not (and + (member "HOT" (my-org-current-tags (fpi/org-project-depth 10))) + (org-with-wide-buffer + (fpi/org-goto-parent-project 10) + (fpi/is-active-project-p)))) + (or (outline-next-heading) + (goto-char (point-max))))) +(defun fpi/org-agenda-skip-all-not-hot () + "Skip all not hot entries." + (when (not (member "HOT" (my-org-current-tags (fpi/org-project-depth 10)))) + (or (outline-next-heading) + (goto-char (point-max))))) +(defun fpi/org-agenda-skip-all-project-tasks () + "Skip all entries which belong to a project." + (when (fpi/is-part-of-project-p 10) + (or (outline-next-heading) + (goto-char (point-max))))) +(defun my-org-current-tags (depth) + (save-excursion + (ignore-errors + (let (should-skip) + (while (and (> depth 0) + (prog1 + (setq depth (1- depth)) + (not (org-up-element)))) + (if (looking-at "^\*+\\s-+") + (setq should-skip (append should-skip (org-get-local-tags))))) + should-skip)))) +(defun fpi/org-project-depth (depth) + "Return number of subheadings before reaching top project." + (org-with-wide-buffer (fpi/org-goto-top-project depth))) +(defun fpi/org-goto-top-project (depth) + "Go to the top project of heading under point" + (save-restriction + (widen) + (let (top + (count -1)) + (with-demoted-errors + (while (and (> depth 1) + (not (equal top (point)))) + (setq depth (1- depth)) + (setq top (point)) + (fpi/org-goto-parent-project depth) + (setq count (1+ count)))) + count))) +(defun fpi/is-part-of-project-p (depth) + "Return t if any parent heading is a project." + (< 0 (fpi/org-project-depth depth))) +(defun fpi/parent-is-not-done-project-p () + "Return t if parent heading is a not done project." + (save-excursion + (save-restriction + (widen) + (and (not (org-up-element)) + (fpi/is-not-done-project-p))))) +(defun fpi/is-not-done-project-p () + "Return t if current heading is a not done project." + (save-restriction + (widen) + (let ((todo (org-get-todo-state))) + (member todo org-project-keywords)))) +(defun fpi/is-active-project-p () + "Return t if current heading is an active project." + (save-restriction + (widen) + (equal "ACTIVE" (org-get-todo-state)))) +#+end_src +To narrow the agenda to the currently selected project this function from [[https://github.com/mm--/dot-emacs/blob/master/jmm-org-config.org][Josh's emacs config]] is useful. +#+begin_src emacs-lisp :tangle no :noweb-ref org-agenda-config +(defun fpi/org-agenda-lock-to-parent-project () + "In the org mode agenda, lock the restriction to the current project." + (interactive) + (save-window-excursion + (org-agenda-goto) + (if (fpi/org-goto-top-project 10) + (org-agenda-set-restriction-lock) + (user-error "No parent project found."))) + (org-agenda-redo-all)) +#+end_src + +#+begin_src emacs-lisp :tangle no :noweb-ref org-agenda-custom-commands +("H" "Hot Projects" tags "HOT&TODO={PLANNING\\|READY\\|ACTIVE}" + ((org-agenda-overriding-header "Hot Projects"))) +("T" "Non-Hot Projects" tags "-HOT&TODO={PLANNING\\|READY\\|ACTIVE}" + ((org-agenda-overriding-header "Non-Hot Projects"))) +("P" "All Projects" + ((tags "HOT&TODO={PLANNING\\|READY\\|ACTIVE}" + ((org-agenda-overriding-header "Hot Projects"))) + (tags "-HOT&TODO={PLANNING\\|READY\\|ACTIVE}" + ((org-agenda-overriding-header "Non-Hot Projects"))) + )) +#+end_src +Some tasks do not go into projects. Let's list only those. +#+begin_src emacs-lisp :tangle no :noweb-ref org-agenda-custom-commands +("g" "Non-Project (general) Tasks" tags "TODO={NEXT\\|INPROGRESS\\|REVIEW\\|WAITING}" + ((org-agenda-overriding-header "Non-Project Tasks") + (org-agenda-skip-function (function fpi/org-agenda-skip-all-project-tasks)))) +#+end_src +******* +#+begin_src emacs-lisp :tangle no :noweb-ref org-agenda-custom-commands +("n" "Project Next Actions" alltodo "" + ((org-agenda-overriding-header "Current Hotlist") + (org-agenda-skip-function + (function fpi/org-agenda-skip-all-not-hot)))) +#+end_src +#+begin_src emacs-lisp :tangle no :noweb-ref org-agenda-custom-commands-wiegley +("A" "Priority #A tasks" agenda "" + ((org-agenda-ndays 1) + (org-agenda-overriding-header "Today's priority #A tasks: ") + (org-agenda-skip-function + (quote + (org-agenda-skip-entry-if + (quote notregexp) + "\\=.*\\[#A\\]"))))) +("b" "Priority #A and #B tasks" agenda "" + ((org-agenda-ndays 1) + (org-agenda-overriding-header "Today's priority #A and #B tasks: ") + (org-agenda-skip-function + (quote + (org-agenda-skip-entry-if + (quote regexp) + "\\=.*\\[#C\\]"))))) +("r" "Uncategorized items" tags "CATEGORY=\"Inbox\"&LEVEL=2" + ((org-agenda-overriding-header "Uncategorized items"))) +("W" "Waiting/delegated tasks" tags "W-TODO=\"DONE\"|TODO={WAITING\\|DELEGATED}" + ((org-agenda-overriding-header "Waiting/delegated tasks:") + (org-agenda-skip-function + (quote + (org-agenda-skip-entry-if + (quote scheduled)))) + (org-agenda-sorting-strategy + (quote + (todo-state-up priority-down category-up))))) +("D" "Deadlined tasks" tags "TODO<>\"\"&TODO<>{DONE\\|CANCELED\\|NOTE\\|PROJECT}" + ((org-agenda-overriding-header "Deadlined tasks: ") + (org-agenda-skip-function + (quote + (org-agenda-skip-entry-if + (quote notdeadline)))) + (org-agenda-sorting-strategy + (quote + (category-up))))) +("S" "Scheduled tasks" tags "TODO<>\"\"&TODO<>{APPT\\|DONE\\|CANCELED\\|NOTE\\|PROJECT}&STYLE<>\"habit\"" + ((org-agenda-overriding-header "Scheduled tasks: ") + (org-agenda-skip-function + (quote + (org-agenda-skip-entry-if + (quote notscheduled)))) + (org-agenda-sorting-strategy + (quote + (category-up))))) +("d" "Unscheduled open source tasks (by date)" tags "TODO<>\"\"&TODO<>{DONE\\|CANCELED\\|NOTE\\|PROJECT}" + ((org-agenda-overriding-header "Unscheduled Open Source tasks (by date): ") + (org-agenda-skip-function + (quote + (org-agenda-skip-entry-if + (quote scheduled) + (quote deadline) + (quote timestamp) + (quote regexp) + "\\* \\(DEFERRED\\|SOMEDAY\\)"))))) +#+end_src + +#+begin_src emacs-lisp :tangle no :noweb-ref org-agenda-custom-commands +("d" "Day agenda" + ((agenda "" ((org-agenda-span 'day))) + (org-time-budgets-in-agenda-maybe) + (tags-todo "/+INPROGRESS" + ((org-agenda-overriding-header "Active Tasks"))))) +#+end_src +Agenda with all open tasks +#+begin_src emacs-lisp :tangle no :noweb-ref org-agenda-custom-commands +("n" "Agenda and all TODOs" + ((todo "INPROGRESS" + ((org-agenda-overriding-header "Inprogress Tasks"))) + (agenda) + (tags-todo "+soon+LEVEL=2" + ((org-agenda-overriding-header "2nd Level /Soon/ Tasks"))) + (tags-todo "+soon" + ((org-agenda-overriding-header "All /Soon/ Tasks"))) + (tags-todo "+shelve") + (tags-todo "+habit") + (todo "IDLE") + (tags-todo "-habit-shelve-soon-idle"))) +#+end_src +******* Fancy agenda to choose todays tasks +Based on https://github.com/psamim/dotfiles/blob/master/doom/config.el#L73. +#+begin_src emacs-lisp :tangle no :noweb-ref org-agenda-custom-commands +("o" "My Agenda" + ((agenda "" ((org-agenda-block-separator ? ) + (org-agenda-overriding-header "\n⚡ Deadlines:\n⎺⎺⎺⎺⎺⎺⎺⎺⎺") + (org-agenda-skip-function '(org-agenda-skip-entry-if 'notdeadline)) + (org-agenda-format-date (lambda (date) "")))) + (agenda* "" ((org-agenda-block-separator ? ) + (org-agenda-skip-function '(fpi/org-agenda-skip-if-not-today)) + (org-deadline-warning-days 0) + (org-agenda-todo-ignore-timestamp 'all) + (org-agenda-start-day "+0d") + (org-agenda-span 'day) + (org-agenda-overriding-header "⚡ Schedule:\n⎺⎺⎺⎺⎺⎺⎺⎺⎺") + (org-agenda-repeating-timestamp-show-all nil) + (org-agenda-remove-tags t) + (org-agenda-use-time-grid t) + ;; (org-agenda-prefix-format " %-3i %30b %t%s") + (org-agenda-todo-keyword-format " ☐ ") + (org-agenda-current-time-string "⮜┈┈┈┈┈┈┈ now") + (org-agenda-scheduled-leaders '("" "")) + (org-agenda-time-grid (quote ((daily today remove-match) + (0900 1200 1500 1800 2100) + " " "┈┈┈┈┈┈┈┈┈┈┈┈┈"))))) + (org-time-budgets-in-agenda-maybe) + (agenda "" ((org-agenda-block-separator ? ) + (org-agenda-overriding-header "\n⚡ Scheduled Tasks:\n⎺⎺⎺⎺⎺⎺⎺⎺⎺") + (org-agenda-skip-function '(org-agenda-skip-entry-if 'notscheduled)) + (org-agenda-use-time-grid nil) + (org-agenda-format-date (lambda (date) "")))) + )) +#+end_src +#+begin_src emacs-lisp +(defun fpi/org-agenda-skip-if-not-today () + "Skip all scheduled entries and deadlines not due for today." + (let ((subtree-end (save-excursion (org-end-of-subtree t))) + (deadline-day + (when (org-entry-get nil "DEADLINE") + (time-to-days + (org-time-string-to-time + (org-entry-get nil "DEADLINE"))))) + (scheduled-day + (when (org-entry-get nil "SCHEDULED") + (time-to-days + (org-time-string-to-time + (org-entry-get nil "SCHEDULED"))))) + (now (time-to-days (current-time)))) + (and (or (and deadline-day + (not (= deadline-day now))) + (and scheduled-day + (not (= scheduled-day now)))) + subtree-end))) +#+end_src +****** Week agendas +#+begin_src emacs-lisp :tangle no :noweb-ref org-agenda-custom-commands +("w" . "Week agendas") +("ww" "Standard week agenda" + ((agenda "" ((org-agenda-span 'week))))) +("wt" "This Week's agenda (starting on last Monday)" + ((agenda "" ((org-agenda-span 'week) + (org-agenda-start-day "-mon"))) + (tags-todo "+work"))) +("wn" "Next Week's agenda" + ((agenda "" ((org-agenda-span 'week) + (org-agenda-start-day "mon"))) + (tags-todo "+work"))) +#+end_src +****** Misc agendas +#+begin_src emacs-lisp :tangle no :noweb-ref org-agenda-custom-commands +("r" "Refile entries" ((tags "+REFILE"))) +("i" "Idle Actions" + ((tags-todo "IDLE-read-watch" + ((org-agenda-overriding-header "Idle Tasks") + (org-agenda-skip-function 'bh/skip-project-tasks) + (org-agenda-sorting-strategy + '(todo-state-down effort-up)))) + (tags-todo "read" + ((org-agenda-overriding-header "Idle Reading List") + (org-agenda-sorting-strategy + '(todo-state-down effort-up)))) + (tags-todo "watch" + ((org-agenda-overriding-header "Things to Watch") + (org-agenda-skip-function 'bh/skip-project-tasks) + (org-agenda-sorting-strategy + '(todo-state-down effort-up)))))) +("z" "Todos in org-roam-dir" + ((alltodo "" + ((org-agenda-files (fpi/collect-org-directories-recursively org-roam-directory)))))) +("c" "Agenda and all todos in current directory" + ((agenda "" + ((org-agenda-files (fpi/collect-org-directories-recursively default-directory)))) + (alltodo "" + ((org-agenda-files (fpi/collect-org-directories-recursively default-directory)))))) +#+end_src +***** Filtering +****** Auto Exclude +#+begin_src emacs-lisp +;; https://github.com/jwiegley/dot-emacs/blob/master/dot-org.el +(defun org-my-auto-exclude-function (tag) + (and (cond + ((string= tag "call") + (let ((hour (nth 2 (decode-time)))) + (or (< hour 8) (> hour 21)))) + ((string= tag "errand") + (let ((hour (nth 2 (decode-time)))) + (or (< hour 12) (> hour 17)))) + ((or (string= tag "home") (string= tag "nasim")) + (with-temp-buffer + (call-process "ifconfig" nil t nil "en0" "inet") + (call-process "ifconfig" nil t nil "en1" "inet") + (call-process "ifconfig" nil t nil "bond0" "inet") + (goto-char (point-min)) + (not (re-search-forward "inet 192\\.168\\.1\\." nil t)))) + ((string= tag "net") + (not (quickping "imap.fastmail.com"))) + ((string= tag "fun") + org-clock-current-task)) + (concat "-" tag))) +#+end_src +****** Stuck projects +The agenda can also list stuck projects with =C-c a #=. For this to be useful we have define what a stuck project is. + +A stuck project +1. has any todo state of the states listed in ~org-project-keywords~ +2. does /not/ have a subtask with a state of =TODO=, =NEXT= or =INPROGRESS=. + +#+begin_src emacs-lisp :tangle no :noweb-ref org-agenda-custom +(org-stuck-projects '("/+{PLANNING\\|READY\\|ACTIVE}" ("TODO" "NEXT" "INPROGRESS") nil "")) +#+end_src +**** Refile +Use the full outline path so I can distinguish headlines with the same name & disable step-wise completion as I think from the refile target backwards, not from top-level downwards. Also include the current file's headings as a refile targets up to a deep level, all agenda files up to a small level and all open org files up to an even smaller level. + +As refile only works on file-visiting buffers, we need to filter all other org buffers from ~(org-buffer-list)~. +#+begin_src emacs-lisp +(defun fpi/org-file-buffer-list () + "Return a list of org buffers which visit files." + (seq-filter 'buffer-file-name (org-buffer-list))) +#+end_src + +#+begin_src emacs-lisp :noweb-ref org-custom :tangle no +(org-refile-use-outline-path 'file) +(org-refile-targets '((buffer-file-name :maxlevel . 12) + (org-agenda-files :maxlevel . 10) + (fpi/org-file-buffer-list :maxlevel . 2))) +#+end_src +**** Time budgets +Gives an overview of time spent on defined budgets this week. Great to track if you've worked enough hours. To use it add ~(org-time-budgets-in-agenda-maybe)~ after ~(agenda)~ in a custom agenda command. +#+begin_src emacs-lisp +(use-package org-time-budgets + :straight (:host github :repo "fpiper/org-time-budgets" + :branch "develop" + :no-byte-compile t) + :config + (setq fpi/dense-time-budgets + '((:title "Work" :match "+work-nowork" :budget "40:00" :blocks (workday week)) + (:title "Personal" :match "+nowork-nonprod" :budget "5:00" :blocks (nil week)))) + (setq fpi/wide-time-budgets + '((:title "Work" :match "+work-nowork" :budget "40:00" :blocks (workday week)) + (:title "├Research" :match "+work+research" :budget "24:00" :blocks (nil week)) + (:title "├Teaching" :match "+work+teaching" :budget "8:00" :blocks (nil week)) + (:title "╰Reading" :match "+work+read" :budget "5:00" :blocks (workday week)) + (:title "Personal" :match "+nowork-nonprod" :budget "5:00" :blocks (nil week)))) + (setq org-time-budgets fpi/wide-time-budgets) + (defun fpi/toggle-time-budgets () + "Toggle between dense and wide time budgets." + (interactive) + (if (eq org-time-budgets fpi/wide-time-budgets) + (progn + (setq org-time-budgets fpi/dense-time-budgets) + (message "Set dense time budgets")) + (setq org-time-budgets fpi/wide-time-budgets) + (message "Set wide time budgets")))) +#+end_src +**** Column view +#+begin_src emacs-lisp +(setq org-columns-default-format + "%50ITEM(Task) %5Effort(Effort){:} %5CLOCKSUM %3PRIORITY %20DEADLINE %20SCHEDULED %20TIMESTAMP %TODO %CATEGORY %TAGS") +#+end_src +**** Clocking +I try to clock without any gap +#+begin_src emacs-lisp :tangle no :noweb-ref org-agenda-custom +(org-agenda-clock-consistency-checks '(:max-duration "10:00" :min-duration 0 :max-gap "0:00" :gap-ok-around ("4:00") :default-face ((:background "DarkRed") (:foreground "white")) :overlap-face nil :gap-face nil :no-end-time-face nil :long-face nil :short-face nil)) + +#+end_src +***** Combine adjacent clock lines +#+begin_src emacs-lisp +(defun fpi/org-clock-join-last-clock () + "Join current clock with last one if start/end point match." + (save-mark-and-excursion + (beginning-of-line) + (let* ((eol (save-excursion (end-of-line) (point))) + (boi (progn (re-search-forward "\\[" eol t) (backward-char) (point))) + (eoi (progn (re-search-forward "\\]" eol t) (point))) + (i (buffer-substring-no-properties boi eoi)) ;; last clock-in-time + (boc (progn (re-search-forward "\\[" eol t) (backward-char) (point))) + (eoc (progn (re-search-forward "\\]" eol t) (point))) + (c (buffer-substring-no-properties boc eoc))) ;; last clock-out-time (equals org-clock-out-time if last clock) + (next-line) + (end-of-line) + (let* ((bol (save-excursion (beginning-of-line) (point))) + (eoo (progn (re-search-backward "\\]" bol t) (forward-char) (point))) + (boo (progn (re-search-backward "\\[" bol t) (point))) + (o (buffer-substring-no-properties boo eoo))) ;; last-last clock-out-time + (when (equal i o) + (delete-region boo eoo) + ;; (insert (format-time-string (org-time-stamp-format t t) org-clock-out-time)) + (insert c) + (org-evaluate-time-range) + (previous-line) + (delete-region (save-excursion (beginning-of-line) (backward-char) (point)) eol) + (message (format "Joined nearby clocks at %s" i))))))) +(add-hook 'org-clock-out-hook 'fpi/org-clock-join-last-clock) +#+end_src +***** org-clock-convenience +#+begin_src emacs-lisp +(use-package org-clock-convenience + :straight t + :bind (:map org-agenda-mode-map + ("<S-up>" . org-clock-convenience-timestamp-up) + ("<S-down>" . org-clock-convenience-timestamp-down) + ("<C-right>" . org-clock-convenience-fill-gap) + ("<C-left>" . org-clock-convenience-fill-gap-both))) +#+end_src +*** org-checklist +#+begin_quote +This file provides some functions for handing repeated tasks which involve +checking off a list of items. By setting the RESET_CHECK_BOXES property in an +item, when the TODO state is set to done all checkboxes under that item are +cleared. If the LIST_EXPORT_BASENAME property is set, a file will be created +using the value of that property plus a timestamp, containing all the items +in the list which are not checked. Additionally the user will be prompted to +print the list. +#+end_quote +#+begin_src emacs-lisp +(use-package org-checklist + :after org + :straight (org-contrib)) +#+end_src +*** Handling web urls +**** org-web-tools +:PROPERTIES: +:ID: dc4129ff-6d76-4f12-926f-c62a687a39ec +:END: +This provides functions to get webpage title or content for org mode links. +#+begin_src emacs-lisp +(use-package org-web-tools + :straight t) +#+end_src +#+begin_src emacs-lisp :noweb-ref fpi-bindings :tangle no +(fpi/define-key fpi-map "l" #'org-web-tools-insert-link-for-url "Link (org)") +#+end_src + +*** Gnorb +:PROPERTIES: +:ID: 990e2668-11d6-45eb-9c9b-1dc0b89b556d +:END: +This combines [[file:gnus.org][Gnus]] conversations with Org mode for note taking and [[id:390b66e5-b123-4cb1-9a56-61e41d7a818a][BBDB]] for contact information. +#+begin_src emacs-lisp +(use-package gnorb + :straight t + :config + (gnorb-install-defaults) + :custom + <<gnorb-custom>>) +#+end_src +To setup =gnorb= we need to do several things according to [[info:gnorb#Tracking Setup][the manual]]: +1. Activate the gnus registry with ~(gnus-registry-initialize)~ +2. Make sure global id tracking in org-id is enabled + #+begin_src emacs-lisp :noweb-ref org-id-custom :tangle no + (org-id-track-globally t) + #+end_src +3. Add nngnorb to ~gnus-secondary-select-methods~ +4. Call ~(gnorb-tracking-initialize)~. As this requires =gnus= to be loaded, this is called in =gnus.org= +5. Set gnorb saved messages groups + #+begin_src emacs-lisp :tangle no :noweb-ref gnorb-custom + (gnorb-gnus-sent-groups '("nnimap+imsmail:INBOX/work" "nnimap+imsmail:Gesendete ELemente")) + #+end_src +6. Set todo capture template + #+begin_src emacs-lisp :tangle no :noweb-ref gnorb-custom + (gnorb-gnus-new-todo-capture-key "t") + #+end_src + +Default keybindings: +#+begin_example emacs-lisp +(global-set-key (kbd "C-c A") 'gnorb-restore-layout) +(eval-after-load "gnorb-bbdb" + '(progn + (define-key bbdb-mode-map (kbd "C-c S") #'gnorb-bbdb-mail-search) + (define-key bbdb-mode-map (kbd "C-c l") #'gnorb-bbdb-open-link) + (define-key bbdb-mode-map [remap bbdb-mail] #'gnorb-bbdb-mail) + (eval-after-load "gnorb-org" + (org-defkey org-mode-map (kbd "C-c C") #'gnorb-org-contact-link)))) +(eval-after-load "gnorb-org" + '(progn + (org-defkey org-mode-map (kbd "C-c t") #'gnorb-org-handle-mail) + (org-defkey org-mode-map (kbd "C-c v") #'gnorb-org-view) + (org-defkey org-mode-map (kbd "C-c E") #'gnorb-org-email-subtree) + (setq gnorb-org-agenda-popup-bbdb t) + (eval-after-load "org-agenda" + '(progn (org-defkey org-agenda-mode-map (kbd "C-c t") #'gnorb-org-handle-mail) + (org-defkey org-agenda-mode-map (kbd "C-c v") #'gnorb-org-view))))) +(eval-after-load "gnorb-gnus" + '(progn + (define-key gnus-summary-mime-map "a" #'gnorb-gnus-article-org-attach) + (define-key gnus-summary-mode-map (kbd "C-c t") #'gnorb-gnus-incoming-do-todo) + (define-key gnus-summary-mode-map (kbd "C-c v") #'gnorb-gnus-view) + (define-key gnus-summary-mode-map (kbd "C-c C-t") #'gnorb-gnus-tag-message) + (define-key gnus-summary-limit-map (kbd "g") #'gnorb-gnus-insert-tagged-messages) + (define-key gnus-summary-limit-map (kbd "G") #'gnorb-gnus-insert-tracked-messages) + (setq gnorb-gnus-capture-always-attach t) + (push '("attach to org heading" . gnorb-gnus-mime-org-attach) + gnus-mime-action-alist) + (push '(gnorb-gnus-mime-org-attach "a" "Attach to Org heading") + gnus-mime-button-commands) + (setq gnus-mime-button-map + (let ((map (make-sparse-keymap))) + (dolist (c gnus-mime-button-commands) + (define-key map (cadr c) (car c))) + map)))) +(eval-after-load "message" + '(progn + (define-key message-mode-map (kbd "C-c t") #'gnorb-gnus-outgoing-do-todo))) +#+end_example +**** More refile targets +Make gnorb consider the same refile targets as org. +#+begin_src emacs-lisp :tangle no :noweb-ref gnorb-custom +(gnorb-gnus-trigger-refile-targets org-refile-targets) +#+end_src +*** Inline images + +Resize inline images to 400px but respect width specifications in attribute lines. +#+begin_src emacs-lisp :noweb-ref org-custom :tangle no +(org-image-actual-width t) +#+end_src +Also display remote images by downloading them. +#+begin_src emacs-lisp :noweb-ref org-custom :tangle no +(org-display-remote-inline-images 'download) +#+end_src + +#+begin_src emacs-lisp :noweb-ref ob-hooks :tangle no +(org-babel-after-execute . org-redisplay-inline-images) +#+end_src +*** Babel +This function is handy to use in header arguments to create names based on the current org heading. E.g. =:var data=(fpi/format-headline "/tmp/prefix_")= +#+begin_src emacs-lisp +(defun fpi/format-headline (&optional pre post) + (let ((pre (or pre "")) + (post (or post ""))) + (format "%s%s%s" pre (nth 4 (org-heading-components)) post))) +#+end_src + +We can also create unique names based on the source block content and header information. +#+begin_src emacs-lisp +(defun fpi/org-babel-get-src-block-hash (&optional block) + "Return a hash based on src block content and header. + +This function tries to not take any file positions into account +and always return the same hash given the same source code and +same header arguments. + +`org-babel-sha1-hash' may provide the same feature, but I +discovered that function only after writing this." + (save-mark-and-excursion + (if block (org-babel-goto-named-src-block block)) + (let* ((info (org-babel-get-src-block-info t)) + (body (nth 1 info)) + (header (nth 2 info)) + (hashstring (format "%s%s" body header))) + (md5 hashstring)))) + +(setq fpi/org-babel-outfile-directory "/tmp/babel") +(make-directory fpi/org-babel-outfile-directory t) + +(defun fpi/org-babel-src-block-temp-file (&optional suffix prefix directory block) + "Return a unique filename based on src block content and header. + +This function is intended as an alternative to +`org-babel-temp-file' to provide unique and constant output +filenames. Optionally provide SUFFIX or PREFIX of the filename +and the file DIRECTORY. If SUFFIX or PREFIX is a list its content +will be concatenated. Default directory is +`org-babel-temporary-directory'. Optionally provide a source +block name BLOCK. + " + ;; FIXME Way to create really unique names. In case same code can produce different outputs (e.g. based on time, file context) + (let ((hash (fpi/org-babel-get-src-block-hash block)) + (directory (or + directory + fpi/org-babel-outfile-directory)) + (suffix (if (listp suffix) + (mapconcat (lambda (x) + (cond ;; FIXME possible to handle all cases without cond? + ((symbolp x) (symbol-name x)) + ((numberp x) (number-to-string x)) + (t x) + )) suffix "") + suffix)) + (prefix (if (listp prefix) + (mapconcat (lambda (x) + (cond ;; FIXME possible to handle all cases without cond? + ((symbolp x) (symbol-name x)) + ((numberp x) (number-to-string x)) + (t x) + )) prefix "") + prefix)) + (prefix (or prefix "")) + ) + (expand-file-name (format "%s%s%s" prefix hash suffix) directory) + )) +(defalias 'fpi/ob-name #'fpi/org-babel-src-block-temp-file) +#+end_src + +Now wen can set something like ~:file (fpi/ob-name ".png")~ on all source blocks where we do not care about the output file name. + +Some tests for ~fpi/ob-name~: +#+begin_src emacs-lisp :results value replace :tangle no :exports both +(list + (fpi/ob-name) + (fpi/ob-name "-SUFFIX") + (fpi/ob-name nil "PREFIX-") + (fpi/ob-name "-SUFFIX" "PREFIX-") + (fpi/ob-name '("-SUF" 42 FIX)) + ) +#+end_src + +#+RESULTS: +| /tmp/babel-gwZcjh/291f3f60f3e5d467584a3b5bda4d7b05 | /tmp/babel-gwZcjh/291f3f60f3e5d467584a3b5bda4d7b05-SUFFIX | /tmp/babel-gwZcjh/PREFIX-291f3f60f3e5d467584a3b5bda4d7b05 | /tmp/babel-gwZcjh/PREFIX-291f3f60f3e5d467584a3b5bda4d7b05-SUFFIX | /tmp/babel-gwZcjh/291f3f60f3e5d467584a3b5bda4d7b05-SUF42FIX | + +*** ol-bbdb +#+begin_src emacs-lisp +(use-package ol-bbdb) +#+end_src +*** icalendar support +While =org-caldav= offers syncing with caldav servers it relies on =ox-icalendar= to convert between org entries and icalendar events. +**** org-caldav +#+begin_src emacs-lisp +(use-package org-caldav + :straight t + :custom + (org-caldav-url private/calendar-url) + (org-caldav-calendar-id private/calendar-id) + (org-caldav-inbox "~/sync/w.org") + (org-caldav-files nil) + (org-caldav-sync-direction 'cal->org) + (org-caldav-delete-calendar-entries 'never) + (org-caldav-exclude-tags nil) +) +#+end_src +**** ox-icalendar +#+begin_src emacs-lisp +(use-package ox-icalendar + :after org + :custom + (org-icalendar-store-UID t)) +#+end_src +*** prettify symbols +Set some prettify symbols for org mode. +#+begin_src emacs-lisp +(defun fpi/add-org-prettify-symbols () + "Beautify Org Checkbox Symbol" + (setq prettify-symbols-alist + (append prettify-symbols-alist + '(("#+BEGIN_SRC" . ?») + ("#+END_SRC" . ?«) + ("#+begin_src" . ?») + ("#+end_src" . ?«) + ("[ ]" . ?☐) + ("[X]" . ?☑ ) + ("[-]" . ?❍ ))))) +(add-hook 'org-mode-hook 'fpi/add-org-prettify-symbols) +#+end_src +*** org-roam +Org-roam mainly provides a display of backlinks to the current file. This allows the creation of a one-subject-per-file Zettelkasten. +#+begin_src emacs-lisp :tangle tangle/emacs-10-init.el :noweb yes :results silent +(use-package org-roam + :straight (:host github + :repo "org-roam/org-roam" + :no-byte-compile t) + :after (magit org) + :custom + (org-roam-directory "~/git/projects/zettel") + (org-roam-v2-ack t) + (org-roam-mode-section-functions + '(org-roam-backlinks-section + org-roam-reflinks-section + org-roam-unlinked-references-section)) + (org-roam-capture-templates + (quote + <<org-roam-capture-templates()>> + )) + :config + (org-roam-db-autosync-mode 1) + (add-to-list 'display-buffer-alist + '("\\*org-roam\\*" + (display-buffer-in-direction) + (direction . below) + (window-height . 0.3))) + :bind + (:map org-roam-mode-map + ( + <<org-roam-bindings>> + ) + :map org-mode-map + ( + <<org-roam-bindings>> + ))) +#+end_src + +#+begin_src emacs-lisp :tangle no :noweb-ref org-roam-bindings +("C-c n f" . org-roam-node-find) +("C-c n i" . org-roam-node-insert) +("C-c n t" . org-roam-buffer-toggle) +("C-c n c" . org-roam-capture) +#+end_src +#+begin_src emacs-lisp :noweb-ref fpi-bindings :tangle no +(fpi/define-key fpi-map "r" #'org-roam-node-find "Roam") +#+end_src + +#+begin_src emacs-lisp +(use-package org-roam-ui + :straight (:host github :repo "org-roam/org-roam-ui" :branch "main" :files ("*.el" "out")) + :after org-roam + :custom + (org-roam-ui-browser-function #'browse-url-generic)) +#+end_src + +#+begin_src emacs-lisp :tangle no :noweb-ref org-roam-bindings +("C-c n u" . org-roam-ui-mode) +#+end_src + +The idea of ~fpi/org-roam-todo~ is from a post by [[https://oremacs.com/2020/12/31/happy-new-year/][aboabo]]. It lists all open todos in zettelkasten entries and is a (faster) alternative to running an todo agenda with ~org-agenda-files~ set to ~org-roam-directory~. +#+begin_src emacs-lisp :tangle no :noweb-ref org-roam-config +(defun fpi/org-roam-todo () + (interactive) + (setq unread-command-events + (listify-key-sequence (kbd "C-c C-o M->"))) + (counsel-rg "^\\*+ \\(NEXT\\|TODO\\)" org-roam-directory "--sort modified")) +#+end_src + +As =C-c n t= is already taken, use =o= (mnemonic: “open”) instead. +#+begin_src emacs-lisp :tangle no :noweb-ref org-roam-bindings +("C-c n o" . fpi/org-roam-todo) +#+end_src + +**** org-roam capture templates +Here we define some capture templates for roam files. Using variables in the source block header we can define the template contents in quote blocks below. + +#+HEADER: :var default=org-roam-template-default ref=org-roam-template-ref +#+HEADER: :var entities=org-roam-template-entities work=org-roam-template-work +#+HEADER: :var personal=org-roam-template-personal private=org-roam-template-private +#+NAME: org-roam-capture-templates +#+begin_src emacs-lisp :tangle no :noweb yes :results code silent +`( + ("d" "Default (avoid this)" plain "%?" + :if-new (file+head "%<%Y%m%d%H%M%S>-${slug}.org" ,default) + :unnarrowed t) + ("l" "Link/Reference" plain "%?" + :if-new (file+head "Ref/${slug}.org" ,ref) + :unnarrowed t) + ("e" "Entity (Person, Company, …)" plain "%?" + :if-new (file+head "Entities/${slug}.org" ,entities) + :unnarrowed t) + ("w" "Work related zettel" plain "%?" + :if-new (file+head "Work/%<%Y%m%d%H%M%S>-${slug}.org" ,work) + :unnarrowed t) + ("p" "Personal/Non-work related zettel" plain "%?" + :if-new (file+head "Personal/%<%Y%m%d%H%M%S>-${slug}.org" ,personal) + :unnarrowed t) + ("P" "Private zettel" plain "%?" + :if-new (file+head "Personal/Private/%<%Y%m%d%H%M%S>-${slug}.org" ,private) + :unnarrowed t) + ) +#+end_src + +As capture templates get more complex storing the template itself in a separate file – or org-babel source block – can be helpful. Above are my (all very similar) template definitions; below the template contents. + +#+NAME: org-roam-template-default +#+begin_quote +#+title: ${title} +#+end_quote +#+NAME: org-roam-template-ref +#+begin_quote +:PROPERTIES: +:ROAM_REFS: ${ref} +:END: +#+title: ${title} +#+end_quote +#+NAME: org-roam-template-entities +#+begin_quote +#+FILETAGS: entity +#+title: ${title} +#+end_quote +#+NAME: org-roam-template-work +#+begin_quote +#+FILETAGS: work +#+title: ${title} +#+end_quote +#+NAME: org-roam-template-personal +#+begin_quote +#+FILETAGS: personal +#+title: ${title} +#+end_quote +#+NAME: org-roam-template-private +#+begin_quote +#+FILETAGS: personal private +#+title: ${title} +#+end_quote +**** org-roam-protocol +#+begin_src emacs-lisp +(use-package org-roam-protocol + :after org-roam + :custom (org-roam-capture-ref-templates + '(("zr" "roam ref" plain "%?" + :if-new (file+head "Ref/${slug}.org" + "#+title: ${title}") + :unnarrowed t) + ("zf" "roam fleeting ref" plain "%?" + :if-new (file+head "Fleeting/${slug}.org" + "#+title: ${title}") + :unnarrowed t)))) +#+end_src +**** org-roam-bibtex +#+begin_src emacs-lisp +(use-package org-roam-bibtex + :straight t + :delight + :hook (org-roam-mode . org-roam-bibtex-mode) + :bind (:map org-mode-map + (("C-c n a" . orb-note-actions))) + :after (bibtex org-roam) + :custom + <<orb-custom>> + :config + <<orb-config>>) +#+end_src +Rewrite of ~bibtex-autokey-get-year~ is a crude way to get bibtex to recognize =date= fields as year. + +Upon showing the notes of an entry with org-ref an appropriate org-roam note file is automatically created using ~orb-edit-notes~. Here I customize the template for my use. +#+begin_src emacs-lisp :tangle no :noweb-ref orb-custom +(orb-templates + '(("r" "ref" plain #'org-roam-capture--get-point + "\n%?\n\n#+BEGIN_SRC bibtex\n%(fpi/orb-capture--get-bibtex-entry)\n#+END_SRC" + :file-name "${citekey}" :head "#+TITLE: %(fpi/orb-capture--get-first-citekey): ${title}\n#+ROAM_KEY: ${ref} +" :unnarrowed t)) +) +#+END_SRC +Here are the functions used. +#+BEGIN_SRC emacs-lisp :tangle no :noweb-ref orb-config +(defun fpi/orb-capture--get-bibtex-entry () + "Return bibtex entry for the roam citekey in current buffer" + (save-excursion + (goto-char (point-min)) + (when (re-search-forward "^#\\+ROAM_KEY: cite:\\(.*?\\)[\s\n]") + (let ((key (match-string 1))) + (org-ref-get-bibtex-entry key))))) +(defun fpi/orb-capture--get-first-citekey () + "Return first part of the roam citekey in current buffer" + (save-excursion + (goto-char (point-min)) + (when (re-search-forward "^#\\+ROAM_KEY: cite:\\(.*?\\)[\s\n]") + (let ((key (match-string 1))) + (when (string-match "^\\(.*?\\)_" key) (match-string 1 key)))))) +#+end_src +*** Org-edna +:PROPERTIES: +:ID: fd3936c7-9fc5-42d0-990d-32024e23b22f +:END: +=Org-edna= is a great tool to manage =TODO= dependencies. I mainly use it to mark tasks as =NEXT= after switching another task to =DONE=. The functions below are taken from Josh's Emacs Config over at [[https://github.com/mm--/dot-emacs/blob/master/jmm-org-config.org][Github]]. He wrote a =edna-finder= which allows link descriptions and a nice hydra to manage the various =org-edna= properties. I call it in my [[id:22750e48-aaee-4f60-bdce-1d511ebe3375][context aware hydra]] when on an org headline. For more functions and explanations checkout his config. +#+begin_src emacs-lisp +(use-package org-edna + :straight t + :after org + :delight + :config + (org-edna-load) + (defun org-edna-finder/link-ids (&rest ids) + "Find a list of headlines with given IDs. + +Unlike `org-edna-finder/ids', IDS here can be links of the form \"[[id:UUID][Headline]]\" (in quotes). +This allows for easier readability of targets." + (mapcar (lambda (id) (save-window-excursion + (org-open-link-from-string id) + (point-marker))) + ids)) + (defun jmm/org-edna-set-trigger-and-point (triggervalue) + "Set the TRIGGER property to TRIGGERVALUE. Move the point to +the newly set value. Open the PROPERTIES drawer." + (let ((property "TRIGGER")) + (org-entry-put (point) property triggervalue) + (org-back-to-heading t) + (let* ((beg (point)) + (range (org-get-property-block beg 'force)) + (end (cdr range)) + (case-fold-search t)) + (goto-char (1- (car range))) ;Need to go one character back to get property-drawer element + (let ((element (org-element-at-point))) + (when (eq (org-element-type element) 'property-drawer) + (org-flag-drawer nil element))) + (goto-char (car range)) + (re-search-forward (org-re-property property nil t) end t)))) + (defun jmm/org-edna-chain-next () + "Set TRIGGER to chain next" + (interactive) + (jmm/org-edna-set-trigger-and-point "next-sibling todo!(NEXT) chain!(\"TRIGGER\")")) + (defun jmm/org-pop-stored-link () + "Get the string for the previously stored link, then remove it from `org-stored-links'" + (let* ((firstlink (car org-stored-links)) + (link (car firstlink)) + (desc (cadr firstlink))) + (setq org-stored-links (delq (assoc link org-stored-links) + org-stored-links)) + (org-make-link-string link desc))) + (defun jmm/org-edna-link (&optional rest) + "Set TRIGGER to chain next. With option" + (interactive) + (jmm/org-edna-set-trigger-and-point + (format "link-ids(\"%s\")%s" (jmm/org-pop-stored-link) (if rest (concat " " rest) "")))) + (defhydra fpi/org-edna-hydra (:color blue :hint nil) + " +Org Edna + _l_: Link _P_: N+p + _L_: Link NEXT _p_: Parent DONE + _n_: Sibling NEXT ^ ^ + _N_: Chain sibling NEXT _q_: quit +" + ("l" jmm/org-edna-link) + ("L" (jmm/org-edna-link "todo!(NEXT)")) + ("n" (jmm/org-edna-set-trigger-and-point "next-sibling todo!(NEXT)")) + ("N" (jmm/org-edna-set-trigger-and-point "next-sibling todo!(NEXT) chain!(\"TRIGGER\")")) + ("P" (jmm/org-edna-set-trigger-and-point "if next-sibling todo-state?(HOLD) then else next-sibling todo!(NEXT) endif next-sibling chain!(\"TRIGGER\") if siblings then parent todo!(DONE) endif")) + ("p" (jmm/org-edna-set-trigger-and-point "parent todo!(DONE)")) + ("q" nil))) +#+end_src +*** org-attach +=org-attach= is useful to attach reference material to org files. This can be reference images, data or other files. A special link type is available for attached files: ~[[attachment:file]]~. + +- Inheritance :: Note that inheritance here means, that the attachment dir of all children is set to that of the parent. +- Attachment Folder :: While I do not like the default double nested + folder structure it creates, I also do not want to set an individual + =DIR= property for all headings I want to attach something to. + Instead I define a new function to use the uuid directly as the + folder name. +#+begin_src emacs-lisp +(use-package org-attach + :custom + (org-attach-use-inheritance t) + (org-attach-preferred-new-method 'id) + (org-attach-store-link-p t) + :config + (defun fpi/org-attach-id-folder-format (id) + id) + (defun fpi/org-attach-id-ts-folder-format (id) + "Timestamp id converter to ids generated in the \"%FT%T%z\" format." + (format "%s/%s" + (substring id 0 7) + (substring id 8))) + (add-to-list 'org-attach-id-to-path-function-list 'fpi/org-attach-id-folder-format) + (add-to-list 'org-attach-id-to-path-function-list 'fpi/org-attach-id-ts-folder-format)) +#+end_src +=org-attach-git= auto-commits changes to attachments if the directory +is a git repository. I want every attachments to be saved using +=git-annex=. I stopped using this because the buildin =git annex +assistant= seems like a better choice, as it also handles automatic +content syncing upon commit. +#+begin_src emacs-lisp :tangle no +(use-package org-attach-git + :custom + (org-attach-git-annex-cutoff 0)) +#+end_src +Also exclude =ATTACH= from the inherited tags +#+begin_src emacs-lisp :tangle no :noweb-ref org-custom-no-inheritance-tags +"ATTACH" +#+end_src +*** Org-Capture +#+BEGIN_SRC emacs-lisp +(setq org-journal-file (format "~/sync/journal/%s.org" (nth 2 (calendar-current-date)))) +(use-package org-capture + :after org + :custom + ( + (org-capture-templates + `( +<<org-capture-templates>>)) + (org-capture-templates-contexts + '( + <<org-capture-templates-contexts>>)))) +#+END_SRC + +**** Templates +:PROPERTIES: +:header-args:emacs-lisp: :eval never :noweb yes +:END: +***** Journal +Capture templates for journal entries. Mostly to just keep track of things I have looked at and which may be interesting later, but do not warrant a zettel right now. +#+BEGIN_SRC emacs-lisp :tangle no :noweb-ref org-capture-templates +("j" "Journal") +("jj" "Link Current buffer" + entry + (file+olp+datetree + ,org-journal-file) + ;; "** %<%H:%M> %a\n %i%? \n%:description\n%:elfeed-entry-content\n%:elfeed-entry-date\n%:elfeed-entry-meta\n%:elfeed-entry-title\n%:elfeed-entry-enclosures\n%:elfeed-entry-tags" ) + "** %a +:PROPERTIES: +:CREATED: %U +:END: +%i%?" ) +("je" "Manual Entry" + entry + (file+olp+datetree + ,org-journal-file) + "** %? +:PROPERTIES: +:CREATED: %U +:END: +%i" ) +#+END_SRC +To get the title from the url in =kill-ring= I use [[id:dc4129ff-6d76-4f12-926f-c62a687a39ec][org-web-tools]]. +#+BEGIN_SRC emacs-lisp :tangle no :noweb-ref org-capture-templates +("jw" "Web Link from kill-ring" + entry + (file+olp+datetree + ,org-journal-file) + "** %(org-web-tools--org-link-for-url (org-web-tools--get-first-url))%? +:PROPERTIES: +:CREATED: %U +:END: +%i") +#+END_SRC +***** Clock +#+begin_src emacs-lisp :tangle no :noweb-ref org-capture-templates +("c" "Clock" + plain + (file "~/sync/refile.org") + "%(fpi/org-clock-in-heading)") +#+end_src +***** Interrupts +For interruptions. These are saved in a global refile file and to be sorted to their appropriate place. +#+BEGIN_SRC emacs-lisp :tangle no :noweb-ref org-capture-templates +("i" "Interrupt" + entry + (file "~/sync/refile.org") + "** %? +:PROPERTIES: +:CREATED: %U +:SOURCE: %a +:END: +:LOGBOOK: +:END: +" + :clock-in t + :clock-resume t) +#+END_SRC +***** Appointments +#+BEGIN_SRC emacs-lisp :tangle no :noweb-ref org-capture-templates +("a" "Appointment" + entry + (id "802014b3-fddf-4090-b140-7fb62cb982f2") + "** %? +:PROPERTIES: +:CREATED: %U +:DATE: %^t +<<org-capture-template-properties>> +:SOURCE: %a +:END: +" + ) +#+END_SRC +***** Tasks +Instead of project related capture templates, I use the same template for all tasks and refile them manually to where they belong. +#+BEGIN_SRC emacs-lisp :tangle no :noweb-ref org-capture-templates +("t" "Task" + entry + (file "~/sync/refile.org") + "** NEXT %? +:PROPERTIES: +:CREATED: %U +<<org-capture-template-properties>> +:SOURCE: %a +:END: +%i") +#+END_SRC +***** Plans & Ideas +#+BEGIN_SRC emacs-lisp :tangle no :noweb-ref org-capture-templates +("P" "Plans/Ideas" + entry + (file "~/sync/refile.org") + "*** PLANNING %? +:PROPERTIES: +:CREATED: %U +<<org-capture-template-properties>> +:SOURCE: %a +:END: +%i") +#+END_SRC +***** Reply to Mail +#+BEGIN_SRC emacs-lisp :tangle no :noweb-ref org-capture-templates +("r" "Respond" entry (file "~/sync/refile.org") + "* NEXT Respond to %:from on %:subject +:PROPERTIES: +:CREATED: %U +<<org-capture-template-properties>> +:END: +%a" :immediate-finish t) +#+END_SRC + +#+BEGIN_SRC emacs-lisp :tangle no :noweb-ref org-capture-templates-contexts +("r" ((in-mode . "gnus-summary-mode") + (in-mode . "gnus-article-mode"))) +#+END_SRC +***** Interesting stuff I have to look at later +#+BEGIN_SRC emacs-lisp :tangle no :noweb-ref org-capture-templates +("C" "Checkout") +("Cr" ".. & read" + entry + (file "~/sync/refile.org") + "* TODO %a :read: +:PROPERTIES: +:CREATED: %U +<<org-capture-template-properties>> +:SOURCE: %a +:END: +%? +") +#+END_SRC +***** Ledger transactions +#+BEGIN_SRC emacs-lisp :tangle no :noweb-ref org-capture-templates +("l" "Ledger") + ("lb" "Bank" plain (file ,(format "~/.personal/f/%s.ledger" (format-time-string "%Y"))) + ,private/org-ledger-card-template + :empty-lines 1 + :immediate-finish t) + ("lc" "Cash" plain (file ,(format "~/.personal/f/%s.ledger" (format-time-string "%Y"))) + ,private/org-ledger-cash-template + :empty-lines 1 + :immediate-finish t) +#+END_SRC +***** org-protocol +:PROPERTIES: +:ID: 28704dfb-7647-43ac-b96f-5967383d1188 +:END: +Org-protocol is an easy way to capture stuff from outside emacs. +#+begin_src emacs-lisp :tangle tangle/emacs-10-init.el :eval yes :results silent +(use-package org-protocol) +#+end_src +To install the handler for =org-protocol://= URIs under linux you probably need a =.desktop= file similar to the one below. Place it under =~/.local/share/applications= and run src_shell{update-desktop-database}. +# #+HEADER: :tangle ~/.local/share/applications/org-protocol.desktop +#+begin_src conf +[Desktop Entry] +Version=1.0 +Encoding=UTF-8 +Name=Org Protocol +Comment=OrgProtocol URI handler +Exec=/home/fpi/.local/bin/emacsclient %u +Type=Application +Terminal=false +MimeType=x-scheme-handler/org-protocol;⏎ +#+end_src +Under Windows install a registry key. The example below works for Emacs running under WSL. Place it in a =.reg= file and open it with the registry editor to install. +# #+HEADER: :tangle ~/win/tmp/org-protocol.reg +#+begin_src conf +REGEDIT4 + +[HKEY_CLASSES_ROOT\org-protocol] +@="URL:Org Protocol" +"URL Protocol"="" +[HKEY_CLASSES_ROOT\org-protocol\shell] +[HKEY_CLASSES_ROOT\org-protocol\shell\open] +[HKEY_CLASSES_ROOT\org-protocol\shell\open\command] +@="\"C:\\Windows\\System32\\wsl.exe\" emacsclient \"%1\"" +#+end_src + +To be compatible with [[https://github.com/sprig/org-capture-extension][this chromium/firefox extension]] I use these capture templates: +#+begin_src emacs-lisp :tangle no :noweb-ref org-capture-templates + ("p" "Protocol" entry (file+olp+datetree ,org-journal-file) + "* %^{Title} +:PROPERTIES: +:SOURCE: %c +:CREATED: %U +:END: +#+BEGIN_QUOTE\n%i\n#+END_QUOTE\n\n\n%?") +("L" "Protocol Link" entry (file+olp+datetree ,org-journal-file) + "* %? [[%:link][%:description]] +:PROPERTIES: +:CREATED: %U +:ID: %(org-id-new) +:ROAM_REFS: %:link +:END: +") +#+end_src +***** Old templates +Templates I no longer use, but may be interesting. +#+BEGIN_SRC emacs-lisp :tangle no +("n" "note" entry (file "~/sync/refile.org") + "* %? :NOTE:\n%U\n%a\n" :clock-in t :clock-resume t) +("j" "Journal/Interruptions" entry (file+olp+datetree "~/sync/diary.org") + "* %?\n%U\n" :clock-in t :clock-resume t) +("h" "Habit" entry (file "~/sync/refile.org") + "* NEXT %?\n%U\n%a\nSCHEDULED: %(format-time-string \"%<<%Y-%m-%d %a .+1d/3d>>\")\n:PROPERTIES:\n:STYLE: habit\n:REPEAT_TO_STATE: NEXT\n:END:\n") +("m" "Meeting" entry (file "~/sync/refile.org") + "* MEETING with %? :MEETING:\n%U" :clock-in t :clock-resume t) +("p" "Phone call" entry (file "~/sync/refile.org") + "* PHONE %? :PHONE:\n%U" :clock-in t :clock-resume t) + +("c" "Item to Current Clocked Task" item (clock) + "%i%?" :empty-lines 1) +("K" "Kill-ring to Current Clocked Task" plain (clock) + "%c" :immediate-finish t :empty-lines 1) +("p" "Gcal Appointment" entry (file "~/.emacs.d/gcal.org") + "* %?\n%^T\n") +("z" "Zettel" entry (file "~/zettel.org") + "* %i%? %(and (org-id-get-create) nil) +:PROPERTIES:\n:CREATED: %u\n:END:\n") +#+END_SRC +**** Setup for floating capture window +For reference see [[https://www.windley.com/archives/2010/12/capture_mode_and_emacs.shtml][here]]. +#+begin_src emacs-lisp +(defun fpi/make-floating-frame (&optional width height minibuffer name) + (interactive) + (let ((width (or width 80)) + (height (or height 36)) + (name (or name "*Floating Emacs*"))) + (make-frame `((name . ,name) + (window-system . x) + (width . ,width) + (height . ,height) + (minibuffer . ,minibuffer))))) + +(defadvice org-capture-finalize + (after delete-capture-frame activate) + "Advise capture-finalize to close the frame" + (if (equal "*Capture*" (frame-parameter nil 'name)) + (delete-frame))) +(defadvice org-capture-destroy + (after delete-capture-frame activate) + "Advise capture-destroy to close the frame" + (if (equal "*Capture*" (frame-parameter nil 'name)) + (delete-frame))) +(defun fpi/make-floating-capture-frame () + (interactive) + (select-frame (fpi/make-floating-frame 70 20 t "*Capture*")) + (add-hook 'org-capture-mode-hook 'delete-other-windows) + (org-capture) + (remove-hook 'org-capture-mode-hook 'delete-other-windows)) +#+end_src +*** Org Expiry +This is an easy way to (semi-)automatically archive no longer relevant entries. + +I want to archive entries sometime after they are set to =DONE=. I first thought about using [[id:fd3936c7-9fc5-42d0-990d-32024e23b22f][Org Edna]]'s =TRIGGER= keyword: +: :TRIGGER: self set-property("EXPIRY" "some-date") +But unfortunately it does not support evaluating lisp for the property value. Therefore either an absolute expiry date has to be known when setting the =TRIGGER= or one needs to use a relative date. + +To come by with relatives dates I use the =CLOSED= property as reference for org-expiry when evaluating relative timestamps. The relative timestamp can then already be set directly in the capture template. Ten days gives me enough time to check whether the content is no longer important and to review the clocked times. +#+begin_src fundamental :noweb-ref org-capture-template-properties +:EXPIRY: +10d +#+end_src +As I do not always mark appointments as =DONE=, I set the =CLOSED= property already in the capture template (to the same time as the actual date). This is currently bugged.. +#+begin_src fundamental :noweb-ref org-capture-template-closed +CLOSED: %\\1 +#+end_src + +#+begin_src emacs-lisp +(use-package org-expiry + :after org + :straight + (org-contrib) + :custom + (org-expiry-handler-function 'org-expiry-archive-subtree) + (org-expiry-inactive-timestamps t) + (org-expiry-created-property-name "CLOSED")) +;; (defun fpi/org-insert-expiry (&optional date) +;; (interactive) +;; (let ((date (or date "fri"))) +;; (with-temp-buffer +;; (org-insert-time-stamp (org-read-date nil t "fri") nil t) +;; (buffer-string)))) +#+end_src +(org-read-date nil nil ".") +*** org-mime +Set ~:preserve-breaks~ to keep line breaks in the html output. =org-mime-export-options= supports the same options as documented in =org-export-options-alist=. +#+begin_src emacs-lisp +(use-package org-mime + :straight t + :custom ((org-mime-export-options + '(:with-latex dvipng + :preserve-breaks t)))) +#+end_src +*** Ricing +#+begin_src emacs-lisp +(setq line-spacing 0.1) +(setq header-line-format " ") +;; (set-face-attribute 'header-line nil :height 50) ;; make buffer-local first + +;; side padding +(lambda () + (progn + (setq left-margin-width 2 + right-margin-width 2) + (set-window-buffer nil (current-buffer)))) + +;; try writeroom-mode +#+end_src +*** Org crypt +A small function to toggle the encryption state of the current entry. +#+begin_src emacs-lisp +(use-package org-crypt + :config + (defun fpi/org-toggle-crypt-entry () + "Encrypt/Decrypt current headline." + (interactive) + (require 'epg) + (when (eq major-mode 'org-mode) + (unless (org-before-first-heading-p) + (org-with-wide-buffer + (org-back-to-heading t) + (org-end-of-meta-data) + (if (looking-at-p "-----BEGIN PGP MESSAGE-----") + (org-decrypt-entry) + (org-encrypt-entry)))))) + (fpi/define-key fpi/toggle-map "e" #'fpi/org-toggle-crypt-entry "Encrypt")) +#+end_src +*** Reference management +**** Bibtex +#+begin_src emacs-lisp +(use-package bibtex + :custom + (bibtex-completion-library-path "~/git/projects/personal/Lit") + <<bibtex-custom>> + :config + (bibtex-set-dialect 'BibTeX)) + +(setq bibtex-completion-bibliography + (if (equal fpi/current-device "DESKTOP-PM1PPEC") + '("~/git/projects/personal/bib.bib" + "~/win/Zotero/biblatex/00_Unsorted.bib" + "~/win/Zotero/biblatex/01_Annotated.bib" + "~/win/Zotero/biblatex/99_AllZotero.bib") + '("~/git/projects/personal/bib.bib"))) +(setq bibtex-completion-notes-path "~/git/projects/zettel/Lit") +(setq bibtex-completion-notes-extension ".org") +#+end_src + +The bibtex package provides a customizable implementation for key generation with ~bibtex-generate-autokey~. +#+begin_src emacs-lisp :noweb-ref bibtex-custom :tangle no +(bibtex-autokey-year-title-separator "_") +(bibtex-autokey-title-terminators ".$") +(bibtex-autokey-titlewords 3) +(bibtex-autokey-titlewords-stretch 1) +(bibtex-autokey-titleword-length 5) +#+end_src +We can also +#+begin_src emacs-lisp :noweb-ref orb-custom :tangle no +(orb-autokey-format "%e{(bibtex-generate-autokey)}") +#+end_src +**** Org Cite +=org-ref= was replaced by =org-cite= which is built into =org=. + +#+begin_src emacs-lisp :noweb yes +(use-package oc + :after (org bibtex) + :custom + (org-cite-global-bibliography bibtex-completion-bibliography) + (org-cite-export-processors + '((latex biblatex "ieee") + (t basic))) + <<org-cite-custom>> + ) +#+end_src + +=Citar= is a package that provides extra actions on org cite links. + +#+begin_src emacs-lisp +(use-package citar + :straight t + :after oc + :custom + (citar-bibliography org-cite-global-bibliography) + (citar-library-paths '("~/git/projects/annex_work/Lit")) + (citar-notes-paths '("~/git/projects/zettel/Lit")) + ;; (citar-at-point-function 'embark-act) + (citar-templates + '((main . "${author editor:30} ${date year issued:4} ${title:48}") + (suffix . " ${=key= id:15} ${=type=:12} ${tags keywords keywords:*}") + (preview . "${author editor} (${year issued date}) ${title}, ${journal journaltitle publisher container-title collection-title}. +") + (note . "${=key=}: ${title}") + )) + ;; (citar-symbols + ;; `((file (?📁) . " ") + ;; (note (?📓) . " ") + ;; (link (?🔗) . " "))) + ;; (citar-symbol-separator " ") + ) +#+end_src + +Lets customize =org-cite= to use =citar= by default. + +#+begin_src emacs-lisp :noweb-ref org-cite-custom :tangle no +(org-cite-insert-processor 'citar) +(org-cite-follow-processor 'citar) +(org-cite-activate-processor 'citar) +#+end_src + +We also make =org-roam-bibtex= compatible with =org-cite= by changing the cite format: +#+begin_src emacs-lisp :noweb-ref orb-custom :tangle no +(orb-pdf-scrapper-citekey-format "[cite:@%s]") +#+end_src + +***** Capturing entries +I store my bibtex references in an org file together with my notes. In +addition to saving the meta information in properties using the same +functions as =doi-utils-doi-to-org-bibtex=, I also store them a second +time in a bibtex src block in the heading. The src blocks are tangled +to compile into a separate =.bib= file. The function below creates new +entries from a given doi and is called in my respective capture +template. + +Here is my capture template. +#+BEGIN_SRC emacs-lisp :tangle no :noweb-ref org-capture-templates +("b" "Bibtex entry" + entry + (id "efc97963-b714-4020-94b6-c23ad2a286ee") + (function fpi/add-org-from-doi)) +#+END_SRC +And the function to create the file. +#+begin_src emacs-lisp +(defun fpi/add-org-from-doi (&optional doi) + "Get bibtex entry from doi and format as Org header with +properties and additional bibtex src block. Also downloads the +pdf if available." + (let* ((doi (or doi (read-string "Enter doi: "))) + (content (replace-regexp-in-string "\n$" "" (doi-utils-doi-to-bibtex-string doi))) + (cleaned (with-temp-buffer + (insert content) + (org-ref-clean-bibtex-entry) + (org-bibtex-read) + (buffer-substring (point-min) (point-max))))) + (with-temp-buffer + (org-mode) + (org-bibtex-write) + (goto-char (point-max)) + (insert "#+BEGIN_SRC bibtex\n") + (insert cleaned) + (insert "\n#+END_SRC\n") + (org-demote) + (buffer-substring (point-min) (point-max))))) +#+end_src +Here's a function to easily copy a doi from the results of =crossref-lookup=. +#+begin_src emacs-lisp +(defun fpi/biblio-get-doi () + (interactive) + (let ((doi (alist-get 'doi (cdr (biblio--selection-metadata-at-point))))) + (kill-new doi) + (message "Copied doi %s" doi))) +(use-package biblio + :bind (:map biblio-selection-mode-map + ("d" . fpi/biblio-get-doi))) +#+end_src +***** org-protocol conversion +Capturing new entries with org-protocol is convenient. To convert the result of [[id:28704dfb-7647-43ac-b96f-5967383d1188][my capture templates]] to a valid entry, we have to extract the doi. +#+begin_src emacs-lisp +(defun fpi/ieee-to-doi (url) + "Get doi from an ieeexplore.ieee.org page." + (let* ((meta (with-current-buffer (url-retrieve-synchronously url) + (goto-char 1) + (search-forward "global.document.metadata=") + (kill-sexp) + (pop kill-ring))) + (json (json-read-from-string meta))) + (alist-get 'doi json))) +#+end_src +Other keys which IEEE returns are: +#+begin_example +(mapcar (lambda (l) (car l)) json) +(userInfo authors isbn articleNumber dbTime metrics purchaseOptions getProgramTermsAccepted sections formulaStrippedArticleTitle allowComments pdfUrl keywords abstract pubLink doiLink rightsLink pdfPath startPage endPage publicationTitle displayPublicationTitle doi issueLink isGetArticle isGetAddressInfoCaptured isMarketingOptIn applyOUPFilter pubTopics publisher isOUP isFreeDocument isSAE isNow isCustomDenial conferenceDate isDynamicHtml isStandard displayDocTitle isNotDynamicOrStatic isPromo htmlAbstractLink xploreDocumentType chronOrPublicationDate isConference isOpenAccess persistentLink isEarlyAccess htmlLink publicationDate isJournal isBook isBookWithoutChapters isChapter isStaticHtml isMorganClaypool isProduct isEphemera accessionNumber dateOfInsertion isACM isSMPTE startPage openAccessFlag ephemeraFlag title confLoc accessionNumber html_flag ml_html_flag sourcePdf content_type mlTime chronDate xplore-pub-id pdfPath isNumber rightsLinkFlag dateOfInsertion contentType publicationDate publicationNumber citationCount xplore-issue articleId publicationTitle sections onlineDate conferenceDate publicationYear subType _value lastupdate mediaPath endPage displayPublicationTitle doi) +#+end_example +Combining this with other functions allows us to do the whole conversion. In the future the citation information can be directly from extracted from the retrieved webpage instead of over the doi. +#+begin_src emacs-lisp +(defun fpi/convert-capture-bib () + "Convert current org-protocol ieee capture to bib." + (interactive) + (let ((rep (fpi/get-capture-bib-replacement))) + (kill-region (point-min) (point-max)) + (insert rep) + )) +(defun fpi/get-capture-bib-replacement () + (save-excursion + (goto-char (point-min)) + (org-next-link) + (let* ((link (org-element-context)) + (url (concat (org-element-property :type link) + ":" + (org-element-property :path link)))) + (fpi/add-org-from-doi + (fpi/ieee-to-doi url))))) + +(defun fpi/format-org-roam-from-doi (&optional doi) + "Get bibtex entry from doi and format for org-roam. Also downloads the +pdf if available." + (let* ((doi (or doi (read-string "Enter doi: "))) + (content (replace-regexp-in-string "\n$" "" (doi-utils-doi-to-bibtex-string doi))) + (cleaned (with-temp-buffer + (insert content) + (org-ref-clean-bibtex-entry) + (org-bibtex-read) + (buffer-substring (point-min) (point-max)))) + (parsed (reftex-parse-bibtex-entry cleaned)) + (key (org-ref-reftex-get-bib-field "&key" parsed)) + (first (when (string-match "^\\(.*?\\)_" key) (match-string 1 key))) + (title (org-ref-reftex-get-bib-field "title" parsed))) + (setq fpi//capture-bibtex-key key) + (with-temp-buffer + (org-mode) + (insert (format "#+TITLE: %s: %s\n" first title)) + (insert (format "#+ROAM_KEY: cite:%s\n\n" key)) + ;; (org-bibtex-write) + (goto-char (point-max)) + (insert "#+BEGIN_SRC bibtex\n") + (insert cleaned) + (insert "\n#+END_SRC\n") + (list key + (buffer-substring (point-min) (point-max)))))) + +(defun fpi/org-roam-format-from-doi (&optional doi) + (let* ((doi (or doi (read-string "Enter doi: ")))) + (setq fpi/org-roam-last-captured-doi doi) + (fpi/format-org-roam-from-doi doi))) + +(defvar fpi/org-roam-last-content nil) +(defvar fpi/org-roam-last-key nil) +(defun fpi/org-roam-get-key (doi) + (let* ((resp (fpi/format-org-roam-from-doi doi)) + (key (car resp)) + (content (cadr resp))) + (setq fpi/org-roam-last-content content) + key)) +(defun fpi/org-roam-get-last-content () + fpi/org-roam-last-content) +(defun fpi/org-roam-get-last-key () + fpi/org-roam-last-key) +(defun fpi/org-roam-get-content (doi) + (let* ((resp (fpi/format-org-roam-from-doi doi)) + (key (car resp)) + (content (cadr resp))) + (setq fpi/org-roam-last-content content) + (setq fpi/org-roam-last-key key) + content)) + +(defun fpi/create-org-roam-from-doi (&optional doi) + (interactive) + (let* ((resp (fpi/format-org-roam-from-doi doi)) + (key (car resp)) + (content (cadr resp))) + (find-file (expand-file-name (format "Lit/%s.org" key) org-roam-directory)) + (org-mode) + (insert content))) + +(defun fpi/create-org-roam-from-protocol-capture () + "Create a org-roam entry from an org-protocol capture buffer." + (interactive) + (save-excursion + (goto-char (point-min)) + (org-next-link) + (let* ((link (org-element-context)) + (url (concat (org-element-property :type link) + ":" + (org-element-property :path link)))) + (fpi/create-org-roam-from-doi + (fpi/ieee-to-doi url))))) +#+end_src +*** Toggle drawer visibility +#+begin_src emacs-lisp +(setq fpi/org-meta-heading-info-store nil) +(make-variable-buffer-local 'fpi/org-meta-heading-info-store) +(defun mw-org-hide-meta-heading-info () + "Hide meta data following headings." + (interactive) + (org-save-outline-visibility t + (save-excursion + ;; (widen) + ;; (org-cycle '(64)) + ;; (org-show-all '(drawers)) ; expand all props before make invisible to avoid ellipses. + (goto-char (point-min)) + (unless (org-at-heading-p) (outline-next-heading)) + (while (not (eobp)) + (let ((beg (1+ (progn (end-of-line) (point)))) + (end (1- (progn (org-end-of-meta-data t) (point))))) + (when (< beg end) + (push (make-overlay beg end) fpi/org-meta-heading-info-store) + (overlay-put (car fpi/org-meta-heading-info-store) 'invisible t))) + (when (not (org-at-heading-p)) + (outline-next-heading)))))) + +(defun mw-org-show-meta-info-lines () + "Show meta info." + (interactive) + (mapc #'delete-overlay fpi/org-meta-heading-info-store) + (setq fpi/org-meta-heading-info-store nil)) + + +(defun fpi/org-toggle-meta-info-lines () + (interactive) + (if fpi/org-meta-heading-info-store + (mw-org-show-meta-info-lines) + (mw-org-hide-meta-heading-info))) +(fpi/define-key fpi/toggle-map "m" #'fpi/org-toggle-meta-info-lines "Metalines (org)") +#+end_src +*** Table of contents in org +#+begin_src emacs-lisp +(use-package toc-org + :straight t + :hook (org-mode . toc-org-mode)) +#+end_src +*** Workflow +My current workflow is largely inspired by [[http://doc.rix.si/cce/cce-org.html][Ryan Rix's]] and [[http://doc.norang.ca/org-mode.html][Bernt +Hansen's]] configs. + +First set the ids of some default and often referenced tasks. +#+begin_src emacs-lisp +(setq fpi/organization-task-id "52ac704f-9cc4-4291-9721-aa3cd3b34fae") +(setq fpi/lunch-task "e3d95e3b-416d-4265-835b-1ba57aa84704" + fpi/break-task "fede843d-02fc-4cdd-8a63-91905e727dab" + ;; fpi/prep-task "9d6279b8-c921-46e7-8ee4-b4d367dca1e0" + fpi/morning-flow "2bec1c12-2ee5-4f50-9eac-a018ca081d7d" + ) +#+end_src + +This hydra contains most parts of my current workflow. It has +everything from going to certain headlines, clocking time and +capturing notes. +#+begin_src emacs-lisp +(defhydra hydra-workflow (:hint nil) + " +Searching ----------> Do stuff --------> Do Stuff 2 -------> Workflow ---------------> Nar/Wid ------------------> +_i_: In-file headings _d_: Clock in _c_: Capture _m_: Prep meeting notes _n_: Narrow to Subtree +_h_: All headings _e_: Email _<_: Last Task _M_: Mail meeting notes _w_: Widen +_a_: Select an Agenda _l_: Lunch _j_: Jump Clock _B_: BBDB search _r_: Narrow to region +_g_: Go to active clock _b_: Break _P_: Insert BBDB _c_: Capture _t_: Show TODO Entries + _k_: Morning prep _z_: Capture Note _s_: *scratch* + _o_: Clock out _S_: Org Scratch +" + ("<" bh/clock-in-last-task) + ("a" org-agenda :exit t) + ("B" bbdb) + ("b" rrix/clock-in-break-task) ;; TODO + ("c" org-capture) + ("d" bh/punch-in) + ("e" rrix/clock-in-email-task) ;; TODO + ("g" org-clock-goto) + ("h" cce/org-goto-agenda-heading) + ("i" org-goto) + ("j" (progn + (interactive) + (setq current-prefix-arg '(4)) + (call-interactively 'org-clock-in))) + ("k" rrix/clock-morning-prep) + ("l" rrix/clock-in-lunch-task) + ("M" bh/mail-subtree) ;; TODO ;; checkout org-mime + ("m" bh/prepare-meeting-notes) ;; TODO + ("n" bh/narrow-to-subtree) ;; TODO + ("o" bh/punch-out) + ("P" bh/phone-call) ;; TODO + ("r" narrow-to-region) ;; neccessary? + ("S" bh/make-org-scratch) ;; neccessary? + ("s" bh/switch-to-scratch) ;; neccessary? + ("t" bh/org-todo) ;; neccessary? + ("w" bh/widen) ;; neccessary? + ("z" cce/note-to-clock)) +#+end_src + +#+begin_src emacs-lisp :noweb-ref fpi-bindings :tangle no +(fpi/define-key fpi-map (kbd "f") 'hydra-workflow/body "Flow") +#+end_src +Basic flow: +1. Start your work by clocking in with ~bh/punch-in~. This sets a + predefined "Organizational" entry as default clocking entry and + clocks you in on it. +2. To start planning your day go to "Morning prep" or directly start + working on something and clock in on it using either "Jump clock" + or ~org-clock-in~ normally. +3. Do stuff. Change clocks, capture stuff, take notes, take breaks, … +4. At the end of the day clock out with ~bh/punch-out~. + +**** Clocking +While punched in org continues to clock your time. Each time you clock +out of an entry it clocks you in on the parent entry or the default +organizational task. +#+begin_src emacs-lisp +(defun bh/clock-out-maybe () + (when (and bh/keep-clock-running + (not org-clock-clocking-in) + (marker-buffer org-clock-default-task) + (not org-clock-resolving-clocks-due-to-idleness)) + (rrix/clock-in-sibling-or-parent-task))) + +(add-hook 'org-clock-out-hook 'bh/clock-out-maybe 'append) + +(defun rrix/clock-in-sibling-or-parent-task () + "Move point to the parent (project) task if any and clock in" + (let ((parent-task) + (parent-task-is-flow) + (sibling-task) + (curpoint (point))) + (save-excursion + (save-restriction + (widen) + (outline-back-to-heading) + (org-cycle) + (while (and (not parent-task) (org-up-heading-safe)) + (when (member (nth 2 (org-heading-components)) org-todo-keywords-1) + (setq parent-task (point)))) + (goto-char curpoint) + (while (and (not sibling-task) (org-get-next-sibling)) + (when (member (nth 2 (org-heading-components)) org-todo-keywords-1) + (setq sibling-task (point)))) + (setq parent-task-is-flow (cdr (assoc "FLOW" + (org-entry-properties parent-task)))) + (cond ((and sibling-task + parent-task-is-flow) + (org-with-point-at sibling-task + (org-clock-in)) + (org-clock-goto)) + (parent-task + (org-with-point-at parent-task + (org-clock-in)) + (org-clock-goto)) + (t (when bh/keep-clock-running + (bh/clock-in-default-task)))))))) +(defun bh/clock-in-default-task () + (save-excursion + (org-with-point-at org-clock-default-task + (org-clock-in) + (org-clock-goto)))) +#+end_src +Define the punch-in and punch-out functions. +#+begin_src emacs-lisp +(defun bh/punch-in (arg) + (interactive "p") + (setq bh/keep-clock-running t) + (if (equal major-mode 'org-agenda-mode) + (let* ((marker (org-get-at-bol 'org-hd-marker)) + (tags (org-with-point-at marker (org-get-tags-at)))) + (if (and (eq arg 4) tags) + (org-agenda-clock-in '(16)) + (bh/clock-in-organization-task-as-default))) + (save-restriction + (widen) + (if (and (equal major-mode 'org-mode) (not (org-before-first-heading-p)) (eq arg 4)) + (org-clock-in '(16)) + (bh/clock-in-organization-task-as-default))))) + +(defun bh/clock-in-organization-task-as-default () + (interactive) + (org-with-point-at (org-id-find fpi/organization-task-id 'marker) + (org-clock-in '(16)))) + +(defun bh/punch-out () + (interactive) + (setq bh/keep-clock-running nil) + (when (org-clock-is-active) + (org-clock-out)) + (org-agenda-remove-restriction-lock)) +#+end_src +Clocking into a task by id and some default clock-in functions. +The separate functions are needed so they can be used in the hydra. +#+begin_src emacs-lisp +(defun bh/clock-in-task-by-id (id) + "Clock in a task by id" + (org-with-point-at (org-id-find id 'marker) + (org-clock-in nil))) +(setq org-id-link-to-org-use-id 'create-if-interactive-and-no-custom-id) + +(defun rrix/clock-in-lunch-task () + (interactive) + (bh/clock-in-task-by-id fpi/lunch-task)) +(defun rrix/clock-in-break-task () + (interactive) + (bh/clock-in-task-by-id fpi/break-task) + (org-agenda nil "i")) + +(defun rrix/clock-morning-prep () + (interactive) + (bh/clock-in-task-by-id fpi/morning-flow) + (org-clock-goto) + ;; (bh/narrow-to-subtree) + ) +#+end_src +Function to clock into the last task. +#+begin_src emacs-lisp +(defun bh/clock-in-last-task (arg) + "Clock in the interrupted task if there is one +Skip the default task and get the next one. +A prefix arg forces clock in of the default task." + (interactive "p") + (let ((clock-in-to-task + (cond + ((eq arg 4) org-clock-default-task) + ((and (org-clock-is-active) + (equal org-clock-default-task (cadr org-clock-history))) + (caddr org-clock-history)) + ((org-clock-is-active) (cadr org-clock-history)) + ((equal org-clock-default-task (car org-clock-history)) (cadr org-clock-history)) + (t (car org-clock-history))))) + (widen) + (org-with-point-at clock-in-to-task + (org-clock-in nil)))) +#+end_src +Add a note to the current clock +#+begin_src emacs-lisp +(defun cce/note-to-clock () + "Add a note to the currently clocked task." + (interactive) + (save-window-excursion + (org-clock-goto) + (org-add-note))) +#+END_SRC +**** General +Go to any heading in an agenda file (or more specifically in any file +included in 'org-refile-targets) +#+begin_src emacs-lisp +(defun cce/org-goto-agenda-heading (&optional prompt) + (interactive) + (let* ((location (org-refile-get-location (or prompt "Goto"))) + (file (cadr location)) + (marker (car (last location)))) + (find-file file) + (goto-char marker) + (org-show-context) + (current-buffer))) +#+END_SRC +**** Filter functions +Various functions to determine if the current entry is a task, a +project or neither. +#+begin_src emacs-lisp +(defun bh/is-task-p () + "Any task with a todo keyword and no subtask" + (save-restriction + (widen) + (let ((has-subtask) + (subtree-end (save-excursion (org-end-of-subtree t))) + (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1))) + (save-excursion + (forward-line 1) + (while (and (not has-subtask) + (< (point) subtree-end) + (re-search-forward "^\*+ " subtree-end t)) + (when (member (org-get-todo-state) org-todo-keywords-1) + (setq has-subtask t)))) + (and is-a-task (not has-subtask))))) +(defun bh/is-project-p () + "Any task with a todo keyword subtask" + (save-restriction + (widen) + (let ((has-subtask) + (subtree-end (save-excursion (org-end-of-subtree t))) + (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1))) + (save-excursion + (forward-line 1) + (while (and (not has-subtask) + (< (point) subtree-end) + (re-search-forward "^\*+ " subtree-end t)) + (when (member (org-get-todo-state) org-todo-keywords-1) + (setq has-subtask t)))) + (and is-a-task has-subtask)))) +(defun bh/find-project-task () + "Move point to the parent (project) task if any" + (save-restriction + (widen) + (let ((parent-task (save-excursion (org-back-to-heading 'invisible-ok) (point)))) + (while (org-up-heading-safe) + (when (member (nth 2 (org-heading-components)) org-todo-keywords-1) + (setq parent-task (point)))) + (goto-char parent-task) + parent-task))) +(defun bh/is-project-subtree-p () + "Any task with a todo keyword that is in a project subtree. +Callers of this function already widen the buffer view." + (let ((task (save-excursion (org-back-to-heading 'invisible-ok) + (point)))) + (save-excursion + (bh/find-project-task) + (if (equal (point) task) + nil + t)))) +(defun bh/skip-project-tasks () + "Show non-project tasks. +Skip project and sub-project tasks, habits, and project related tasks." + (save-restriction + (widen) + (let* ((subtree-end (save-excursion (org-end-of-subtree t)))) + (cond + ((bh/is-project-p) + subtree-end) + ((org-is-habit-p) + subtree-end) + ((bh/is-project-subtree-p) + subtree-end) + (t + nil))))) +#+end_src +** Deft + +#+begin_quote +Deft is an Emacs mode for quickly browsing, filtering, and editing +directories of plain text notes, inspired by Notational Velocity. It +was designed for increased productivity when writing and taking notes +by making it fast and simple to find the right file at the right time +and by automating many of the usual tasks such as creating new files +and saving files. +#+end_quote + +I use =Deft= to organize my /Zettelkasten/. It contains many single +files about various topics. =Deft= handles searching and file +creation. +#+begin_src emacs-lisp +(use-package deft + :straight t + :custom ((deft-directory "~/git/projects/zettel") + (deft-extensions '("org")) + (deft-default-extension "org") + (deft-use-filename-as-title t) + (deft-recursive t) + (deft-use-filter-string-for-filename t) + <<deft-custom>>)) +#+end_src +Most org files start with meta information on lines starting with ~#+~, but also sometimes ~:PROPERTIES:~ drawers. We can exclude these lines from the preview content =Deft= displays with regular expressions. I first noticed this setting in [[https://github.com/hsinhaoyu/.emacs.d/blob/master/config.org][this config by hsin-hao yu]]. Define ~deft-strip-summary-regexp~ to match a group of expressions. +#+begin_src emacs-lisp :tangle no :noweb-ref deft-custom +(deft-strip-summary-regexp + (rx (group (or + space + <<deft-strip-summary-regexps>> + )))) +#+end_src + +Match ~#+~ based meta lines. +#+begin_src emacs-lisp :tangle no :noweb-ref deft-strip-summary-regexps +(seq bol "#+" (+ (any alpha ?_)) ?: (* any) eol) +#+end_src +Match all drawer lines, including the content. +#+begin_src emacs-lisp :tangle no :noweb-ref deft-strip-summary-regexps +(seq bol ?: (*? (not ?:)) ?: (*? (or any "\n")) ":END:") +#+end_src +Match some formatted standard additional information at the start of files. +#+begin_src emacs-lisp :tangle no :noweb-ref deft-strip-summary-regexps +(seq bol "- tags ::" (* any) eol) +(seq bol "- links ::" (* any) eol) +(seq bol "- source ::" (* any) eol) +#+end_src + +[[https://github.com/EFLS/zetteldeft][Zetteldeft]] provides further functions to search and link between +different /Zettel/. As /Zettel/ are scattered in separate files, +normal org file links using IDs lack in comparison to the introduced +custom link format. + +#+begin_src emacs-lisp +(use-package zetteldeft + :straight t + ;; :bind (:map fpi-map (("d d" . deft) + ;; ("d D" . zetteldeft-deft-new-search) + ;; ("d R" . deft-refresh) + ;; ("d s" . zetteldeft-search-at-point) + ;; ("d c" . zetteldeft-search-current-id) + ;; ("d f" . zetteldeft-follow-link) + ;; ("d F" . zetteldeft-avy-file-search-ace-window) + ;; ("d l" . zetteldeft-avy-link-search) + ;; ("d t" . zetteldeft-avy-tag-search) + ;; ("d T" . zetteldeft-tag-buffer) + ;; ("d i" . zetteldeft-find-file-id-insert) + ;; ("d I" . zetteldeft-find-file-full-title-insert) + ;; ("d o" . zetteldeft-find-file) + ;; ("d n" . zetteldeft-new-file) + ;; ("d N" . zetteldeft-new-file-and-link) + ;; ("d r" . zetteldeft-file-rename) + ;; ("d x" . zetteldeft-count-words))) + ) +#+end_src +#+begin_src emacs-lisp :noweb-ref fpi-bindings :tangle no +(fpi/define-key fpi-map "dd" #'deft "Deft") +#+end_src + +** Shell +#+begin_src emacs-lisp +(use-package shell + :commands (shell shell-command)) +#+end_src +To open and hide a shell quickly I use =shell-pop=. +#+begin_src emacs-lisp +(use-package shell-pop + :straight t + :bind (("C->" . shell-pop)) + :custom + (shell-pop-shell-type (quote ("eshell" "*eshell*" (lambda nil (eshell)))))) +#+end_src +Vterm is the emacs terminal emulator, which is closest to standard terminal emulators. +#+begin_src emacs-lisp +(use-package vterm + :straight t) +#+end_src +** Grep +#+begin_src emacs-lisp +(use-package grep + :custom (grep-command "grep --color -nH --null ")) +#+end_src +** Proced +Built-in process monitor. +#+BEGIN_SRC emacs-lisp +(use-package proced + :commands proced + :custom + (proced-toggle-auto-update t) + (proced-auto-update-interval 1) + (proced-descend t) + (proced-filter 'user)) +#+END_SRC +** Passwords +*** [[info:auth#Top][auth-source]] +#+begin_src emacs-lisp +(use-package auth-source + :custom (auth-source-save-behavior nil)) +#+end_src +*** Pass +Emacs interface & mode for the password manager [[https://www.passwordstore.org/][pass/password-store]]. +The emacs =pass= package provides a nice buffer listing all stored +passwords files and also a good mode to edit them. The +=password-store= package provides functions to copy and edit +individual password files. I'm not sure which one I'll end up using. I +bind a small function to copy a password or a field if called with a +prefix to my custom keymap. +#+BEGIN_SRC emacs-lisp +(use-package pass + :straight t) +#+END_SRC +#+begin_src emacs-lisp +(use-package password-store + :straight t + :commands (password-store-copy + password-store-edit + password-store-insert) + :custom (password-store-time-before-clipboard-restore 30) + :config (defun fpi/password-store-copy-pass-or-field (&optional arg) + (interactive "P") + (if arg + (call-interactively 'password-store-copy-field) + (call-interactively 'password-store-copy)))) +#+end_src + +#+begin_src emacs-lisp :noweb-ref fpi-bindings :tangle no +(fpi/define-key fpi-map "p" #'fpi/password-store-copy-pass-or-field "Pass") +#+end_src +**** auth-password-store/auth-source-pass +A password-store backend for the Emacs [[info:auth#Top][auth-source]] library which +normally uses the =~/.authinfo= file. For correct setup of +password-store files see [[https://rkm.id.au/2015/07/07/integrating-password-store-with-emacs/#fnr.1][here]] and in its [[https://github.com/DamienCassou/auth-password-store][github repo]]. For remote hosts +they need to contain the host and user info. The port is most of the +time inferred. The filename must also include the hostname. For +multiple users on the same host either use =user1@host.gpg= and +=user2@host.gpg= or =host/user1.gpg=, =host/user2.gpg=. +#+CAPTION: Example =pass= entry for use with =auth-source-pass= +#+begin_src pass-view +<password> +host: localhost +user: root +#+end_src + +#+BEGIN_SRC emacs-lisp +(use-package auth-source-pass + :straight t + :config (auth-source-pass-enable)) +#+END_SRC +** Ledger +Here is a good [[https://www.reddit.com/r/emacs/comments/8x4xtt][reddit thread]] about using ledger +#+BEGIN_SRC emacs-lisp +(use-package ledger-mode + :straight t + :init (setq ledger-clear-whole-transactions 1) + :mode "\\.dat\\'" + "\\.ledger\\'") +;; (use-package flycheck-ledger +;; :straight t +;; :after ledger-mode) +#+END_SRC + +I also use some =org-capture= templates to quickly capture +transactions. They are defined in [[file:emacs-private.el.gpg::4][emacs-private.el.gpg]]. + +** Plotting data + +=gnuplot= is a great option for plotting any kind of data, no matter +where it comes from. + +#+begin_src emacs-lisp +(use-package gnuplot + :straight t) +(use-package gnuplot-mode + :straight t) +#+end_src +** HTML renderer +=shr= is the /Simple HTML renderer/ library, which Emacs uses to +display HTML. It is used by elfeed, notmuch and a variety of other +tools. + +- Open links in =eww= instead of the system browser +- Limit the entry width to the same as =fill-column= +- Limit the size of images + +#+BEGIN_SRC emacs-lisp + ;; (lambda (url &rest args) + ;; (if args + ;; (browse-url-default-browser url) + ;; (eww-browse-url url))) + +(use-package shr + :commands (eww eww-browse-url) + :custom + (browse-url-browser-function 'eww-browse-url) + (browse-url-generic-program "firefox") + (shr-external-browser 'browse-url-generic) + (shr-width 900) + (shr-max-image-proportion 0.4) + (shr-use-colors nil) + (shr-use-fonts nil) ) +#+END_SRC + +Support for HTML code blocks with proper syntax highlighting. See [[https://github.com/xuchunyang/shr-tag-pre-highlight.el][its GitHub project page]]. +#+BEGIN_SRC emacs-lisp +(use-package shr-tag-pre-highlight + :straight t + :after shr + :config + (add-to-list 'shr-external-rendering-functions + '(pre . shr-tag-pre-highlight)) + (when (version< emacs-version "26") + (with-eval-after-load 'eww + (advice-add 'eww-display-html :around + 'eww-display-html--override-shr-external-rendering-functions)))) +#+END_SRC +** Email +For the setup of external mail specific programs see [[file:mail.org]]. +*** Sending mail +I use =msmtp= to send mail. + +- Infer the =envelope-from= header and therefore the adress to send + the mail from based on the /From/ header argument. +- Add a =-f username= flag to the sendmail command line call, as msmtp + needs it. +- Enable footnote-mode when entering message-mode. + +#+begin_src emacs-lisp +(use-package message + :custom + (message-send-mail-function 'message-send-mail-with-sendmail) + (message-sendmail-envelope-from 'header) + (message-sendmail-f-is-evil nil) + (message-kill-buffer-on-exit t) + (message-forward-as-mime t) + (message-fill-column nil) ;; to disable auto-fill-mode + :hook (message-mode . footnote-mode)) +(use-package sendmail + :custom + (send-mail-function 'smtpmail-send-it) + (sendmail-program "/usr/bin/msmtp") + (mail-specify-envelope-from t) + (mail-envelope-from 'header)) +#+end_src +*** MIME +#+begin_src emacs-lisp +(use-package mm-decode + :config + (use-package spice-mode + :straight t + :config + (add-to-list 'auto-mode-alist '("\\.cir$" . spice-mode)) + (add-to-list 'auto-mode-alist '("\\.scs$" . spice-mode))) + (defun mm-display-spice-inline (handle) + "Show an spice mode text from HANDLE inline." + (mm-display-inline-fontify handle 'spice-mode)) + (add-to-list 'mm-inline-media-tests '("application/x-wine-extension-cir" mm-display-spice-inline identity)) + (add-to-list 'mm-inlined-types "application/x-wine-extension-cir")) +#+end_src +**** S/MIME +Mail signing and encrypting with S/MIME needs a =gpgsm= setup and =smime.el=. + +One can either use =EasyPG= or =OpenSSL= as external implementations. Still need to document these settings and packages better.. +#+begin_src emacs-lisp +(use-package epg + :custom (epg-pinentry-mode nil)) +(use-package mml-sec + :custom + (mml-default-encrypt-method "smime") + (mml-default-sign-method "smime") + (mml-secure-cache-passphrase nil) + (mml-secure-passphrase-cache-expiry 16) + ) +(use-package mml-smime + :custom + (mml-smime-use 'epg) + (mml-secure-smime-sign-with-sender t) +) +#+end_src + +#+begin_src emacs-lisp :tangle no +(use-package smime + :custom + (smime-CA-directory "~/certs/trusted") + (smime-certificate-directory "~/certs") + (smime-keys private/smime-keys) + ) +#+end_src + +#+begin_src emacs-lisp :tangle no +(setq mm-sign-option 'guided) +#+end_src +*** MUA/Notmuch + +After using =mu4e= as my mail user agent for a while I switched to +=notmuch=. I like the tagging based approach and the easy & great +searching. + +- Show newest messages first. +- Set archive tags to remove/set upon archiving a mail with =a=. +- Setup some saved searched. +- Set my signature (defined in [[file:emacs-private.el.gpg::13][emacs-private.el.gpg]]). +- Set the FCC directories where sent mails should be saved to (also + defined in [[file:emacs-private.el.gpg::20][emacs-private.el.gpg]].). +- Setup format=flowed +#+BEGIN_SRC emacs-lisp +(use-package notmuch + :straight t + :custom + (notmuch-search-oldest-first nil) + (notmuch-archive-tags '("-inbox" "-td" "+archived")) + (notmuch-saved-searches + '((:name "inbox" :query "tag:inbox" :key "i") + (:name "unread (inb)" :query "(tag:unread and tag:inbox) or tag:td" :key "u") + (:name "unread (tot)" :query "tag:unread and date:6month..0month" :key "U") + (:name "flagged" :query "tag:flagged" :key "f") + (:name "sent" :query "tag:sent" :key "s") + (:name "drafts" :query "tag:draft" :key "d") + (:name "all mail" :query "*" :key "a") + (:name "tr" :query "tag:tr and date:6month..0month" :key "t"))) + (message-signature private/message-signature) + (notmuch-fcc-dirs private/notmuch-fcc-dirs)) +#+END_SRC +**** f=f +Hard new lines are identified using a ~hard~ text property and +displayed as =⏎=. We need to make sure all newlines inserted by +message initialization (signature, ...) also have this text property. +For now I use this bad code. +#+BEGIN_SRC emacs-lisp :tangle no +(use-package messages-are-flowing + :straight t + :config (add-hook 'message-mode-hook 'messages-are-flowing-use-and-mark-hard-newlines)) +(defun message-insert-signature (&optional force) + (interactive) + (goto-char (point-max)) + (let ((point (point))) + (message-insert-signature-original force) + (goto-char point) + (while (search-forward "\n" nil t) + (set-hard-newline-properties (- (point) 1) (point))))) + +(defun message-insert-signature-original (&optional force) + "Insert a signature. See documentation for variable `message-signature'. " + (interactive (list 0)) + (let* ((signature + (cond + ((and (null message-signature) + (eq force 0)) + (save-excursion + (goto-char (point-max)) + (not (re-search-backward message-signature-separator nil t)))) + ((and (null message-signature) + force) + t) + ((functionp message-signature) + (funcall message-signature)) + ((listp message-signature) + (eval message-signature)) + (t message-signature))) + signature-file) + (setq signature + (cond ((stringp signature) + signature) + ((and (eq t signature) message-signature-file) + (setq signature-file + (if (and message-signature-directory + ;; don't actually use the signature directory + ;; if message-signature-file contains a path. + (not (file-name-directory + message-signature-file))) + (expand-file-name message-signature-file + message-signature-directory) + message-signature-file)) + (file-exists-p signature-file)))) + (when signature + (goto-char (point-max)) + ;; Insert the signature. + (unless (bolp) + (newline)) + (when message-signature-insert-empty-line + (newline)) + (insert "-- ") + (newline) + (if (eq signature t) + (insert-file-contents signature-file) + (insert signature)) + (goto-char (point-max)) + (or (bolp) (newline))))) +#+END_SRC +*** Gnus +The customization for gnus is located in [[file:gnus.org][gnus.org]] and loaded from there upon startup. + +I change the group buffer to something more memorable. This needs to be set before gnus is started and therefore only setting it in gnus.org is not sufficient. +#+begin_src emacs-lisp +(setq gnus-group-buffer "*Gnus*") +#+end_src +** Footnote Mode +#+begin_src emacs-lisp +(use-package footnote + :custom + (footnote-section-tag "")) +#+end_src +** BBDB +:PROPERTIES: +:ID: 390b66e5-b123-4cb1-9a56-61e41d7a818a +:END: +#+begin_src emacs-lisp +(use-package bbdb + :straight t) +(bbdb-initialize 'gnus 'message) +(bbdb-mua-auto-update-init 'gnus 'message) + +(setq bbdb-mua-pop-up 'horiz) +(setq bbdb-pop-up-layout 'one-line) +;; size of the bbdb popup +(setq bbdb-pop-up-window-size 0.15) +(setq bbdb-mua-pop-up-window-size 0.15) + +;; What do we do when invoking bbdb interactively +(setq bbdb-mua-update-interactive-p '(query . create)) + +;; Make sure we look at every address in a message and not only the +;; first one +(setq bbdb-message-all-addresses t) + +;; use ; on a message to invoke bbdb interactively +(add-hook + 'gnus-summary-mode-hook + (lambda () + (define-key gnus-summary-mode-map (kbd ";") 'bbdb-mua-edit-field))) +#+end_src +To synchronize the database across devices I symlink it to my central synchronization directory: +#+begin_src shell :noweb-ref symlinks :tangle no +ln -siv ~/sync/bbdb/bbdb ~/.emacs.d/bbdb +#+end_src +** Compile +Fix ansi colors in compile buffers. From [[https://endlessparentheses.com/ansi-colors-in-the-compilation-buffer-output.html][endlessparentheses]]. +#+begin_src emacs-lisp +(use-package compile + :custom + (compilation-scroll-output t) + :config + (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)))) + :hook (compilation-filter . endless/colorize-compilation)) +#+END_src +** Speed reading +=spray= offers an interface similar to the [[https://ds300.github.io/jetzt/][jetzt]] browser based speed reader. +#+begin_src emacs-lisp +(use-package spray + :straight (:host nil :repo "https://git.sr.ht/~iank/spray/")) +#+end_src +** Context aware hydra +:PROPERTIES: +:ID: 22750e48-aaee-4f60-bdce-1d511ebe3375 +:END: +[[https://dfeich.github.io/www/org-mode/emacs/2018/05/10/context-hydra.html][dfeich]] has a nice post on this. Basically it launches a specific hydra +based on the current mode and context around point. +#+BEGIN_SRC emacs-lisp +(defun dfeich/context-hydra-launcher () + "A launcher for hydras based on the current context." + (interactive) + (cl-case major-mode + ((org-mode org-journal-mode) + (let* ((elem (org-element-context)) + (etype (car elem)) + (type (org-element-property :type elem))) + (cl-case etype + (headline (fpi/org-edna-hydra/body)) + (src-block (hydra-babel-helper/body)) + (link (hydra-org-link-helper/body)) + ((table-row table-cell) (hydra-org-table-helper/body) ) + (t (message "No specific hydra for %s/%s" etype type) + (hydra-org-default/body))))) + ('bibtex-mode (org-ref-bibtex-hydra/body)) + ('ibuffer-mode (hydra-ibuffer-main/body)) + (t (message "No hydra for this major mode: %s" major-mode)))) + +;;; *** org mode hydras +(defhydra hydra-org-default (:color pink :hint nil) + " +Org default hydra + +_l_ insert template from last src block +_s_ insert src block ref with helm + +_q_ quit +" + ("l" fpi/copy-last-src-block-head :color blue) + ("s" helm-lib-babel-insert :color blue) + ("q" nil :color blue)) + + +(defhydra hydra-org-link-helper (:color pink :hint nil) + " +org link helper +_b_ backward slurp _f_ forward slurp _n_ next link +_m_ backward barf _g_ forward barf _p_ previous link +_t_ terminal at path + +_q_ quit +" + ("b" org-link-edit-backward-slurp) + ("f" org-link-edit-forward-slurp) + ("m" org-link-edit-backward-barf) + ("g" org-link-edit-forward-barf) + ("n" org-next-link) + ("p" org-previous-link) + ("t" fpi/gnome-terminal-at-link :color blue) + ("q" nil :color blue)) + +(defhydra hydra-org-table-helper (:color pink :hint nil) + " +org table helper +_r_ recalculate _w_ wrap region _c_ toggle coordinates +_i_ iterate table _t_ transpose _D_ toggle debugger +_B_ iterate buffer _E_ export table _d_ edit field +_e_ eval formula _s_ sort lines + +_q_ quit +" + ("E" org-table-export :color blue) + ("s" org-table-sort-lines) + ("d" org-table-edit-field) + ("e" org-table-eval-formula) + ("r" org-table-recalculate) + ("i" org-table-iterate) + ("B" org-table-iterate-buffer-tables) + ("w" org-table-wrap-region) + ("D" org-table-toggle-formula-debugger) + ("t" org-table-transpose-table-at-point) + ("c" org-table-toggle-coordinate-overlays :color blue) + ("q" nil :color blue)) + +(defun fpi/org-babel-src-mode-hydra () + "Launch a hydra specific to the src language of the current + babel code block if defined." + (interactive) + (let* ((elem (org-element-context)) + (lang (plist-get (cadr elem) :language))) + (pcase lang + ("bibtex" (org-ref-bibtex-hydra/body))))) +(defhydra hydra-babel-helper (:color pink :hint nil) + " +org babel src block helper functions +_n_ next _i_ info _I_ insert header +_p_ prev _c_ check _m_ ode hydra +_h_ goto head _E_ expand +^ ^ _s_ split +_q_ quit _r_ remove result _e_ examplify region + +" + ("i" org-babel-view-src-block-info) + ("I" org-babel-insert-header-arg) + ("c" org-babel-check-src-block :color blue) + ("s" org-babel-demarcate-block :color blue) + ("n" org-babel-next-src-block) + ("p" org-babel-previous-src-block) + ("E" org-babel-expand-src-block :color blue) + ("e" org-babel-examplify-region :color blue) + ("r" org-babel-remove-result :color blue) + ("h" org-babel-goto-src-block-head) + ("m" fpi/org-babel-src-mode-hydra :color blue) + ("q" nil :color blue)) + + +;;; *** ibuffer hydra +;; from https://github.com/abo-abo/hydra/wiki/Ibuffer +(defhydra hydra-ibuffer-main (:color pink :hint nil) + " + ^Navigation^ | ^Mark^ | ^Actions^ | ^View^ +-^----------^-+-^----^--------+-^-------^--------+-^----^------- + _p_: ʌ | _m_: mark | _D_: delete | _g_: refresh + _RET_: visit | _u_: unmark | _S_: save | _s_: sort + _n_: v | _*_: specific | _a_: all actions | _/_: filter +-^----------^-+-^----^--------+-^-------^--------+-^----^------- +" + ("n" ibuffer-forward-line) + ("RET" ibuffer-visit-buffer :color blue) + ("p" ibuffer-backward-line) + + ("m" ibuffer-mark-forward) + ("u" ibuffer-unmark-forward) + ("*" hydra-ibuffer-mark/body :color blue) + + ("D" ibuffer-do-delete) + ("S" ibuffer-do-save) + ("a" hydra-ibuffer-action/body :color blue) + + ("g" ibuffer-update) + ("s" hydra-ibuffer-sort/body :color blue) + ("/" hydra-ibuffer-filter/body :color blue) + + ("o" ibuffer-visit-buffer-other-window "other window" :color blue) + ("q" nil "quit" :color blue)) + +(defhydra hydra-ibuffer-mark (:color teal :columns 5 + :after-exit (hydra-ibuffer-main/body)) + "Mark" + ("*" ibuffer-unmark-all "unmark all") + ("M" ibuffer-mark-by-mode "mode") + ("m" ibuffer-mark-modified-buffers "modified") + ("u" ibuffer-mark-unsaved-buffers "unsaved") + ("s" ibuffer-mark-special-buffers "special") + ("r" ibuffer-mark-read-only-buffers "read-only") + ("/" ibuffer-mark-dired-buffers "dired") + ("e" ibuffer-mark-dissociated-buffers "dissociated") + ("h" ibuffer-mark-help-buffers "help") + ("z" ibuffer-mark-compressed-file-buffers "compressed") + ("b" hydra-ibuffer-main/body "back" :color blue)) + +(defhydra hydra-ibuffer-action (:color teal :columns 4 + :after-exit + (if (eq major-mode 'ibuffer-mode) + (hydra-ibuffer-main/body))) + "Action" + ("A" ibuffer-do-view "view") + ("E" ibuffer-do-eval "eval") + ("F" ibuffer-do-shell-command-file "shell-command-file") + ("I" ibuffer-do-query-replace-regexp "query-replace-regexp") + ("H" ibuffer-do-view-other-frame "view-other-frame") + ("N" ibuffer-do-shell-command-pipe-replace "shell-cmd-pipe-replace") + ("M" ibuffer-do-toggle-modified "toggle-modified") + ("O" ibuffer-do-occur "occur") + ("P" ibuffer-do-print "print") + ("Q" ibuffer-do-query-replace "query-replace") + ("R" ibuffer-do-rename-uniquely "rename-uniquely") + ("T" ibuffer-do-toggle-read-only "toggle-read-only") + ("U" ibuffer-do-replace-regexp "replace-regexp") + ("V" ibuffer-do-revert "revert") + ("W" ibuffer-do-view-and-eval "view-and-eval") + ("X" ibuffer-do-shell-command-pipe "shell-command-pipe") + ("b" nil "back")) + +(defhydra hydra-ibuffer-sort (:color amaranth :columns 3) + "Sort" + ("i" ibuffer-invert-sorting "invert") + ("a" ibuffer-do-sort-by-alphabetic "alphabetic") + ("v" ibuffer-do-sort-by-recency "recently used") + ("s" ibuffer-do-sort-by-size "size") + ("f" ibuffer-do-sort-by-filename/process "filename") + ("m" ibuffer-do-sort-by-major-mode "mode") + ("b" hydra-ibuffer-main/body "back" :color blue)) + +(defhydra hydra-ibuffer-filter (:color amaranth :columns 4) + "Filter" + ("m" ibuffer-filter-by-used-mode "mode") + ("M" ibuffer-filter-by-derived-mode "derived mode") + ("n" ibuffer-filter-by-name "name") + ("c" ibuffer-filter-by-content "content") + ("e" ibuffer-filter-by-predicate "predicate") + ("f" ibuffer-filter-by-filename "filename") + (">" ibuffer-filter-by-size-gt "size") + ("<" ibuffer-filter-by-size-lt "size") + ("/" ibuffer-filter-disable "disable") + ("b" hydra-ibuffer-main/body "back" :color blue)) +#+END_SRC +** SSH tunnels +#+begin_src emacs-lisp +(use-package ssh-tunnels + :straight t + :custom (ssh-tunnels-configurations + (cons `(:name "nntp" + :local-port 4321 + :remote-port 4321 + :login ,private/ssh-login-nntp + :host "localhost") + private/ssh-tunnels)) + :config (auto-ssh-tunnels-mode 1)) +#+end_src +** Minor utilities +*** Screenshots / -casts +[[https://gitlab.com/ambrevar/emacs-gif-screencast][Here]] is a guide to creating emacs gif screencasts. + +If compiled with =cairo= support emacs can directly create svg screenshots ([[https://www.reddit.com/r/emacs/comments/idz35e/emacs_27_can_take_svg_screenshots_of_itself/][source]]). +#+begin_src emacs-lisp +(defun screenshot-svg () + "Save a screenshot of the current frame as an SVG image. +Saves to a temp file and puts the filename in the kill ring." + (interactive) + (let* ((filename (make-temp-file "Emacs-" nil ".svg")) + (data (x-export-frames nil 'svg))) + (with-temp-file filename + (insert data)) + (kill-new filename) + (message filename))) +#+end_src +*** Whole-line-or-region +#+begin_src emacs-lisp +(use-package whole-line-or-region + :straight t + :config + (whole-line-or-region-global-mode 1) + (delight 'whole-line-or-region-local-mode nil t)) +#+end_src +*** Pomodoro / Redtick +#+begin_src emacs-lisp +(use-package redtick + :straight (:host github :repo "fpiper/redtick" + :branch "dev") + :custom + ((redtick-sound-volume "20") + (redtick-play-sound t) + (redtick-work-interval (* 60 20)) + (redtick-rest-interval (* 60 5))) + :config (redtick-mode 1)) +#+end_src +*** Script creation +Automatically make scripts executable upon save if first line is a shebang: +#+begin_src emacs-lisp +(add-hook 'after-save-hook + 'executable-make-buffer-file-executable-if-script-p) +#+end_src + +The =Auto-Insert= package helps inserting header templates upon creating files. If you do not turn on =auto-insert-mode= you can manually call =M-x auto-insert= to perform the insertion. +#+begin_src emacs-lisp +(use-package autoinsert + :config + (define-auto-insert '("\\.sh\\'" . "Shell script skeleton") + '("" + "#!/usr/bin/env bash" \n \n)) + (auto-insert-mode -1)) +#+end_src +** Embark +Do things in the order =selection → action= instead of =action → selection=. +#+begin_src emacs-lisp +(use-package embark + :straight t + :bind (("C-." . embark-act))) +(use-package embark-consult + :straight t + :after (embark consult)) +#+end_src + +As minor-mode maps would override the global map we have to unset the =C-.= binding in flyspell. We can either do this with an ~eval-after-load~ +#+begin_src emacs-lisp :tangle no :eval never +(eval-after-load "flyspell" + '(define-key flyspell-mode-map (kbd "C-.") nil)) +#+end_src + +or by (un-)setting the binding explicitly in the =use-package= call of flyspell. +#+begin_src emacs-lisp :tangle no :noweb-ref flyspell-bindings +("C-." . nil) +#+end_src +* Language settings +End sentences with single spaces. +#+begin_src emacs-lisp +(setq sentence-end-double-space nil) +#+end_src +** Spellcheck +#+begin_src emacs-lisp +(use-package ispell + :config + (setq ispell-program-name "/usr/bin/hunspell") + (setq ispell-dictionary "en_US,de_DE") + (ispell-set-spellchecker-params) + (ispell-hunspell-add-multi-dic "en_US,de_DE") + ) +#+end_src +*** Flyspell +Setup mainly from [[https://github.com/howardabrams/dot-files/blob/master/emacs.org][Howard Abrams]]. +#+begin_src emacs-lisp +(use-package flyspell + :delight + :bind (:map flyspell-mode-map + <<flyspell-bindings>> + ) + :init + (add-hook 'prog-mode-hook 'flyspell-prog-mode) + (dolist (hook '(text-mode-hook org-mode-hook)) + (add-hook hook (lambda () (flyspell-mode 1)))) + (dolist (hook '(change-log-mode-hook log-edit-mode-hook org-agenda-mode-hook)) + (add-hook hook (lambda () (flyspell-mode -1))))) +#+end_src +* Interface +** General +#+begin_src emacs-lisp +(use-package emacs + :custom + (vc-follow-symlinks t) + (echo-keystrokes 0.25) + (auto-revert-verbose nil) + :config + (defalias 'yes-or-no-p 'y-or-n-p) + (put 'dired-find-alternate-file 'disabled nil) + (put 'narrow-to-region 'disabled nil)) +#+end_src +** Rainbow mode +#+begin_src emacs-lisp +(use-package rainbow-mode + :straight t) +#+end_src +** Parentheses +#+begin_src emacs-lisp +(use-package paren + :custom + (show-paren-style 'mixed) + (show-paren-when-point-in-periphery t) + (show-paren-when-point-inside-paren t) + :config + (show-paren-mode 1)) +#+end_src +** Whitespace +I do not really care about spaces versus tabs most of the time. I only +want it to be consistent within a file. +#+begin_src emacs-lisp +(use-package emacs + :config + (define-minor-mode tab-mode + "Toggle tab and space based indentation." + :init-value nil + :lighter " »" + (if tab-mode + (progn + (setq indent-tabs-mode t) + (setq tab-width 4) + ) + (setq indent-tabs-mode nil) + (setq tab-width 8) + )) + (defun enable-tab-mode () + (tab-mode 1)) + (defun disable-tab-mode () + (tab-mode -1)) + :custom + (indent-tabs-mode nil) + ;; (tab-width 4) + ;; (tab-mode 1) + :hook + (prog-mode . enable-tab-mode) + (emacs-lisp-mode . disable-tab-mode) + (lisp-mode . disable-tab-mode) + (matlab-mode . enable-tab-mode) + ) +#+end_src +Instead of =$= use =⏎= to indicate newlines +#+begin_src emacs-lisp +(use-package whitespace + :delight + :custom (whitespace-display-mappings '((space-mark 32 + [183] + [46]) + (space-mark 160 + [164] + [95]) + (newline-mark 10 + [9166 10]) ;;[36 10] + (tab-mark 9 + [187 9] + [92 9])))) +#+end_src +** Notifications +#+begin_src emacs-lisp +(use-package sauron + :straight t + :custom + (sauron-separate-frame (not (eq (fpi/current-device-info :wm) 'exwm))) + (sauron-notifications-urgency-to-priority-plist '(:low 2 :normal 4 :critical 5 :otherwise 2)) + :config + (add-to-list 'sauron-modules 'sauron-dbus)) +(use-package alert + :straight t) +(use-package org-alert + :straight t) +#+end_src +** Undo + +Emacs undo mechanic can be confusing. =undo-tree= is a great package +but is prone to corruption and also does not allow undo based on the +active region. + +*** Vundo +=Vundo= is a promising alternative to =undo-tree=, that is compatible with the default emacs undo/redo system. Its function is described in detail in [[https://archive.casouri.cat/note/2021/visual-undo-tree/index.html][this blogpost]]. +#+begin_src emacs-lisp +(use-package vundo + :straight (:host github :repo "casouri/vundo" + :branch "master") + :bind (("M-_" . vundo))) +#+end_src +*** Undo-propose :ARCHIVE: +=undo-propose= shows undo changes in a temporary buffer. For the +keybindings see [[elisp:(which-key-show-full-keymap +'undo-propose-mode-map)]]. =undo-propose-commit= commits the cumulated +undo changes and the traveled undo history to the original buffer. +=undo-propose-squash-commit= omits the history. + +The temporary buffer messes up point and folding in org buffers. +Therefore I don't use it anymore and should someday look into how this +temporary buffer is created. + +#+begin_src emacs-lisp :tangle no +(use-package undo-propose + :straight t + :bind (("C-/" . undo-propose))) +#+end_src +** Electric stuff +#+begin_src emacs-lisp +(use-package electric + :init + (setq electric-pair-inhibit-predicate 'electric-pair-conservative-inhibit) + (setq electric-pair-pairs '((?\" . ?\") + (?‘ . ?’) + (?“ . ?”) + (?« . ?») + (?„ . ?“) + (?‚ . ?‘) + )) + (setq electric-pair-skip-self 'electric-pair-default-skip-self) + (setq electric-quote-context-sensitive t) + (setq electric-quote-paragraph t) + (setq electric-quote-string nil) + :config + (electric-indent-mode 1) + (electric-pair-mode 1) + (electric-quote-mode -1)) +#+end_src +** Writing Setup +:PROPERTIES: +:ID: 9746c4dd-52d9-47fa-943b-7aa58601f22b +:END: +I gather all settings related to writing in a minor mode. +#+begin_src emacs-lisp +(define-minor-mode prose-mode + "Toggle some settings for text based buffers." + :init-value nil + :lighter " ✎" + (if prose-mode + (progn + (olivetti-mode 1) + (set-window-fringes (selected-window) 0 0) + (variable-pitch-mode 1) + ) + (olivetti-mode -1) + (set-window-fringes (selected-window) nil) + (variable-pitch-mode -1) + )) +#+end_src +The mode is enabled for all =text-mode= based buffers by default. +#+begin_src emacs-lisp +(add-hook 'text-mode-hook 'prose-mode) +#+end_src +Also set an easy keybinding to toggle it manually. +#+begin_src emacs-lisp :noweb-ref fpi-bindings :tangle no +(fpi/define-key fpi/toggle-map "p" #'prose-mode "Prose") +#+end_src + +Olivetti mode is used to center text in the buffer. This somehow helps with writing. +#+begin_src emacs-lisp +(use-package olivetti + :straight t + :delight + :custom + (olivetti-body-width 80) + ;; (olivetti-minimum-body-width 70) + ) +#+end_src + +For org-mode also reduce indentation by =org-indent-mode= as described [[https://explog.in/notes/writingsetup.html][here]]. +#+begin_src emacs-lisp :noweb-ref org-indent-custom :tangle no +(org-indent-indentation-per-level 1) +#+end_src +These settings are also from the above blog post, but mainly manually set what =org-indent-mode= does anyway. +#+begin_src emacs-lisp :noweb-ref org-custom :tangle no +(org-adapt-indentation nil) +(org-hide-leading-stars t) +(org-hide-emphasis-markers t) +(org-cycle-separator-lines 1) +#+end_src + +While I generally use ~fit-window-to-buffer~ (bound to =C-z s=) to fit a buffer to its content width (see [[id:99f1af26-1383-43c1-8408-9a13c495925e][Window configuration]]), buffers in =prose-mode= can reduced to ~olivetti-body-width~ if it is an integer. +#+begin_src emacs-lisp +(defun fpi/fit-window-to-buffer (&optional WINDOW MAX-HEIGHT MIN-HEIGHT MAX-WIDTH MIN-WIDTH PRESERVE-SIZE) + "Wrapper around `fit-window-to-buffer' which considers `olivetti-mode'. + +If `olivetti-body-width' is a number fit the window width to it instead of the actual line width." + (interactive) + (let ((max-width (when (and olivetti-mode (numberp olivetti-body-width)) + (round (* 1.03 olivetti-body-width))))) + (fit-window-to-buffer (selected-window) nil nil max-width nil) + )) +#+end_src + +#+begin_src emacs-lisp :tangle no :noweb-ref fpi-bindings +(fpi/define-key 'fpi-map (kbd "s") 'fpi/fit-window-to-buffer "Size window to buffer") +#+end_src + +* Wrapping up + +Some stuff that is run after everything else. +#+begin_src emacs-lisp +<<theme-dependent-vars>> +<<themes>> +#+end_src diff --git a/gnuplot.org b/gnuplot.org new file mode 100644 index 0000000..a9ec9f4 --- /dev/null +++ b/gnuplot.org @@ -0,0 +1,215 @@ +# -*- coding: utf-8-unix -*- +#+PROPERTY: header-args:gnuplot :tangle tangle/.gnuplot :eval query :tangle-mode (identity #o444) +* Symlink +First create a symlink to the desired config location. +#+begin_src shell :results silent :tangle tangle/symlink.sh :shebang "#!/bin/bash" +ln -siv $(pwd)/tangle/.gnuplot ~/ +#+end_src +* General Configuration +Start off by resetting most settings. +#+begin_src gnuplot +reset +#+end_src + +Plot data using linepoints and make solid regions transparent. +#+begin_src gnuplot +set style data lp +set style fill transparent solid 0.4 noborder +#+end_src + +Enable macros and make gnuplot interpret =NaN= as missing data. +#+begin_src gnuplot +set macros +set datafile missing NaN +#+end_src + +A macro to easily reset gnuplot and also reload my settings. +#+begin_src gnuplot +init="load '~/.gnuplot'" +before_refresh="" # Commands to eval before each refresh +r="@before_refresh;refresh" +#+end_src + +Here is a handy function to define colors with individual rgb integers instead of the hex notation. Example usage: ~plot x w l lc rgb rgb(255,80,0)~. Alternatively gnuplot also supports hsv colors with ~hsv2rgb(h,s,v)~. +#+begin_src gnuplot +rgb(r,g,b) = 65536 * int(r) + 256 * int(g) + int(b) +#+end_src + +When setting the column using a variable you can not use the shorthand syntax ~$2~. Instead setup a function so I only have to write ~c(i)~ instead of ~column(i)~. +#+begin_src gnuplot +c(a)=column(a) +#+end_src +* Mathematical functions +A collection of functions that can calculate a running average. +#+begin_src gnuplot +# running averages +samples(x,n) = $0>(n-1) ? n : ($0+1) +init(x)=(back1=back2=back3=back4=back5=back6=back7=back8=back9=back10=back11=back12=sum=0) +if(init(0)){} # what is the best way to run functions without showing output? +avg1(x)=(back1=x,back1) +avg2(x)=(back2=back1,(avg1(x)+back2)/samples($0,2)) +avg3(x)=(back3=back2,(samples($0,2)*avg2(x)+back3)/samples($0,3)) +avg4(x)=(back4=back3,(samples($0,3)*avg3(x)+back4)/samples($0,4)) +avg5(x)=(back5=back4,(samples($0,4)*avg4(x)+back5)/samples($0,5)) +avg6(x)=(back6=back5,(samples($0,5)*avg5(x)+back6)/samples($0,6)) +avg7(x)=(back7=back6,(samples($0,6)*avg6(x)+back7)/samples($0,7)) +avg8(x)=(back8=back7,(samples($0,7)*avg7(x)+back8)/samples($0,8)) +avg9(x)=(back9=back8,(samples($0,8)*avg8(x)+back9)/samples($0,9)) +avg10(x)=(back10=back9,(samples($0,9)*avg9(x)+back10)/samples($0,10)) +avg11(x)=(back11=back10,(samples($0,10)*avg10(x)+back11)/samples($0,11)) +avg12(x)=(back12=back11,(samples($0,11)*avg11(x)+back12)/samples($0,12)) +#+end_src + +And some derivatives functions. +#+begin_src gnuplot +d(y) = ($0 == 0) ? (y1 = y, 1/0) : (y2 = y1, y1 = y, y1-y2) +d2(x,y) = ($0 == 0) ? (x1 = x, y1 = y, 1/0) : (x2 = x1, x1 = x, y2 = y1, y1 = y, (y1-y2)/(x1-x2)) +#+end_src + +Functions to convert between radians and degrees. +#+begin_src gnuplot +rad(deg)=deg/180*pi +deg(rad)=rad/pi*180 +#+end_src +* Colors +=podo= is a good standard colorblind friendly colorsequence. +#+begin_src gnuplot +# use colorblind friendly colorsequence +set colorsequence podo +#+end_src + +I just reorder the =podo= colors, mainly to make black not the default color. +#+begin_src gnuplot +# use colorsequence podo but reorder some colors +set linetype 1 lc rgb "#0072b2" lw 2 pt 1 ps default +set linetype 2 lc rgb "#d55e00" lw 2 pt 2 ps default +set linetype 3 lc rgb "#009e73" lw 2 pt 3 ps default +set linetype 4 lc rgb "#cc79a7" lw 2 pt 4 ps default +set linetype 5 lc rgb "#56b4e9" lw 2 pt 5 ps default +set linetype 6 lc rgb "#e69f00" lw 2 pt 6 ps default +set linetype 7 lc rgb "#f0e442" lw 2 pt 7 ps default +set linetype 8 lc rgb "black" lw 2 pt 8 ps default +#+end_src +* Grid, Border, Tics +I store the default grid, border and tics settings in the =gbt= variable. So I can easily reset these with the macro call ~@gbt~. The =gbt(col)= function also allows setting grid and border to some other color, but needs to be called using eval, e.g. ~eval(gbt("black"))~. +#+begin_src gnuplot +# grid border tics settings +# call @gbt for defaults +# call eval(gbt("color")) to use color instead of default +gbt(col)=sprintf("set tics nomirror; set border 3 back lc '%s'; set grid back lw 1 lc '%s'",col,col) +gbt="set tics nomirror; set border 3 back lc 'gray50'; set grid back lw 1 lc 'gray50'" +@gbt +#+end_src + +Support function to set x/y tic formatting with ~set format x formatter(".0","m")~. +#+begin_src gnuplot +formatter(prec,unit)=sprintf("%%%ss %%c%s", prec, unit) +#+end_src +* A4 plots +See [[https://milianw.de/blog/how-to-generate-proper-din-a4-sized-plots-with-gnuplot.html][How to generate proper DIN A4 sized plots with Gnuplot - Milian Wolff]]. + +#+begin_src gnuplot +a4="set size ratio 0.71; set terminal postscript enhanced landscape;" +#+end_src +Also set output to a =.ps= file. After that: +#+begin_src bash :eval never +ps2ps -sPAGESIZE=a4 yourfilename.ps new_dina4_file.ps +#+end_src +To finish either use something like =ps2pdf= or view the =.ps= file with =ghostview=. +* Interactive Label Placement +[[http://www.gnuplotting.org/interactive-label-placing/][Source]]. I adapted the =label_loop= function to newer gnuplot syntax & +added functionality for multiple arguments. The function call to +=label_loop= is stored inside a string and can then be executed as a +macro like this: ~@iLabel "label1" "label2"~ + +#+begin_src gnuplot +iLabel = "call '~/git/projects/dotfiles/tangle/label_loop.gp' " +#+end_src + +#+begin_src gnuplot :tangle tangle/label_loop.gp +# label_loop +# This loop adds a label to a plot by pressing the left mouse key. +# If you are not convinced with your chosen position, just klick the mouse key +# again and it will be positioned at another place. If you are finished, just +# press another key. +# +# Original AUTHOR: Hagen Wierstorf + +# Initialize a label number +if (!exists("label_number")) { label_number = 1 } + +do for [ELEMENT in ARG1." ".ARG2." ".ARG3." ".ARG4." ".ARG5] { + while (1) { + # Waiting for the key press + pause mouse any ELEMENT + + # Check if the left mouse key is pressed and add the given label to the plot. + # Otherwise stop the loop and count the added label + if( MOUSE_BUTTON==1 ) { + set label label_number ELEMENT at MOUSE_X,MOUSE_Y textcolor ls 1 + print " at ",MOUSE_X,MOUSE_Y + replot + } else { + label_number = label_number+1 + print "\n" + break + } + } +} +#+end_src + +We can also interactively place rotated labels. Getting the label rotation correct is somewhat tricky and heavily relies on macros. Also the use of ~refresh~ limits the usefulness of this for multiplots. +#+begin_src gnuplot :tangle tangle/label.gp +# label +# Script to interactively position a rotated label. +# +# To update after changing graph size rotation angles are scaled with +# the scaling() function. List of useful macros you should define: +# scaling(_)= (1.0*(GPVAL_TERM_YMAX-GPVAL_TERM_YMIN)/(GPVAL_TERM_XMAX-GPVAL_TERM_XMIN))/((GPVAL_Y_MAX-GPVAL_Y_MIN)/(GPVAL_X_MAX-GPVAL_X_MIN)) +# label_reset= "@label_unset;@label_labels;replot;" +# label_init= "undefine label_labels label_unset" + +if (!exists("label_number")) {label_number = 1} +if (!exists("label_labels")) {label_labels = ""} +if (!exists("label_unset")) {label_unset = ""} + +do for [ELEMENT in ARG1." ".ARG2." ".ARG3." ".ARG4." ".ARG5] { + print(ELEMENT) + while (1) { + next=0 + + array pointsX[2]; array pointsY[2] + do for [point=1:2]{ + pause mouse any + if( MOUSE_BUTTON==1 ) { + pointsX[point]=MOUSE_X + pointsY[point]=MOUSE_Y + } else { next=1;break } + } + if(next){break} + if (pointsX[2] == pointsX[1]){ dx = 1e-20 } + else { dx = pointsX[2] - pointsX[1] } + dy = pointsY[2] - pointsY[1] + + cmd=sprintf("set label %i \"%s\" at %f,%f rotate by deg(atan(%f*scaling(NaN)));",\ + label_number, ELEMENT, pointsX[1], pointsY[1],dy/dx) + eval(cmd); refresh + } + print cmd + label_labels = label_labels.cmd + label_unset = label_unset.sprintf("unset label %i;", label_number) + label_number=label_number+1 +} +refresh +#+end_src + +To make using the script easier define a few macros/functions. +#+begin_src gnuplot +scaling(_)= (1.0*(GPVAL_TERM_YMAX-GPVAL_TERM_YMIN)/(GPVAL_TERM_XMAX-GPVAL_TERM_XMIN))/((GPVAL_Y_MAX-GPVAL_Y_MIN)/(GPVAL_X_MAX-GPVAL_X_MIN)) # functions need to have at least one argument +label="call '~/git/projects/dotfiles/tangle/label.gp' " + +label_reset= "@label_unset;@label_labels;refresh;" +before_refresh = before_refresh."set output GPVAL_OUTPUT;@label_unset;@label_labels;" +label_init= "@label_unset;label_labels='';label_unset=''" +@label_init # clear labels each @init +#+end_src diff --git a/gnus.org b/gnus.org new file mode 100644 index 0000000..6765440 --- /dev/null +++ b/gnus.org @@ -0,0 +1,646 @@ +#+PROPERTY: header-args:emacs-lisp :tangle tangle/gnus.el :noweb yes :tangle-mode (identity #o444) + +#+begin_src shell :results silent :tangle tangle/symlink.sh :shebang "#!/bin/bash" +ln -siv $(pwd)/tangle/gnus.el ~/.gnus.el +#+end_src + +I use =nextcloud= to synchronize gnus state files across devices. Alternatively one may use [[info:gnus#The Gnus Cloud][info:gnus#Gnus Cloud]]. Here i symlink the relevant files/directories to my synchronization directory. +#+begin_src shell :results silent :tangle tangle/symlink.sh :shebang "#!/bin/bash" +ln -siv ~/sync/gnus/News ~/News +ln -siv ~/sync/gnus/.newsrc.eld ~/.newsrc.eld +ln -siv ~/sync/gnus/.gnus.registry.eieio ~/.gnus.registry.eieio +#+end_src + +Load private settings. +#+begin_src emacs-lisp +(mapc (lambda (file) (load file)) + (directory-files user-emacs-directory t "^emacs-.*el.gpg$")) +#+end_src +* Config +** Servers +I use =imap= as my primary server. Setup some generic options: +#+begin_src emacs-lisp :noweb-ref imap :tangle no +nnimap ,@private/imap-info +(nnimap-stream ssl) +(nnir-search-engine imap) +#+end_src +Only fetch partial articles. This saves time on opening messages with +large attachments. Load any text based parts and also load any +signature if the message is signed. Unfortunately to correctly verify +the signature the full message needs to be loaded, which is why I +disabled partial fetching for now. +#+begin_src emacs-lisp :noweb-ref imap :tangle no +;; (nnimap-fetch-partial-articles "\\(text/\\|signature\\)") +#+end_src +Set my default inbox folder. This is the folder mail is split out of. +#+begin_src emacs-lisp :noweb-ref imap :tangle no +(nnimap-inbox "INBOX") +#+end_src +Use fancy splitting and setup splitting rules. See [[info:gnus#Fancy Mail Splitting][info:gnus#Fancy Mail Splitting]] for details. +#+begin_src emacs-lisp :noweb-ref imap :tangle no +(nnimap-split-methods nnimap-split-fancy) +(nnimap-split-fancy + (| (: nnmail-split-fancy-with-parent) + ,@private/imap-split-fancy + "INBOX" + )) +#+end_src + +Noweb the primary server settings together. +#+begin_src emacs-lisp :noweb yes +(setq gnus-select-method + `( + <<imap>> + )) +#+end_src + +To avoid confusion I enable namespaces for imap groups. +#+begin_src emacs-lisp +(setq nnimap-use-namespaces t) +#+end_src +*** Secondary servers +#+begin_src emacs-lisp +<<secondary-select-methods>> +#+end_src +**** Personal mailbox +#+begin_src emacs-lisp :tangle no :noweb-ref secondary-select-methods +(mapc + (lambda (info) + (add-to-list + 'gnus-secondary-select-methods + `(nnimap + ,@info + (nnimap-stream ssl) + (nnir-search-engine imap) + (nnimap-inbox "INBOX")))) + private/personal-imap-info) +#+end_src + +**** RSS/Atom over nntp +Setup a secondary imap server and a local nntp server I use to fetch +RSS/Atom Feeds asynchronously. +#+begin_src emacs-lisp :tangle no :noweb-ref secondary-select-methods +(add-to-list 'gnus-secondary-select-methods '(nntp "localhost" 4321)) +#+end_src + +**** Harddrive Maildir +This is still WIP, because the =nnmaildir= backend sucks. +#+begin_src emacs-lisp :tangle no +(add-to-list 'gnus-secondary-select-methods + '(nnmaildir "Local Maildir" + (directory "~/.nnmaildir") + (gnus-search-engine gnus-search-notmuch + (config-file "~/.notmuch-config")))) +#+end_src +** Options +*** General +**** Startup +Load only groups with level < 2 for faster startup. +#+begin_src emacs-lisp +(setq gnus-activate-level 2) +#+end_src +**** Message related +Bcc self to archive sent messages & ensure proper sending +#+begin_src emacs-lisp +(setq message-default-mail-headers + (format "Bcc: %s\n" user-mail-address)) +#+end_src +Sent mails are read. +#+begin_src emacs-lisp +(setq gnus-gcc-mark-as-read t) +#+end_src +Save sent mails in my imap folder +#+begin_src emacs-lisp +(setq gnus-message-archive-method "dummy string") +(setq gnus-message-archive-group private/imap-sent-folder) +#+end_src +Enable responding to meeting invites. +#+begin_src emacs-lisp +(use-package gnus-icalendar + :config + (gnus-icalendar-setup) + (setq gnus-icalendar-org-capture-file "~/sync/appointments.org") + (setq gnus-icalendar-org-capture-headline '("Calendar")) ;;make sure to create Calendar heading first + (gnus-icalendar-org-setup) + ) +#+end_src +Enable message delaying (scheduling) +#+begin_src emacs-lisp +(gnus-delay-initialize) +#+end_src +***** BBDB integration +Enable =mail-aliases= and create aliases for all mail adresses if an entry has multiple. +#+begin_src emacs-lisp +(add-hook 'message-setup-hook 'bbdb-mail-aliases) +(setq bbdb-mail-alias 'all) +#+end_src +***** Mail encryption & signing +Verify mail signatures with known protocols. +#+begin_src emacs-lisp +(setq mm-verify-option 'known) +#+end_src +Show buttons for result of signature verification & for multipart mails. To show the message fully buttonized use =K b= in the summary buffer. +#+begin_src emacs-lisp +(setq gnus-buttonized-mime-types '("multipart/signed" "multipart/alternative")) +#+end_src +**** Mail splitting +Setup for fancy mail splitting. Also see the parameters in ~gnus-select-method~. +#+begin_src emacs-lisp +(setq nnmail-split-methods 'nnimap-split-fancy) + +(setq nnmail-cache-accepted-message-ids t) +(setq nnmail-message-id-cache-length 10000) +#+end_src +**** Search +Use gnus search language. See [[info:gnus#Search Queries][gnus#Search Queries]] for info. +#+begin_src emacs-lisp +(setq gnus-search-use-parsed-queries t) +#+end_src +**** Demon +Background fetching for gnus. See the manual and [[https://www.emacswiki.org/emacs/GnusDemon][emacswiki]]. +#+begin_src emacs-lisp +(defun gnus-demon-scan-news-level (level only) + (let ((win (current-window-configuration)) + (gnus-read-active-file 'some) + (gnus-check-new-newsgroups nil) + (gnus-verbose 2) + (gnus-verbose-backends 5)) + (while-no-input + (unwind-protect + (save-window-excursion + (when (gnus-alive-p) + (with-current-buffer gnus-group-buffer + (gnus-group-get-new-news level only)))) + (set-window-configuration win))))) +(defun gnus-demon-scan-news-2 () + (gnus-demon-scan-news-level 2 nil)) +(defun gnus-demon-scan-news-3 () + (gnus-demon-scan-news-level 3 t)) +(defun gnus-demon-scan-news-4 () + (gnus-demon-scan-news-level 4 t)) +(defun gnus-demon-scan-news-5 () + (gnus-demon-scan-news-level 5 t)) + +(setq gnus-demon-timestep 10) +(gnus-demon-add-handler 'gnus-demon-scan-news-2 3 nil) +(gnus-demon-add-handler 'gnus-demon-scan-news-3 60 t) +(gnus-demon-add-handler 'gnus-demon-scan-news-4 130 1) +(gnus-demon-add-handler 'gnus-demon-scan-news-5 140 1) +#+end_src +**** Scoring +To define different scoring files for different groups I set [[info:gnus#Home Score File][home score files]] based on the group name. +#+begin_src emacs-lisp +(setq gnus-home-score-file + '(("misc@" "nntp_gmane.SCORE") + ("ieee" "nn_ieee.SCORE") + ("^nnimap" "nnimap.SCORE") ;; w/ author scoring + ("^INBOX" "nnimap.SCORE") ;; w/ author scoring + ("gmane" "nntp_gmane.SCORE") ;; w/ author scoring + ("^nntp\\+localhost" "nntp_global.SCORE") ;; w/o author scoring + )) +(setq gnus-home-adapt-file + '(("misc@" "nntp_gmane.ADAPT") + ("ieee" "nn_ieee.ADAPT") + ("^nnimap" "nnimap.ADAPT") + ("^INBOX" "nnimap.ADAPT") + ("gmane" "nntp_gmane.ADAPT") + ("^nntp\\+localhost" "nntp_global.ADAPT"))) +#+end_src +For information about adaptive scoring see [[info:gnus#Adaptive Scoring][info:gnus#Adaptive Scoring]] and this [[https://notes.whatthefuck.computer/1417593600.0-note.html][blog post]] by Ryan Rix. + +Temporary scores by default expire after 7 days. I want a slightly longer threshold. +#+begin_src emacs-lisp +(setq gnus-score-expiry-days 14) +#+end_src +***** Score File Setup +#+begin_src emacs-lisp +(setq gnus-use-adaptive-scoring '(word line)) +(setq gnus-adaptive-word-length-limit 5) +(setq gnus-adaptive-word-no-group-words t) +(setq gnus-summary-mark-below -300) +(setq gnus-default-adaptive-score-alist + '( + <<gnus-adaptive-scoring-wo-from>>)) +(setq gnus-default-adaptive-word-score-alist + `((,gnus-read-mark . 10) + (,gnus-catchup-mark . -4) + (,gnus-killed-mark . -15) + (,gnus-del-mark . -8)) + ) +;; (setq gnus-adaptive-word-score-alist gnus-default-adaptive-word-score-alist) +#+end_src +****** Scoring rules +Scoring based on the =from= header does not make sense for rss feeds with only one author or newsgroups with unset author. These files therefore contain my default adaptive scoring rules with or without =from= scoring. +#+NAME: gnus-adaptive-scoring-w-from +#+begin_src emacs-lisp :tangle no :eval never +(gnus-unread-mark) +(gnus-ticked-mark (from 4)) +(gnus-dormant-mark (from 5)) +(gnus-del-mark (from -4) (subject -50)) +(gnus-read-mark (from 5) (subject 100)) +(gnus-expirable-mark) +(gnus-killed-mark (from -5) (subject -300) (followup -150)) +(gnus-kill-file-mark) +(gnus-ancient-mark) +(gnus-low-score-mark) +(gnus-catchup-mark (from -2) (subject -40)) +#+end_src +#+NAME: gnus-adaptive-scoring-wo-from +#+begin_src emacs-lisp :tangle no :eval never +(gnus-unread-mark) +(gnus-ticked-mark) +(gnus-dormant-mark) +(gnus-del-mark (subject -50)) +(gnus-read-mark (subject 100)) +(gnus-expirable-mark) +(gnus-killed-mark (subject -300) (followup -150)) +(gnus-kill-file-mark) +(gnus-ancient-mark) +(gnus-low-score-mark) +(gnus-catchup-mark (subject -40)) +#+end_src +Unfortunately setting these on a per group basis does not work currently as it would (at least) override the word scoring setting. So I stick with the same adaptive scoring rules for all groups set above. +***** Misc Options +To ensure filenames compatible with Windows and stuff: +#+begin_src emacs-lisp +(setq nnheader-file-name-translation-alist '((?: . ?_) (?[ . ?_) (?] . ?_))) +#+end_src + +Slow scoring decay prevents huge scores from building up. Only run on =.ADAPT= score files and decay each scoring rule by 1 point or 1%, whichever is larger. +#+begin_src emacs-lisp +(setq gnus-decay-scores "\\.ADAPT\\'" + gnus-score-decay-constant 1 + gnus-score-decay-scale 0.01) +#+end_src +***** Ignored Words +Do not score on some common german words. I extracted these from my score file after a few weeks of using scoring. +#+begin_src emacs-lisp +(setq gnus-ignored-adaptive-words + '("loswerden" "teilweise" "übernahme" "betrieb" "kündigt" "schnittstelle" "abgewendet" "hälfte" "massiv" "massivst" "angeblich" "verschleppt" "startup" "auslistung" "wichtiger" "öffentliches" "verwenden" "asynchron" "lieber" "arbeite" "zahlreiche" "november" "entscheidung" "käufer" "findet" "mittlere" "vorstoß" "starker" "erreicht" "letzte" "geplant" "september" "nachfolger" "ankündigen" "mildern" "antrieb" "lassen" "aufsteigen" "entdeckt" "hinweise" "bedingungen" "miniserie" "funktioniert" "umfragen" "angreifbare" "fiasko" "prüfstand" "sparsamer" "steigt" "zugangsdaten" "tutorial" "details" "verfahren" "verschiebt" "enorme" "schlechtere" "erwarten" "optimierungen" "aushalten" "kratzer" "stürze" "gelöscht" "getestet" "stalker" "showcase" "warnung" "maßnahmenplan" "konstruieren" "deutsches" "großen" "probefahrt" "interesse" "preise" "verteilt" "leaken" "günstiger" "umgerüstet" "ausflug" "edition" "definitive" "schützen" "zeiten" "größte" "sicherer" "falsches" "schnelles" "wollte" "angebunden" "externe" "aktualisiertes" "zweiten" "limitiert" "überraschend" "unsicher" "schonfrist" "strukturiert" "historisches" "riesige" "gründet" "mitarbeiter" "geleakt" "mutmaßlichem" "idiotensicher" "stunden" "zornige" "schwächer" "funktionierende" "meinen" "meisten" "geringer" "gewinnen" "rennen" "halten" "synchronisation" "normal" "riesiges" "bessere" "enthält" "integriert" "project" "zurücknehmen" "verursacht" "bleibt" "angeschlossene" "verbrauchen" "berichtet" "ausmachen" "unterschied" "stoppen" "weiterhin" "ausschluss" "schaffen" "exklusives" "riesiger" "keinen" "verbesserter" "steckt" "kündigen" "dienste" "erwägt" "dürfen" "demonstriert" "unerlaubter" "möglichkeiten" "unendlicher" "unbegrenzte" "vermehrt" "greift" "veröffentlicht" "komplett" "warten" "blockiert" "freier" "erscheinen" "reicht" "fliegen" "eigene" "erweitert" "sollen" "könnte" "erscheint" "können" "arbeiten" "eigenen" "lieferbar" "kostet" "kommen" "startet" "zurück" "bestätigt" "schnell" "bietet" "unterstützen" "zahlen" "bekommt" "ersten" "schneller" "verkauft" "kaufen" "machen" "vorgestellt" "bringt" "offenbar" "geräte" "präsentiert" "videos" "stellt" "schließt" "werden" "erhält" "wieder" "endlich" "verfügbar" "deutsche" + )) +#+end_src +**** Registry +Use the [[info:gnus#The Gnus Registry][Gnus Registry]]. This is required to use [[id:990e2668-11d6-45eb-9c9b-1dc0b89b556d][Gnorb]]. +#+begin_src emacs-lisp +(gnus-registry-initialize) +#+end_src +Remove some groups from being saved to the registry +#+begin_src emacs-lisp +(setq gnus-registry-split-strategy 'majority) +(setq gnus-registry-ignored-groups + '(("^nnrss" t) + ("^nnreddit" t) + ("^nntp" t) + ("delayed$" t) + ("drafts$" t) + ("queue$" t) + ("INBOX$" t) + ("^nnmairix:" t) + ("^nnir:" t) + ("archive" t) + )) +#+end_src +#+begin_src emacs-lisp :tangle no :noweb-ref secondary-select-methods +(add-to-list 'gnus-secondary-select-methods '(nngnorb "Gnorb server")) +#+end_src +Enable gnorb tracking +#+begin_src emacs-lisp +(gnorb-tracking-initialize) +#+end_src +Hint for existing relevant tracked conversations in the summary buffer (see [[info:gnorb#Hinting in Gnus][info:gnorb#Hinting in Gnus]]). Already tracked messages are marked with =&= and new maybe relevant messages with =¡=. +#+begin_src fundamental :tangle no :noweb-ref gnorb-summary-line-format +%ug +#+end_src +Display [[info:gnorb#Tagging Messages and Contacts][message tags]] in the summary line. Stop other summary line content at column 120 and insert the tags after. +#+begin_src fundamental :tangle no :noweb-ref gnorb-summary-tags +%-120=%uG +#+end_src +Also automatically set message tags +#+begin_src emacs-lisp +(setq gnorb-gnus-auto-tag-messages t) +#+end_src +**** Gnus Cloud +The [[info:gnus#The Gnus Cloud][Gnus Cloud]] lets you synchronize marks and general data (whatever that is) across different machines. +This seems more complete than manually (with Nextcloud, …) syncing the news related files (=~/.newsrc.eld=, =~/News=, …).+ + +To enable it go to the gnus server buffer and mark the servers to be synced with =i= and the (imap) server which is used as host with =I=. + +Commands to interact with the gnus cloud are prefixed with =~= in the group buffer. + +#+begin_src emacs-lisp :noweb yes +(use-package gnus-cloud + :custom + (gnus-cloud-method (concat "nnimap:" (caar private/personal-imap-info))) + (gnus-cloud-synced-files '("~/.authinfo.gpg" + ;; "~/.gnus.registry.eieio" + ;; (:directory "~/News" :match ".*.\\(SCORE\\|ADAPT\\)") + (:directory "~/git/projects/dotfiles" :match "[0-9]+-.*\\.patch"))) + (gnus-cloud-storage-method 'epg) + :config + <<gnus-cloud-config>> + ) +#+end_src + +***** Only download specific files +Gnus Cloud sync all newsrc data and the specified files. Sometimes one would only want to download and update only specific files without overwriting all newsrc data. + +This function is very similar to ~gnus-cloud-download-data~ but takes a regexp to match against filenames. Note that it does not update ~gnus-cloud-sequence~ (for now). So when only doing partial downloads repeatedly you may need to update ~gnus-cloud-sequence~ manually. +#+begin_src emacs-lisp :noweb-ref gnus-cloud-config +(defun fpi/gnus-cloud-download-some (regexp &optional sequence-override) + "Download and install files matching REGEXP." + (interactive "sRegexp to match: ") + (let ((articles nil) + (highest-sequence-seen gnus-cloud-sequence) + chunks) + (dolist (header (gnus-cloud-available-chunks)) + (let ((this-sequence (gnus-cloud-chunk-sequence (mail-header-subject header)))) + (when (> this-sequence (or sequence-override gnus-cloud-sequence -1)) + + (if (string-match (format "storage-method: %s" gnus-cloud-storage-method) + (mail-header-subject header)) + (progn + (push (mail-header-number header) articles) + (setq highest-sequence-seen (max highest-sequence-seen this-sequence))) + (gnus-message 1 "Skipping article %s because it didn't match the Gnus Cloud method %s: %s" + (mail-header-number header) + gnus-cloud-storage-method + (mail-header-subject header)))))) + (when articles + (nnimap-request-articles (nreverse articles) gnus-cloud-group-name) + (with-current-buffer nntp-server-buffer + (goto-char (point-min)) + (while (re-search-forward "^Gnus-Cloud-Version " nil t) + (beginning-of-line) + (push (gnus-cloud-parse-chunk) chunks) + (forward-line 1)))) + (mapcar (lambda (chunk) (fpi/gnus-cloud-update-some chunk regexp)) chunks))) + +(defun fpi/gnus-cloud-update-some (elems regexp) + (dolist (elem elems) + (let ((type (plist-get elem :type)) + (name (plist-get elem :file-name))) + (when (and (memq type '(:delete :file)) + (with-temp-buffer + (insert name) + (beginning-of-buffer) + (re-search-forward regexp nil t))) + (message "Match: Updating %s" name) + (gnus-cloud-update-file elem type))))) +(define-key gnus-group-mode-map (kbd "~ p") 'fpi/gnus-cloud-download-some) +#+end_src +*** Display +Sort by newest first +#+begin_src emacs-lisp +(setq gnus-article-sort-functions '((not gnus-thread-sort-by-date)) + gnus-thread-sort-functions '((not gnus-thread-sort-by-date))) +#+end_src +Unicode reply symbol +#+begin_src emacs-lisp +(setq gnus-summary-to-prefix "→ ") +#+end_src +Rename the group buffer to something more memorable. This is not intended to be customized. So some bugs may occur. So far it only seems important to set it before starting gnus the first time. So e.g. set it in your main emacs =init.el=. +#+begin_src emacs-lisp +(setq gnus-group-buffer "*Gnus*") +#+end_src +**** On threads +Gather loose threads, whose parent is currently not displayed, under a +dummy article. I find the default ~'adopt~ to be too confusing. +#+begin_src emacs-lisp +(setq gnus-summary-make-false-root 'dummy) +(setq gnus-summary-dummy-line-format " %(: :%) %S +") +(setq gnus-summary-make-false-root-always t) +#+end_src +Also try to connect threads by guessing which articles are missing +#+begin_src emacs-lisp +(setq gnus-fetch-old-headers nil) +(setq gnus-build-sparse-threads 'more) +#+end_src +Better thread display (from [[https://www.emacswiki.org/emacs/GnusFormatting][emacswiki/GnusFormatting)]]. +#+begin_src emacs-lisp +(setq gnus-summary-line-format (concat "%U%R%z" + "<<gnorb-summary-line-format>>" + " %(%&user-date; %-15,15f %B%s%) " + "<<gnorb-summary-tags>>" "\n") + gnus-user-date-format-alist '((t . "%y-%m-%d %H:%M")) + gnus-summary-thread-gathering-function 'gnus-gather-threads-by-references + gnus-sum-thread-tree-false-root "" + gnus-sum-thread-tree-indent " " + gnus-sum-thread-tree-leaf-with-other "├► " + gnus-sum-thread-tree-root "" + gnus-sum-thread-tree-single-leaf "╰► " + gnus-sum-thread-tree-vertical "│") +#+end_src +**** Topics +Disable indenting a topic. I always do it by accident. +#+begin_src emacs-lisp +(use-package gnus-topic + :delight + :config + (defun fpi/gnus-topic-toggle-topic () + "Toggle display of the topic." + (interactive) + (when (gnus-group-topic-p) + (if (equal 'visible + (nth 1 (cadr (gnus-topic-find-topology (gnus-current-topic))))) + (gnus-topic-hide-topic) + (gnus-topic-show-topic)))) + (define-key gnus-topic-mode-map (kbd "<tab>") 'fpi/gnus-topic-toggle-topic) + (define-key gnus-topic-mode-map (kbd "TAB") 'fpi/gnus-topic-toggle-topic)) +#+end_src +Function to toggle display of group levels in the group buffer. +#+begin_src emacs-lisp +(defvar gnus-group-line-format-wo-levels nil) +(defun fpi/gnus-group-toggle-levels () + (interactive) + (if gnus-group-line-format-wo-levels + (setq gnus-group-line-format gnus-group-line-format-wo-levels + gnus-group-line-format-wo-levels nil) + (setq gnus-group-line-format-wo-levels gnus-group-line-format + gnus-group-line-format (concat "[%L] " gnus-group-line-format))) + ;; Hack to update display + (gnus-group-get-new-news 0)) +(define-key gnus-topic-mode-map (kbd "T L") 'fpi/gnus-group-toggle-levels) +#+end_src +**** Window Layout +See [[info:gnus#Window Layout][info:gnus#Window Layout]]. +#+begin_src emacs-lisp +(setq gnus-use-full-window nil) +#+end_src +**** Article Display +#+begin_src emacs-lisp +(use-package gnus-art + :hook (gnus-article-mode . prose-mode)) +#+end_src +**** Modeline indicator +From the [[https://www.emacswiki.org/emacs/GnusNotify][emacswiki Gnus Notify]]. +#+begin_quote +[…] use ~G p~ in the group buffer, then add ~(modeline-notify t)~ […] +#+end_quote +Activate with [[elisp:gnus-mst-show-groups-with-new-messages]]. +Code: +#+begin_src emacs-lisp +;;; gnus-notify.el --- use the modeline to indicate groups with new messages + +;; Author: Mark Triggs <mark@dishevelled.net> +;; +;; Contributions from: Frederic Couchet <fcouchet AT april.org> + +;; This file is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation; either version 2, or (at your option) +;; any later version. + +;; This file is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs; see the file COPYING. If not, write to +;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +;; Boston, MA 02111-1307, USA. + +;;; Commentary: + +;; This code provides modeline notification of when certain groups contain +;; unread messages. Groups for whom unread messages should be indicated are +;; chosen by setting a group parameter. + +;; Clicking on a group in the modeline will enter that group and view the new +;; message. + +;; Code: + +(require 'cl-lib) + +(defvar gnus-notify-show-unread-counts t + "If true, show the number of unread messages in the modeline in addition to shortened group names.") + + +(when (fboundp 'gnus-define-group-parameter) + (gnus-define-group-parameter + modeline-notify + :type bool + :parameter-type '(const :tag "Notify of new messages for this group." t) + :parameter-document "\ + +If this is set, the name of this group will be placed on the modeline when it +contains new messages")) + +(defvar gnus-mst-display-new-messages "") +(defvar gnus-mst-notify-groups '()) +(defvar gnus-notify-jump-to-group-hook '() + "This hook is invoked before jumping to a gnus group with unread messages. + Each hook should take a single argument - the GROUP to be selected") + + +(add-hook 'gnus-exit-gnus-hook + (lambda () + (setq gnus-mst-display-new-messages ""))) + + +(defun gnus-mst-notify-modeline-form () + gnus-mst-display-new-messages) + + +(if (featurep 'xemacs) + (unless (member 'gnus-mst-display-new-messages global-mode-string) + (if (null global-mode-string) + (setq global-mode-string '("" gnus-mst-display-new-messages)) + (setq global-mode-string + (append global-mode-string + '(gnus-mst-display-new-messages))))) + (unless (member '(:eval (gnus-mst-notify-modeline-form)) global-mode-string) + (setq global-mode-string + (append global-mode-string + (list '(:eval (gnus-mst-notify-modeline-form))))))) + + +(defun gnus-mst-notify-shorten-group-name (group) + "shorten the group name to make it better fit on the modeline" + (let ((name (if (string-match ":" group) + (cadr (split-string group "[:]")) + group))) + (mapconcat 'identity + (mapcar + (lambda (segment) + (string (elt segment 0))) + (split-string name "[\\./]")) + "."))) + + +(defun gnus-mst-notify-update-modeline () + "Update the modeline to show groups containing new messages" + (if gnus-mst-notify-groups + (setq gnus-mst-display-new-messages + (append (list " [m: ") + (cl-maplist + (lambda (sublist) + (let ((group (car sublist)) + (map (make-sparse-keymap))) + (define-key map [mode-line mouse-1] + `(lambda () + (interactive) + (run-hook-with-args + 'gnus-notify-jump-to-group-hook ,group) + (gnus-group-read-group nil nil ,group))) + (cl-list* + (list ':propertize + (if gnus-notify-show-unread-counts + (format "[%s %s]" + (gnus-mst-notify-shorten-group-name + (car sublist)) + (gnus-group-unread (car sublist))) + (format "%s" + (gnus-mst-notify-shorten-group-name + (car sublist)))) + 'face 'bold + 'keymap map + 'help-echo "Visit this group") + (if (cdr sublist) + (list ", ") + nil)))) + gnus-mst-notify-groups) + (list "] "))) + (setq gnus-mst-display-new-messages ""))) + + +(defun gnus-mst-notify-group (group) + "Add notification for this group" + (unless (member group gnus-mst-notify-groups) + (add-to-list 'gnus-mst-notify-groups group t) + (gnus-mst-notify-update-modeline))) + + +(defun gnus-mst-show-groups-with-new-messages (&rest ignored) + (interactive) + (setq gnus-mst-notify-groups '()) + (gnus-mst-notify-update-modeline) + (mapc #'(lambda (g) + (let* ((group (car g)) + (unread (gnus-group-unread group))) + (when (and (cdr (assoc 'modeline-notify + (gnus-group-find-parameter group))) + (and (numberp unread) (> unread 0))) + (gnus-mst-notify-group group)))) + gnus-newsrc-alist)) + + +(add-hook 'gnus-after-getting-new-news-hook + 'gnus-mst-show-groups-with-new-messages) + + +(add-hook 'gnus-summary-exit-hook + 'gnus-mst-show-groups-with-new-messages) + + +(provide 'gnus-notify) +;;; gnus-notify.el ends here +#+end_src +*** Misc +**** nnreddit +#+begin_src emacs-lisp +(use-package nnreddit + :straight t) +(add-to-list 'gnus-secondary-select-methods '(nnreddit "")) +#+end_src diff --git a/gpg-agent.org b/gpg-agent.org new file mode 100644 index 0000000..1db4895 --- /dev/null +++ b/gpg-agent.org @@ -0,0 +1,51 @@ +#+PROPERTY: header-args:conf :tangle tangle/gpg-agent.conf :comments org :tangle-mode (identity #o444) + +#+BEGIN_SRC sh :tangle tangle/symlink.sh :results silent :shebang "#!/bin/bash" +ln -siv $(pwd)/tangle/gpg-agent.conf ~/.gnupg/gpg-agent.conf +ln -siv $(pwd)/tangle/sshcontrol ~/.gnupg/sshcontrol +ln -siv $(pwd)/tangle/pam-gnupg ~/.config/pam-gnupg +#+END_SRC + + +#+BEGIN_SRC conf +default-cache-ttl 10800 +max-cache-ttl 172800 +#+END_SRC +* ssh password caching +#+BEGIN_SRC conf +default-cache-ttl-ssh 10800 +max-cache-ttl-ssh 172800 +#+END_SRC +* Emacs pinentry +#+BEGIN_SRC conf +allow-emacs-pinentry +allow-loopback-pinentry +#+END_SRC +* Enable use as ssh keys +#+begin_src conf +enable-ssh-support +#+end_src + +#+begin_src conf :tangle tangle/sshcontrol :comments no +4AFDEF6B35160F892F61666CE891B2456D755807 +#+end_src +* Unlocking upon login + +[[https://github.com/cruegge/pam-gnupg][pam-gnupg]] is an alternative to =gnome-keyring= to unlock gpg keys upon login. This only works when user and gpg key share the same passphrase. + +Start it by adding this to the relevant login pam files (in =/etc/pam.d=). +#+begin_src conf :tangle no +auth optional pam_gnupg.so store-only +session optional pam_gnupg.so +#+end_src +Allow preset passphrases for =pam-gnupg=. +#+begin_src conf +allow-preset-passphrase +#+end_src + + +The =pam-gnupg= config file only contains a list of keygrips of keys you want to unlock upon login. It works for both gpg and ssh keys. +#+begin_src conf :tangle tangle/pam-gnupg :comments no +DE37E13DE16DB3219D74410F4C20021624CC19E3 +4AFDEF6B35160F892F61666CE891B2456D755807 +#+end_src diff --git a/init-exwm.org b/init-exwm.org new file mode 100644 index 0000000..13d6523 --- /dev/null +++ b/init-exwm.org @@ -0,0 +1,451 @@ +#+PROPERTY: header-args:emacs-lisp :results silent +#+PROPERTY: header-args:emacs-lisp :tangle tangle/init-exwm.el :tangle-mode (identity #o444) + +* Starting EXWM +Either start exwm in =.xinitrc= or if using a display manager setup a desktop file similar to this: +##+HEADER: :tangle /sudo::/usr/share/xsessions/exwm.desktop +#+begin_src conf +[Desktop Entry] +Name=EXWM +Comment=Emacs X Window Manager +TryExec=exwm-start +Exec=exwm-start +Type=Application +#+end_src +With the =exwm-start= script: +##+HEADER: :tangle /sudo::/usr/local/bin/exwm-start +#+begin_src shell :tangle-mode (identity #o755) +#!/usr/bin/env sh + +export VISUAL=emacsclient +export EDITOR="$VISUAL" + +# exec dbus-launch --exit-with-session emacs --eval "(progn (load \"/home/fpi/git/projects/dotfiles/tangle/init-exwm.el\") (exwm-enable))" +# exec dbus-launch --exit-with-session emacs +gpg-agent --daemon +export SSH_AUTH_SOCK=$(gpgconf --list-dirs agent-ssh-socket) + +# exec dbus-launch --exit-with-session /home/fpi/.local/bin/emacs +export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus +exec /home/fpi/.local/bin/emacs +#+end_src +* EXWM config +#+begin_src emacs-lisp +(use-package exwm + :straight t) +#+end_src +When starting the client from .xinitrc, `save-buffer-kill-terminal' will +force-kill Emacs before it can run through `kill-emacs-hook'. +#+BEGIN_SRC emacs-lisp +(global-set-key (kbd "C-x C-c") 'save-buffers-kill-emacs) +#+END_SRC + +set keyboard +#+BEGIN_SRC emacs-lisp +(shell-command "setxkbmap -layout \"de(neo),us,ru,de\"") +#+END_SRC + +** Monitor setup +#+BEGIN_SRC emacs-lisp +(use-package exwm-randr + :config + (setq exwm-randr-workspace-output-plist + (when (equal fpi/current-device "pan") '(0 "DisplayPort-4" 1 "DisplayPort-6"))) + ;; (when (equal system-name "pan") + ;; (start-process-shell-command "xrandr" nil "xrandr --output DisplayPort-0 --off --output DisplayPort-1 --off --output DisplayPort-2 --off --output HDMI-A-0 --off --output DisplayPort-3 --mode 2560x1440 --pos 0x612 --rotate normal --output DisplayPort-4 --off --output DisplayPort-5 --mode 2560x1440 --pos 2560x0 --rotate right --output DisplayPort-6 --off") + ;; (exwm-workspace-add)) + (exwm-randr-enable)) +#+END_SRC +** functions +#+BEGIN_SRC emacs-lisp +(defun ambrevar/switch-to-last-buffer () + "Switch to last open buffer in current window." + (interactive) + (switch-to-buffer (other-buffer (current-buffer) 1))) + +(defun ambrevar/toggle-window-dedicated () + "Toggle whether the current active window is dedicated or not. +Run it in each window you want to 'freeze', i.e. prevent Emacs +from acting on it." + (interactive) + (message + (if (let ((window (get-buffer-window (current-buffer)))) + (set-window-dedicated-p window + (not (window-dedicated-p window)))) + "Window '%s' is dedicated" + "Window '%s' is normal") + (current-buffer))) + +(defun ambrevar/toggle-window-split () + "Switch between vertical and horizontal split. +It only works for frames with exactly two windows." + (interactive) + (if (= (count-windows) 2) + (let* ((this-win-buffer (window-buffer)) + (next-win-buffer (window-buffer (next-window))) + (this-win-edges (window-edges (selected-window))) + (next-win-edges (window-edges (next-window))) + (this-win-2nd (not (and (<= (car this-win-edges) + (car next-win-edges)) + (<= (cadr this-win-edges) + (cadr next-win-edges))))) + (splitter + (if (= (car this-win-edges) + (car (window-edges (next-window)))) + 'split-window-horizontally + 'split-window-vertically))) + (delete-other-windows) + (let ((first-win (selected-window))) + (funcall splitter) + (if this-win-2nd (other-window 1)) + (set-window-buffer (selected-window) this-win-buffer) + (set-window-buffer (next-window) next-win-buffer) + (select-window first-win) + (if this-win-2nd (other-window 1)))))) + +(defun ambrevar/toggle-single-window () + "Un-maximize current window. +If multiple windows are active, save window configuration and +delete other windows. If only one window is active and a window +configuration was previously save, restore that configuration." + (interactive) + (if (= (count-windows) 1) + (when single-window--last-configuration + (set-window-configuration single-window--last-configuration)) + (setq single-window--last-configuration (current-window-configuration)) + (delete-other-windows))) +#+END_SRC +*** Window swapping +#+BEGIN_SRC emacs-lisp +(defun ambrevar/swap-windows (&optional w1 w2) + "If 2 windows are up, swap them. +Else if W1 is a window, swap it with current window. +If W2 is a window too, swap both." + (interactive) + (unless (or (= 2 (count-windows)) + (windowp w1) + (windowp w2)) + (error "Ambiguous window selection")) + (let* ((w1 (or w1 (car (window-list)))) + (w2 (or w2 + (if (eq w1 (car (window-list))) + (nth 1 (window-list)) + (car (window-list))))) + (b1 (window-buffer w1)) + (b2 (window-buffer w2)) + (s1 (window-start w1)) + (s2 (window-start w2))) + (with-temp-buffer + ;; Some buffers like EXWM buffers can only be in one live buffer at once. + ;; Switch to a dummy buffer in w2 so that we don't display any buffer twice. + (set-window-buffer w2 (current-buffer)) + (set-window-buffer w1 b2) + (set-window-buffer w2 b1)) + (set-window-start w1 s2) + (set-window-start w2 s1)) + (select-window w1)) + +(defun ambrevar/swap-windows-left () + "Swap current window with the window to the left." + (interactive) + (ambrevar/swap-windows (window-in-direction 'left))) +(defun ambrevar/swap-windows-below () + "Swap current window with the window below." + (interactive) + (ambrevar/swap-windows (window-in-direction 'below))) +(defun ambrevar/swap-windows-above () + "Swap current window with the window above." + (interactive) + (ambrevar/swap-windows (window-in-direction 'above))) +(defun ambrevar/swap-windows-right () + "Swap current window with the window to the right." + (interactive) + (ambrevar/swap-windows (window-in-direction 'right))) +#+END_SRC +*** Volume & Brightness +#+BEGIN_SRC emacs-lisp +(defun exwm-brightness (incdec) + (shell-command (concat "xbacklight " incdec "10")) + (notifications-notify :title (substring (shell-command-to-string "xbacklight") 0 -1) + :replaces-id 6969 + :urgency 'low + :timeout 550)) + +(defun exwm-volume (incdec) + (notifications-notify + :title (format + "Volume %s" + (substring + (shell-command-to-string + (format "amixer -D pulse set Master 5%%%s|tail -n 1|cut -d '[' -f 2|cut -d ']' -f 1" + incdec)) 0 -1)) + :replaces-id 6968 + :urgency 'low + :timeout 550)) +(defun exwm-togglemute () + (interactive) + (notifications-notify + :title (format + "Volume %s" + (substring + (shell-command-to-string + "amixer -D pulse set Master toggle|tail -n 1|cut -d '[' -f 3|cut -d ']' -f 1") 0 -1)) + :replaces-id 6968 + :urgency 'low + :timeout 550)) +#+END_SRC +*** XF86 Multimedia keys +#+BEGIN_SRC emacs-lisp +(defun exwm-xf86audio (cmd) + ;; Control Spotify + (shell-command (concat "dbus-send --type=method_call --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player." cmd))) +#+END_SRC +*** Browser switching +#+BEGIN_SRC emacs-lisp +(defun fpi/helm-exwm-switch (class &optional program other-window) + "Switch to some EXWM windows belonging to CLASS. +If current window is not showing CLASS, switch to the last open CLASS window. +If there is none, start PROGRAM. + +If PROGRAM is nil, it defaults to CLASS. +With prefix argument or if OTHER-WINDOW is non-nil, open in other window." + ;; If current window is not in `exwm-mode' we switch to it. Therefore we must + ;; also make sure that current window is not a Helm buffer, otherwise calling + ;; this function will lose focus in Helm. + (unless helm-alive-p + (setq program (or program class) + other-window (or other-window current-prefix-arg)) + (let ((filter (lambda () + (member (downcase (or exwm-class-name "")) class)))) + (if (and (eq major-mode 'exwm-mode) + (funcall filter)) + (let ((helm-buffer-details-flag nil)) + (helm-exwm filter)) + (let ((last (buffer-list))) + (while (and last + (not (with-current-buffer (car last) + (and (eq major-mode 'exwm-mode) + (funcall filter))))) + (setq last (cdr last))) + (if last + (funcall (if other-window 'switch-to-buffer-other-window 'switch-to-buffer) (car last)) + (when other-window (select-window (split-window-sensibly))) + (start-process-shell-command program nil program))))))) + +(defun fpi/helm-exwm-switch-browser () + "Switch to some `browse-url-generic-program' windows. + +See `helm-exwm-switch'." + (interactive) + (fpi/helm-exwm-switch (quote ("qutebrowser" + "firefox")) + browse-url-generic-program)) +#+END_SRC +** config +Time & Battery display +#+BEGIN_SRC emacs-lisp +(display-time) +(when (eq (fpi/current-device-info :type) 'mobile) + (display-battery-mode)) +#+END_SRC +Rename buffer to window title.\\ +Spotify's title does not include "spotify" while playing music so just +append it. +#+BEGIN_SRC emacs-lisp +(defun fpie/exwm-rename-buffer-to-title () + (let ((newname (if (string-match "Spotify" (buffer-name)) + (concat exwm-title " - Spotify") + exwm-title))) + (exwm-workspace-rename-buffer newname))) + +(add-hook 'exwm-update-title-hook 'fpie/exwm-rename-buffer-to-title) +#+END_SRC +#+BEGIN_SRC emacs-lisp +(add-hook 'exwm-floating-setup-hook 'exwm-layout-hide-mode-line) +(add-hook 'exwm-floating-exit-hook 'exwm-layout-show-mode-line) +#+END_SRC + +Non-floating resizing with mouse +#+BEGIN_SRC emacs-lisp +(setq window-divider-default-bottom-width 2 + window-divider-default-right-width 2) +(window-divider-mode) +#+END_SRC +System tray +#+BEGIN_SRC emacs-lisp +(use-package exwm-systemtray + :straight exwm) +(exwm-systemtray-enable) +(setq exwm-systemtray-height 16) +#+END_SRC ++auto focus+ +#+BEGIN_SRC emacs-lisp :tangle no +(setq mouse-autoselect-window t + focus-follows-mouse t) +#+END_SRC +List all buffers +#+BEGIN_SRC emacs-lisp +(setq exwm-workspace-show-all-buffers t) +(setq exwm-layout-show-all-buffers t) +#+END_SRC +*** Helm +#+BEGIN_SRC emacs-lisp :results silent +(with-eval-after-load 'helm + ;; Need `with-eval-after-load' here since 'helm-map is not defined in 'helm-config. + (define-key helm-map (kbd "s-\\") 'helm-toggle-resplit-and-swap-windows) + (exwm-input--set-key (kbd "s-p") 'helm-run-external-command) + (exwm-input-set-key (kbd "s-c") 'helm-resume) + (exwm-input-set-key (kbd "s-b") 'helm-mini) + (exwm-input-set-key (kbd "s-f") 'helm-find-files) + (exwm-input-set-key (kbd "s-F") 'helm-locate) + ;;(when (fboundp 'ambrevar/helm-locate-meta) + ;; (exwm-input-set-key (kbd "s-F") #'ambrevar/helm-locate-meta)) + ;;(exwm-input-set-key (kbd "s-g") 'ambrevar/helm-grep-git-or-ag) + ;;(exwm-input-set-key (kbd "s-G") 'ambrevar/helm-grep-git-all-or-ag) + ) + +(use-package helm-exwm + :straight t) +(exwm-input-set-key (kbd "s-w") #'fpi/helm-exwm-switch-browser) +(exwm-input-set-key (kbd "s-W") #'helm-exwm-switch-browser-other-window) +#+END_SRC +*** Keys +Global bindings +#+BEGIN_SRC emacs-lisp +(exwm-input-set-key (kbd "s-K") #'exwm-reset) +(exwm-input-set-key (kbd "s-x") #'exwm-input-toggle-keyboard) + +(exwm-input-set-key (kbd "s-s") #'windmove-left) +(exwm-input-set-key (kbd "s-n") #'windmove-down) +(exwm-input-set-key (kbd "s-r") #'windmove-up) +(exwm-input-set-key (kbd "s-t") #'windmove-right) + +(exwm-input-set-key (kbd "s-B") #'ibuffer-list-buffers) +(exwm-input-set-key (kbd "s-X") #'kill-this-buffer) + +(exwm-input-set-key (kbd "s-M") #'exwm-workspace-switch) + +(exwm-input-set-key (kbd "s-\\") 'ambrevar/toggle-window-split) +(exwm-input-set-key (kbd "s-S") 'ambrevar/swap-windows-left) +(exwm-input-set-key (kbd "s-N") 'ambrevar/swap-windows-below) +(exwm-input-set-key (kbd "s-R") 'ambrevar/swap-windows-above) +(exwm-input-set-key (kbd "s-T") 'ambrevar/swap-windows-right) + +(exwm-input-set-key (kbd "s-<tab>") #'ambrevar/switch-to-last-buffer) +(exwm-input-set-key (kbd "s-<return>") #'vterm) +(exwm-input-set-key (kbd "S-s-<return>") (lambda () + (interactive) + (start-process "term" nil "tilix"))) +(exwm-input-set-key (kbd "s-h") 'bury-buffer) + +(exwm-input-set-key (kbd "s-g") 'previous-buffer) +(exwm-input-set-key (kbd "s-G") 'next-buffer) +#+END_SRC +#+BEGIN_SRC emacs-lisp +(exwm-input-set-key (kbd "s-!") 'helm-pass) +#+END_SRC +Volume & Brightness +#+BEGIN_SRC emacs-lisp +(exwm-input-set-key [XF86AudioLowerVolume] (lambda () (interactive) (exwm-volume "-"))) +(exwm-input-set-key [XF86AudioRaiseVolume] (lambda () (interactive) (exwm-volume "+"))) +(exwm-input-set-key [XF86AudioMute] 'exwm-togglemute) +(exwm-input-set-key [XF86MonBrightnessUp] (lambda () (interactive) (exwm-brightness "+"))) +(exwm-input-set-key [XF86MonBrightnessDown] (lambda () (interactive) (exwm-brightness "-"))) +#+END_SRC +XF86 Multimedia Keys +#+BEGIN_SRC emacs-lisp +(exwm-input--set-key [XF86AudioPlay] (lambda () (interactive) (exwm-xf86audio "PlayPause"))) +(exwm-input--set-key [XF86AudioPause] (lambda () (interactive) (exwm-xf86audio "PlayPause"))) +(exwm-input--set-key [XF86AudioNext] (lambda () (interactive) (exwm-xf86audio "Next"))) +(exwm-input--set-key [XF86AudioPrev] (lambda () (interactive) (exwm-xf86audio "Previous"))) +#+END_SRC +**** Local bindings +#+BEGIN_SRC emacs-lisp +(push ?\s- exwm-input-prefix-keys) +(define-key exwm-mode-map (kbd "s-SPC") #'exwm-floating-toggle-floating) +(define-key exwm-mode-map (kbd "s-i") #'follow-delete-other-windows-and-split) ;; any useful? +(define-key exwm-mode-map (kbd "s-o") #'ambrevar/toggle-single-window) +(define-key exwm-mode-map (kbd "s-O") #'exwm-layout-toggle-fullscreen) + +(define-key exwm-mode-map (kbd "C-q") #'exwm-input-send-next-key) +#+END_SRC +Allow access to my personal keymap. +#+BEGIN_SRC emacs-lisp +(push ?\C-z exwm-input-prefix-keys) +#+END_SRC + +**** Simulation keys +#+BEGIN_SRC emacs-lisp +(setq exwm-input-simulation-keys + '(([?\C-b] . [left]) + ([?\C-f] . [right]) + ([?\C-p] . [up]) + ([?\C-n] . [down]) + ([?\C-a] . [home]) + ([?\C-e] . [end]) + ([?\M-v] . [prior]) + ([?\C-v] . [next]) + ([?\C-d] . [delete]))) + ;;([?\C-k] . [S-end delete]))) ; doesn't work in tilix +#+END_SRC +*** Configure helm-raise-command +~(shell-command "emacsclient -e ...")~ does not work. Advice +~helm-run-or-raise~ instead and overshadow ~shell-command~. + +For now ~helm-run-or-raise~ is redefined after helm is loaded in +~emacs-init.org~ instead of advised. +#+begin_src emacs-lisp +(defun fpi/get-proc-buffers (proc) + (let ((cand (helm-exwm-candidates))) + (remove + nil (mapcar + (lambda (c) + (if (equal + (downcase proc) + (downcase (with-current-buffer c (or exwm-class-name "")))) + c + nil)) cand)))) +(defun fpi/switch-to-proc-buffer (proc) + (switch-to-buffer (car (fpi/get-proc-buffers proc)))) + +;; (setq helm-raise-command "emacsclient -e '(fpi/switch-to-proc-buffer \"%s\")'") +(setq helm-raise-command t) +#+end_src +*** Screenshots +UncleDave has a nice exwm configuration in his [[https://github.com/daedreth/UncleDavesEmacs/blob/master/config.org][config]]. These snippets +are taken from there. + +A nice alternative for screenshots in org-mode is ~org-screenshot.el~. +It uses ~scrot~ to take screenshots of windows and insert a link the +image into the current org buffer. + +**** Screenshotting the entire screen +#+BEGIN_SRC emacs-lisp + (defun daedreth/take-screenshot () + "Takes a fullscreen screenshot of the current workspace" + (interactive) + (when window-system + (loop for i downfrom 3 to 1 do + (progn + (message (concat (number-to-string i) "...")) + (sit-for 1))) + (message "Cheese!") + (sit-for 1) + (start-process "screenshot" nil "import" "-window" "root" + (concat (getenv "HOME") "/" (subseq (number-to-string (float-time)) 0 10) ".png")) + (message "Screenshot taken!"))) + (global-set-key (kbd "<print>") 'daedreth/take-screenshot) +#+END_SRC + +**** Screenshotting a region +#+BEGIN_SRC emacs-lisp +(defun daedreth/take-screenshot-region () + "Takes a screenshot of a region selected by the user." + (interactive) + (when window-system + (call-process "import" nil nil nil ".newScreen.png") + (call-process "convert" nil nil nil ".newScreen.png" "-shave" "1x1" + (concat (getenv "HOME") "/" (subseq (number-to-string (float-time)) 0 10) ".png")) + (call-process "rm" nil nil nil ".newScreen.png"))) +;; (global-set-key (kbd "<Scroll_Lock>") 'daedreth/take-screenshot-region) +#+END_SRC diff --git a/ledgerrc.org b/ledgerrc.org new file mode 100644 index 0000000..78b9f31 --- /dev/null +++ b/ledgerrc.org @@ -0,0 +1,32 @@ +#+PROPERTY: header-args:conf :tangle tangle/.ledgerrc :results silent :tangle-mode (identity #o444) + +#+begin_src conf +--file ~/git/projects/ledger/main.ledger +#+end_src +#+begin_src shell :tangle tangle/symlink.sh :shebang "#!/bin/bash" :results silent +ln -siv $(pwd)/tangle/.ledgerrc ~/ +ln -siv $(pwd)/tangle/report ~/.local/bin/ +#+end_src + +The =report= script can be used for simple plotting of ledger output using gnuplot. This is taken directly from the ledger git repo. +#+begin_src shell :tangle tangle/report :shebang "#!/usr/bin/env sh" :tangle-mode (identity #o555) +# This script facilities plotting of a ledger register report. If you +# use OS/X, and have AquaTerm installed, you will probably want to set +# LEDGER_TERM to "aqua". +# +# Examples of use: +# +# report -j -M reg food # plot monthly food costs +# report -J reg checking # plot checking account balance + +if [ -z "$LEDGER_TERM" ]; then + LEDGER_TERM="wxt persist" +fi + +(cat <<EOF; ledger "$@") | gnuplot + set terminal $LEDGER_TERM + set xdata time + set timefmt "%Y-%m-%d" + plot "-" using 1:2 with linespoints +EOF +#+end_src diff --git a/mail.org b/mail.org new file mode 100644 index 0000000..e56ce6c --- /dev/null +++ b/mail.org @@ -0,0 +1,472 @@ +# -*- buffer-auto-save-file-name: nil; -*- +#+PROPERTY: header-args:conf :tangle-mode (identity #o444) +* Intro + +This file describes my mail setup using +- =mbsync= (isync) to get mail from the mail server and save it + locally +- =notmuch= for tagging-based mail searching and organization + integrated into emacs +- =afew= to provide initial tagging for new mail to notmuch +- =msmtp= to actually send the mail written in emacs + +* mbsync +:PROPERTIES: +:header-args: :tangle tangle/.mbsyncrc :eval never :exports code :results silent +:END: + +The config for mbsync is described in =~/.mbsyncrc=. +#+BEGIN_SRC conf +# IMAP keeps an "internaldate" attribute for messages, which is separate +# from the date given in the message header, set based upon when the +# message was first received. Fastmail's webmail interface at least +# uses this attribute to properly order messages chronologically. +# The CopyArrivalDate option isn't well documented but it seems that when +# synchronising a new message it uses the Maildir file's Modify date as the +# IMAP internaldate attribute and vice versa. Otherwise it seemed the +# synchronisation time was being used instead. By setting the option here it's +# enabled by default for all Channels. +#+END_SRC + +#+BEGIN_SRC conf +# 1st Account GMX +IMAPAccount gmx +# Address to connect to +Host imap.gmx.net +#+end_src +** My mail address :crypt: +-----BEGIN PGP MESSAGE----- + +hQGMA/lzu+pplFIbAQv6Ap/2jmc78BmLzE/M/u/8kMyiBmXuGY6p2S92aRXi2A5a +RzZgox9A3hs1OtUlrFS3n+/qGJu6ufzHFU+NC/xblDCPHJakn8LHiGufqG09B5v5 +F1iDYO7x8+ehcNvfjqBjsrOdqJfkpq57yyzKgO0EwZ65tP+OxOcunINfyOmzDXId +K6Y+ZTVLYKVHpGhdC52t8jXmFCEZyatBlMKMUizVBrGUoHjKXpwbU3D5OyJoSqA7 +QidGC6XNxlGQNjtJLMapSBrNy3srWkprZDhXFersxDNIpfY1+HWAGmnhUbp/1XI8 +rH86gtzZ1xeaVAC7Q0ZUssQ23naIdRlxDM7zMpeH0LXkvC2ElT7JpK1H8XuVe0eH +PBPGleotvWXG6/DT/WLkHvNE/vHXOa4QhJCa2xaEWQP+n1REIXiSuM8YhoM90tY9 +++Xiux4APeeHKGds3Z8FxDS1TxKQ2ijZOXHLXJAcYKdIFBlA+voN79H2IzVz6k1l +TW2HS1eDpVImUrAkKs2Z0pwBcRFcsiTG6FQxJ0Y4qJGjsZK2llwDqptlDApshg7x +13f9wpJnm3qBHQT13sNhzz1Dy4AQsZXj3QEz+u00NqRWy6oVmwKTLQ5W0cXimLn5 +rOfIyOw2zAU9ZLP9yS8/KdONFgrv17bDcToYfjZFeJipHF4b/K0Uk2NSqoX6Hxtd +D9OhyiSwxcYYpY1+0OGQoYcKyAqS3fSu+0vgS48= +=ktHf +-----END PGP MESSAGE----- +** Rest of the configuration +#+begin_src conf :padline no +# Use SSL +SSLType IMAPS +# The following line should work. If get certificate errors, uncomment the two following lines and read the "Troubleshooting" section. +CertificateFile /etc/ssl/certs/ca-certificates.crt +#CertificateFile ~/.cert/imap.gmail.com.pem +#CertificateFile ~/.cert/Equifax_Secure_CA.pem + +IMAPStore gmx-remote +Account gmx + +MaildirStore gmx-local +# The trailing "/" is important +Path ~/Maildir/gmx/ +Inbox ~/Maildir/gmx/INBOX +Flatten . +SubFolders Verbatim + +Channel gmx +Master :gmx-remote: +Slave :gmx-local: +# Exclude everything under the internal [Gmail] folder, except the interesting folders +#Patterns * ![Gmail]* "[Gmail]/Sent Mail" "[Gmail]/Starred" "[Gmail]/All Mail" +# Or include everything +Patterns * +# Automatically create missing mailboxes, both locally and on the server +Create Both +# Save the synchronization state files in the relevant directory +SyncState * +# Remove messages on master marked for deletion +Expunge Master + +Channel gmx-quick +Master :gmx-remote: +Slave :gmx-local: +Patterns INBOX +SyncState * +Sync Pull New + +########################################################## +#+END_SRC + +** More mail accounts :crypt: +-----BEGIN PGP MESSAGE----- + +hQGMA/lzu+pplFIbAQv/VIvFz9ywYSXo4DJPC0AoRgjUGTs/ECam7bosV+QAo8JA +4S+AlonfxROa+tuqC7Sd3GrK4BngJhf+lf7BqmJPr7/yjEAW/SA2IWxOypem3/6o +C62fhqtxAw2b6WT+zCpeCzG95zDIXJNxgqe2fATVpMtno3odV5NkinFxj3AQ20yw +80PIAxOGzPf4xtWmvAcNGD0jwKT8DYHo7Yexr78JYgp3cZNYs3jmO8NYfKoNFzV1 +fSBb07XYz/4v07alP4kwQETOg+ssGflGRknxk6W65XgQO2nm9QTtMhoGcVJtstpG +PYF8UUmg71mJv2GZb2+SxC7IFYbwLOJaYBVCOsZqwxKzy1EBmyhuIzgaJKZbB8EM +yMGKP6pJPoy6BKskALbsptF1cNrDVLWxdrOny3OcK+8JfhfH5MPGiV/u2xMa9sig +ERz6Hy1VY0S/MYt2P+m73G1AMTbN+Qiqp+/023cc3J5ZxaY0R+eZcd785mRQMh+O +fjLU+tlhx0xUUxoRLAT80ukB1sAqaJnn345dR1KMklHC5TFr81wp3zMu+2JoKnqu +/K8SCTo+1t/QkOaf51uGEa9uQ57mqTf9vQdXnQ/gdPGM59K/r75lR/ehVmus9rUW +qeOtBKSRdqTGVHVqLAK9aJ6blNpINSXWWQts0vsZistMpXrhQ5QSK1qIyHBa04Vj +tjzGHtNvRRSkj+eCKQynJDzxVFpw1ElyoHxs0lPItDOSLV3r9HQ9fCCD5e9hoRBm +zzkp4BCBc8WyB1kIUnz/TQvsTCNacbFxume6arysNzMWzQNNHusx/L/83AbTyJ28 +UK26CHvbSkKGYrxKHt5IEenrZFNr7gYNKMhYc/PH3+1hANA7kUXdasFQuIT7Ij1u +fHl7egsKI/k7wyKfKmgKa/FVT5MJ4V7fO3YX2oGAhuH704fhmG4mCMrot4Nz7Gq0 +uzAI7I2eayXQ2ZS83aE0FUhdk2BFCfR4R282PN/1uadAp/8MFDjIW7dhoktMDtST +JeODbnIrqD0kfnq+cCLTSqlHi06v1TeJvB0CS7AugsE4rgiitkN6ELUzKMZsruBx +hQom2CHPKQ7ZSa8tQnLNePIySWy9QO5KNT15ZuScRvXsxUU0awsQExk7asTpawHD +gdZE/n3ekRq9QAnsv0EmCITzGVBy573JCwNDNUwbGseLVeoW5sYJNDXtilRrXhdY +icCbQge6rn7fHqAnBWnxgvDKVcBFZJpVYa//6tIzSHLGDmYi3Kt0HXkf6PwYIvjz +jRHf1Xpy7VRNOA9JTCV5cw6khvpU2u8p+j90f68fsIDqMiLdlgsZSoSwLf2hvjqU +ZgB9W87oQr7yCEuVI41esNF0IhykxlAiJnSfEb8YYnp3DxDvwRF5SLyQCwuFOUpO +sf3KVSye/78roQRIkGLJXp5tdelOPAw+fJi7hv90o29xcieoEoPuwNDhCps4vylH +qPVtv0fcMBZEC1HQwSrrrmBUf0U4kTJntrs/YHAJcEdtGFry5Y7O9eWYX1IKnu2H +q/oq9Qp6mtv66nn61KEYfxx6Jc2dYwo6D+CVEHlLtICqqfPMLZi/toGaz7KPlPTq +/gYSbqIGwzKF6SvLy4vD84we3u65u+fcTnb9uqiLq/oUE83CP6sFapphARl6No9A +zLgC9FzBj5hqh3g2Kg4= +=q0eG +-----END PGP MESSAGE----- +* afew +:PROPERTIES: +:header-args: :tangle tangle/afew.config :eval never :exports code :results silent +:END: + +Config expected to be in =~/.config/afew/config=. + +~ArchiveSentMailsFilter~ entfernt den /new/ tag und danach werden keine +CustomFilter mehr angewendet. Um auch gesendete Mails richtig zu +taggen, wird ~ArchiveSentMailsFilter~ erst am Ende aufgerufen. +#+BEGIN_SRC conf +#default filter chain +[SpamFilter] +[KillThreadsFilter] +[ListMailsFilter] +[SentMailsFilter] +sent_tag = sent +#+end_src +** custom filters :crypt: +-----BEGIN PGP MESSAGE----- + +hQGMA/lzu+pplFIbAQv+LYa99pjG6frcwF8PbG43jAbZobloStIR4LrIwxMaZtYw +1mvUyZKG2L6VHRQaN2h8SiTzhnojw0iaT8Q0AyJTBiCaL6uJx+A5JNPrhC6vWLnK +MSBA4Bj8WTQrLstsl0FBu6az25QM0AE9RObqWeO3E+cym4x9ZpIKA8RXMqd6tIx6 +tsGE2XGCCm7N7pPoRmSnZS1/UmFD69zgSqG/DX0UdFA2I44kERSzQjTdFVxEmc+U +0RVtK3ykeQfmqv1gxBCp96jXzjhHkt0UeiHmsjUQfQA5SSAKY0kMODGh789P6uVa +tfUs7TnrnQJAsEm+Wa+y4ffr+7zoyCyVsupE/EXRf84sXHs34gReh2AJy7mx138I +x1hdEG+eO0xnByxvkcOdGs4CeyuXp46nHEHSzOuwX0tJ2BrGvV5lDYCVjuYQPQsi +gGhickbpzARIrQp767oKNMkIca67VsOoRKf2h4bogI01997e3bR/rIsL+Fco9JOd +o6SXcZm9Twrip3s+MP2G0ukBkXs0lxDQw/2zQWXjjRBUqAeb+kYCGCNVpRRoBWZK +OK09HRuAtgwGQh+B1+JeXhCGoK+JB0EIChIbSJj9NypfTxCe8Iqm9iV8aXfbboK8 +dTGONnltE7PXT/4piF13zZiDkPEHWU7wgIXKcIjtblqYPakkXD26IveZZtaPEJdR +uKuCU6WtgPc28gt5vokzny59kQPJVAWQKY9zTiQGkUz1tWhJCh+KR3sjp/zgYPXb +Mze40oi+LRpEAgDhu+J8zztnXQgfQuFqjO+erW4qTkoxaw11d/IbGFUIdf4EcZF7 +S8eJKUAksNUqUxvMSKkG5dJqr/ApcBEfNtZjuBorphm9VSimWcQblpc4jy8rS0lq +ZeGHkzW2b5Oni6dp0VX+86gp7eHrxLoIQAec6IbD58r+uZfucC4mcdFI4D9+WeSV +ZmT9KwnY5xvQBW3RYVF+LhqQfEvYedlq+Y8Infpm2YgzhkskTO4vEHoLB3DNIAcf +nsR+tyuF0XxamWHaz8QorIIgQlxJ+RKrcJsAS8eiaGhMm0GnVFvazt8zIDruSf3e +GsgCHlUjvz+u8bIBNEIzif5nxv3DTjaSq3bYrQFIkWieGwzBOnyEUil0NV5NKxrb +Xpzkgp64TIGQJSqBrM1Fx7rlMXRJp+XxhWgv1sfprk9uDnzS1N8F8wI+bvQXBC0I +InbYkw69UuTAFhLf2M/JCf87dyo6Ve7jRI3ujJoMW/i65MjVijhVz/ddfBGmg5MP +yXdYe/VIdiugbjSWGapmYiWwN6zjf00MzY41K9XLvQtX8BMmX1QgYiOEDEsZqhTB +h9GxlPTuH9OkgVDpKs+/vNKUrUhdWnpK +=guIu +-----END PGP MESSAGE----- +** more stuff +#+begin_src conf +[Filter.1] +message = "Get mailing lists out" +query = tag:lists and tag:new +tags = -new; + +[ArchiveSentMailsFilter] + +[InboxFilter] +#+END_SRC +Move archived messages from inbox to remote Archive. Archived Messages older +than 1 year are moved to local Archive. + +#+begin_src conf :tangle no +[MailMover] +folders = Inbox Sent Spam +rename = true + +# rules +Inbox = 'date:-1800d..-60d':archive 'tag:spam':Spam +#+end_src +** MailMover section :crypt: +-----BEGIN PGP MESSAGE----- + +hQGMA/lzu+pplFIbAQv/Y9HmsMJS6hVR+LJtOJgL/uDTQv8mMKp1yKg9o5iX1oro +Gs/aaJcy8HpjsYnZd7Yx3PpuFh/yfM4XmNRhE68K2MtljTxrLmhm9oScQNv8QlFK +PwQbN9gKydrYbkxRrpNgbGBSFkrXd7uQ7NAyyvPdHY1Z0w/rDM4LZZKCTx9/1S1Q +3OZniVklBO94fIaPRDXcZK0dhuvXuOYFY6pSnByRJHzK/y0JzU6j50ZoEPre9frb +L/OiQLbsCwOZGXu96uHD6IN1YoTg+y3wSHUt+/rQyBIt9wH65oR2UJzQGiBevWoy +ZB/roXHFUA3qWBtye2zwUUgn9zwfHhxpVXh/CUF+H/nJpu4onr2NFZpVQBjTv3PM +LfS3QFRzArCSwFxAWpwzk8LHAeFTMoL5Ojz5bHGsrJbq3+WO2LPepN0Mb6HJbL+T +p1dYEfdIWLTVOJ+h+OGKg2FhHuN9+sEamrW1MhBqpgiTLN+RcxYLdqzUUYkX5y2l +R3rwiARy20KmQdvPDkgi0sCbAXh3Qkm2FP+naUkpMG8hygfDAIvlKzPPNrfQIF+c +K0sgSSHg6zDY8WD5O+jgsJMb+MDFVVavmy7evA+w5lPXToVrVNItz5iVvXjAY74k +4mUSKkY7RTRDpHihNYNKZ/7iz5QqpCCdAPiZt9neZ/2TR8zD8ESkxFRHt296Tw+Z +U9A5+cmTq05c7KoVsp4S1DADL0V4w5ELbXEAkeZ+fJoYMjTLJ9QxH9FGHduxN161 +uEED+B2SztY/8YWHGk+C6JtRgFqlCIdcshJVRWTlJg36R9jzXKuxhM+GJ4FQ+BSV +GhhV58pAPg/OzvR2o8TmlYm2QUhufZY08PH1HqJWu/GQigpHQlM5sXZgDRlu5ovv +f+hcnYxlWVjh6tquhT4uHo6uVwh//SaOPpYmEVAe9O9PdwL47pFJu6k0MMkH4qrK +7zUsvb+IgDtvGL3JLgMP7+qEF5NhrjoQVowImx8= +=oUMI +-----END PGP MESSAGE----- +* notmuch +:PROPERTIES: +:header-args: :tangle tangle/.notmuch-config :eval never :exports code :results silent +:END: + +Config in =~/.notmuch-config=. +#+BEGIN_SRC conf +# .notmuch-config - Configuration file for the notmuch mail system +# +# For more information about notmuch, see https://notmuchmail.org + +# Database configuration +# +# The only value supported here is 'path' which should be the top-level +# directory where your mail currently exists and to where mail will be +# delivered in the future. Files should be individual email messages. +# Notmuch will store its database within a sub-directory of the path +# configured here named ".notmuch". +# +[database] +path=/home/fpi/Maildir +#+end_src +** User configuration :crypt: +-----BEGIN PGP MESSAGE----- + +hQGMA/lzu+pplFIbAQwAyADHr9/dxo+qBiAnayNbHLRsCOZlRI/LdY8zL9AUN2Dm +V3RvD9vgJAg/FQR3Q3/St+EWrYd8ktPshr/54zE9EpqbQf/iZf1nHx8hQdyZLmFQ +teYuX+d4+r65LV6dwMKc3IYRNVefy0qMYYJcGxisgvg2FmJbZw5pInEfRjlu3e7c +yuiYPfbE1JfbF5Q+UK+jnq1MA/12XRYB+vSaEz+oYAY1B8L/oIifTFTBM2LlSYrs +e1oR1oYcEqZ6/NNcM8oFJV8mKo3ppvLQT3T9mIZinq9wdBssqSm7JjCghh+rBjrA +ZCk9+7n4WgsBIzclKXLPUpQrNt7i/j2o/lJZMe1X6uhwEvY4k2Ef/URRd5T3L0lz +XXHIkcNZQGfko+AnwSIeG2fsDA9h5HOx5t/9gQX5JqVXHNxUomyaumxafEkAw51N +hWN78JIZNTTIeNdlbKs+7tPqc/0Pg5KQsBrOIjsI8Q0/xy0U6ggNflce3jRXQ8b1 +ugcZK5XwVXVChho2w5340sEtAY7o7yrPPB0guACFB6T+pddMGlR2KRFqkL7n3UTt +R0BuuPcAaYwu4NA0dGG3HWEsHHnrCjADQNRimM5vxa2yl74YDBa/sA+eZ48ee3oV +bHXerSuERu0TZd/PxcFGyHLjbe6CR26a+q6O87pYbmlzCANddGSFmhInFv9dzpi9 +1EnTRr8KS2t+KPOAOYGnyuJD/gBsPuA43DAfZG+CFDIve4593QadyovvntJMgb2v +p1P899T9n76zuLd+kpi0vE/1U2XZkJQfp6eZh/1KiP5tnSAQfFaPBICg412vAg/D +7EbWn4xav4MQA7BPz2WWVuIktsJ/22ZhX+EmIB2pKSqad6q0mGt8/nu4ZzUY3HLb +fZA1qaBdSkIZIef4mNkiT2Sl+sbwzv/M8Lg0BZAPAS6hCrt4kNOeRhpcJNTlSaOD +mVq6dwrfvvPiY3tFMkbCLVT+4OztYsgHg+D+e4eGnA6geVCCvVtb79pK1tQKcAED +Y20tp9QZ7jVAP1zOVTZn8x9fe2VTa6+oyAayWtvgxQbSLhfmKc7et0LCngtTaasT +mHQXwQ7r0EIVyrkrhC0/Dlo7pgyoQ9spaBpCPg8hszDoNTJ0gunf2NxYBjjyO5hI +Zxz8+V8+wgKl/CfIoX0EoF3VcOs0EL+GvqFqcM9tsg== +=H1dY +-----END PGP MESSAGE----- +** More configuration +#+begin_src conf +# Configuration for "notmuch new" +# +# The following options are supported here: +# +# tags A list (separated by ';') of the tags that will be +# added to all messages incorporated by "notmuch new". +# +# ignore A list (separated by ';') of file and directory names +# that will not be searched for messages by "notmuch new". +# +# NOTE: *Every* file/directory that goes by one of those +# names will be ignored, independent of its depth/location +# in the mail store. +# +[new] +tags=new +ignore=.mbsyncstate;.uidvalidity + +# Search configuration +# +# The following option is supported here: +# +# exclude_tags +# A ;-separated list of tags that will be excluded from +# search results by default. Using an excluded tag in a +# query will override that exclusion. +# +[search] +exclude_tags=deleted;spam; + +# Maildir compatibility configuration +# +# The following option is supported here: +# +# synchronize_flags Valid values are true and false. +# +# If true, then the following maildir flags (in message filenames) +# will be synchronized with the corresponding notmuch tags: +# +# Flag Tag +# ---- ------- +# D draft +# F flagged +# P passed +# R replied +# S unread (added when 'S' flag is not present) +# +# The "notmuch new" command will notice flag changes in filenames +# and update tags, while the "notmuch tag" and "notmuch restore" +# commands will notice tag changes and update flags in filenames +# +[maildir] +synchronize_flags=true + +# Cryptography related configuration +# +# The following *deprecated* option is currently supported: +# +# gpg_path +# binary name or full path to invoke gpg. +# NOTE: In a future build, this option will be ignored. +# Setting $PATH is a better approach. +# +[crypto] +gpg_path=gpg +#+END_SRC +* msmtp +:PROPERTIES: +:header-args: :tangle tangle/.msmtprc :eval never :exports code :results silent +:END: + +Config in =~/.msmtprc=. +#+BEGIN_SRC conf +# Set default values for all following accounts. +defaults +# Use the mail submission port 587 instead of the SMTP port 25. +port 587 +# Always use TLS. +tls on +# don't use auto_from +auto_from off + +# Log to syslog/systemd +syslog on + +tls_trust_file /etc/ssl/certs/ca-certificates.crt + +# Additionally, you should use the tls_crl_file command to check for revoked +# certificates, but unfortunately getting revocation lists and keeping them +# up to date is not straightforward. +#tls_crl_file ~/.tls-crls + +#+end_src +** Account configuration :crypt: +-----BEGIN PGP MESSAGE----- + +hQGMA/lzu+pplFIbAQv/Z+gf1HDfl3ujUmWlhnNSgtDYvJ0p1F5ocDQFbycYcMnK +y0pgNbBHTt4EnpyBzcO4fJeWnytd8VWivcNyie36fwInOfZGDWwGGbg6mbDSTZ7R +TE6oGnUIJZGZGi3Tc48Pfi2/dnLFaqIFjpCBHoF3SJt35HlHCaH5fo1VCym0WRW/ +zCXZUbbLgncDYnzb1TLvMZcDTqPiIKsMkqXiO2tf/P9WJTqk0gZBPvMWTQKqrjtm +tj5+PAUCG2YATra5MBGeQED7DflV9UMyxcP8pHGV8HStoih0xTQ72X0N0mL5JquK +A0LW4p0jGNig0v5EdgP8yZtygv2Rx+3IRJzuedubM37dnRF+jzAfkmC1ALY5zEfW +8l//9iwcARtEde8AS2vAoPVXlS0xIEF12d6VzkWWzncZmcXIHyXDrFY1+z3tEe0V +e8fBSx4LsBfCTJineSCcDkh+AuGr2JyvM71b8eX3BE1FqrfNppV2pqXlkVIL19R8 +/kr4nDHmtG+59+lmbzyD0ukB0OUbXqHJMnnMbJRjHsEbuQUAazGfOZDUyjd4zJx2 +2fNFuPEPkKiiJUWOFeYqnbG12e+sl0LP2CMTGNdd4aT51IDrWXlSxbkwxBiK3spt +n2LhqzZs0xK0ZGkSiH+7BnxtVgkzBIbF4sGmhq696gWyGuY3EfmIBSNRidlpCGtC +iJwK29G9DUKX7s6cR3+n7A2wWK47fQazRN/lcUQ7XD0JOhsasR0SMUQvQRwnfR9e +ft8romZ4uGBeRhm7n2cA7d5CJJPVJfsq5QdZFLewPmQPDbH4Fkeg8i4Oeh7Lu2fs +EOLOhao5ejocKlY9ZdGpNzhDxHLkZJ4ShX9+OoV9Uz3Sf2rmtz8r94pkNDmaaQ8c +990I3/caiy4PpsWTp1QJ4EUvhT3EWUsE2EYvM3SQSGpF+HOT0j6vrIaoecMCqoLX +WkUvZap6obg3KiSqodGn007iiqQ8pwJZl76FZMbse0jei0XcyiHt+hY2EO1FhMyv +pKRiHcwx8rICoiw2oGn13Zb9UbVmXU5SMeurE59C/0PFUC6SzafMnPTJXUQ7NlUq +ne9se0qmT7JoqHXshuotRSsYRVpxns2JZuE7tqHA7/Ud5hVPLy3ZOl+Zk6ddagc9 +lPhqal3qX0U9nSWQsCXBa8+MhduFG4hYuNj9X5uviTNK2q3wLgRUCo2gRXK2cp+k +FMBa71Nk8D4/EBU9giq5FAPG91uer+UcmSZVknLncY0pd1uAdtBsIUT/+zZvIJMJ +8FNjguacnEefSewhLAcMVrKOQ2WYOvOP5nLr9TaKnJ5nS5GSRXVJy9nBKFtEAZf+ +2wmHTkmFSwP3lqi1ZaIxovF3rs2lHc5Y+l2TYUMpZ7IoENt3mHV5NpMf8n9YMXvH +iml2sfR/j4AwOMKGoq4kd/+X5T3+YDXceV9Na5dVS8Gi988FYJ7mUQgpQEBh97PF +Rfk0cIaKPIfioUlzYQqH1j2iJJ3oR1cY7zOaPZiWsvbIthhMLOFfkHh70Ohcu/b+ +/gV5ByyC9yQDRuyjleeUMuWjQP8rr9eA2ieri6QajNz1xDuf2VwB13NhMAWx +=wmLO +-----END PGP MESSAGE----- +* Checkmail.sh +:PROPERTIES: +:header-args: :tangle tangle/checkmail.sh :exports code +:END: + +This script calls everything necessary to receive mail. An optional 'quick' +argument can be supplied to only sync the inbox. + +#+BEGIN_SRC shell :shebang "#!/bin/sh" :results silent +STATE=`nmcli networking connectivity` +run=$1 + +# no of old unread mails +OLD_UNREAD=`notmuch count "tag:unread and tag:inbox"` + +# Delete deleted mails +COUNT=`notmuch count "tag:deleted and (tag:spam or not tag:spam)"` +if [ $COUNT != 0 ] +then + echo "- deleting $COUNT messages ..." + notmuch search --format=text0 --output=files "tag:deleted and (tag:spam or not tag:spam)" | xargs -0 --no-run-if-empty rm +fi + +if [ $STATE = 'full' ] +then + #~/.local/bin/msmtp-runqueue.sh + if [ $run = 'quick' ] + then + # echo 'Quick Sync' + mbsync gmx-quick + else + # echo 'Normal Sync' + mbsync all + fi + notmuch new + # tag mail + afew -tn + # move mail + # all mail to move archived messages + afew -ma + #notmuch tag -inbox tag:inbox AND tag:lists + + NEW_UNREAD=`notmuch count "tag:unread and tag:inbox"` + if (( $NEW_UNREAD > $OLD_UNREAD )) + then + msgs=( $(notmuch search --output=threads 'tag:unread and tag:inbox')) + for i in $(seq 0 $(($NEW_UNREAD - $OLD_UNREAD -1))) + do + subject=$(notmuch search ${msgs[i]}|grep -oP "(?<=\] ).*(?=( \())") + emacsclient -e "(sauron-add-event 'mail 3 \"$subject\" '(lambda () (other-window 1) (notmuch-show \"${msgs[i]}\" nil nil \"tag:unread and tag:inbox\")))" + notify-send -u low "New mail:" "$subject" + done + fi + + exit 0 +fi +# echo "No Internets!" +exit 0 +#+END_SRC + +A simple cronjob then regulary calls this script. Setup like this it +performs a quick sync every minute and a full sync every ten minutes +and also logs stdout to systemd. +#+BEGIN_SRC conf :eval never :tangle no +,* * * * * systemd-cat /home/fpi/.checkmail.sh quick +,*/10 * * * * systemd-cat /home/fpi/.checkmail.sh full +#+END_SRC +* Emacs setup +:PROPERTIES: +:header-args: :tangle tangle/emacs-mail.el :eval never :exports code :results silent +:END: + +See [[id:1e1d7ae0-3e88-4e14-b67f-72c6be66e565][emacs init file]]. +* Create symlinks + +Finally symbolic links to the desired locations are created for all +the tangled files. + +#+BEGIN_SRC shell :tangle tangle/symlink.sh :shebang "#!/bin/bash" :shebang "#!/bin/bash" +ln -siv $(pwd)/tangle/.mbsyncrc ~/ +ln -siv $(pwd)/tangle/afew.config ~/.config/afew/config +ln -siv $(pwd)/tangle/.notmuch-config ~/ +ln -siv $(pwd)/tangle/.msmtprc ~/ +ln -siv $(pwd)/tangle/checkmail.sh ~/ +#+END_SRC diff --git a/package-versions.el b/package-versions.el new file mode 100644 index 0000000..f9f6001 --- /dev/null +++ b/package-versions.el @@ -0,0 +1,106 @@ +(("Try" . "8831ded1784df43a2bd56c25ad3d0650cdb9df1d") + ("alert" . "7046393272686c7a1a9b3e7f7b1d825d2e5250a6") + ("auctex" . "6abf890a485b2ff734d8f87f38393f9b8f6bbbf6") + ("auth-password-store" . "ff4940c647786914b3cbef69103d96a4ea334111") + ("avy" . "2dde8b71a0feb366c8ee5e2a1400a0d3a0f06424") + ("bbdb" . "45529e315ba861f9df2914f9b88d2f7b991d5595") + ("biblio.el" . "eb9baf1d2bf6a073d24ccb717025baa693e98f3e") + ("cdlatex" . "480387b39f6ddd9cd2a9511ecee064ad8e1dd324") + ("closql" . "9371635bc3e259b73a075985ebbfc58b45fa5e9d") + ("company-mode" . "5618f28d62cbbdcccdaee1b455fc6e9d1c8bff31") + ("dash.el" . "ea4a4cc7cce7c3b93862a22df8bca8b83052ccbf") + ("deft" . "fca9ea05ef4fdac825e2ad3921baa7042f6b82c8") + ("delight" . "02e73b69708e23053105866a58fe14f75c272dee") + ("diff-hl" . "176f931a9bfc6bc6fc5360c6ed7128ff96b21289") + ("dired-du" . "d6571317673ba44566ba411d26b7af74e3139ff7") + ("dired-git-info" . "b47f2b0c3a6cb9b7a62a4ee2605a492e512d40a9") + ("dired-hacks" . "f49a8bbf95f70671a74a24f7f4de453b2686be46") + ("dired-sidebar" . "6e569c851418890c21fd37d03a62f85343aa0900") + ("emacs-async" . "86aef2c38e7d35e8509b7feeee3e989d825eba91") + ("emacs-hide-mode-line" . "88888825b5b27b300683e662fa3be88d954b1cea") + ("emacs-htmlize" . "86f22f211e9230857197c42a9823d3f05381deed") + ("emacs-libvterm" . "f41849c2c9c1899f22d1c3d4f871ec47c82627ce") + ("emacs-request" . "912525c772984c6af0fd84acd6699ee43d91037a") + ("emacs-which-key" . "8b49ae978cceca65967f3544c236f32964ddbed0") + ("emacsmirror-mirror" . "006fbf082e52dd33cb842c9d5fb181de12736142") + ("emacsql" . "a118b6c95af1306f0288a383d274b5dd93efbbda") + ("emacsql-sqlite3" . "1e411fd38a0137553986db209642fe93cae96060") + ("esxml" . "193d199305e7abcb5ed795b9bc5434ded20ae60e") + ("f.el" . "1814209e2ff43cf2e6d38c4cd476218915f550fb") + ("forge" . "048efbba83b1df591de0487202ff968250ea4fc5") + ("ghub" . "3da5d8827f6b697ef71dca0a44eb8134689c1dad") + ("git-annex-el" . "c8f7995a232efe643d7acdafcb6370f2d8af8327") + ("git-auto-commit-mode" . "dd0c2441de0f5ff8c69c8260d9450d0b607e3e55") + ("git-identity.el" . "eec910b2a5459345321b5b9d166383f1323501f5") + ("gnorb" . "260d41f60a6f5ac864ed0cf48a94b546ce71c24a") + ("gntp.el" . "767571135e2c0985944017dc59b0be79af222ef5") + ("gnu-elpa-mirror" . "f07e244acca36061cc03c63463246b848748e804") + ("gnuplot" . "f0001c30010b2899e36d7d89046322467e923088") + ("gnuplot-mode" . "601f6392986f0cba332c87678d31ae0d0a496ce7") + ("header-info" . "1482e2f9fe0558acb36e170b627dc46b1f6f6a38") + ("helm" . "3ff35503a920d8629cf5c9c07647923661f24ba2") + ("helm-bibtex" . "8a0dd9841316793aacddea744d6b8ca4a7857a35") + ("ht.el" . "fff8c43f0e03d5b98deb9f988522b839ce2ca253") + ("hydra" . "8a9124f80b6919ad5288172b3e9f46c5332763ca") + ("ibuffer-vc" . "1249c1e30cf11badfe032ac3b1058f24ba510ace") + ("icomplete-vertical" . "a5871d39c5850ac4d9aac48350eaa1d31f3aaef7") + ("key-chord" . "72443e9ff3c4f1c3ccaced3130236801efde3d83") + ("language-detection.el" . "54a6ecf55304fba7d215ef38a4ec96daff2f35a4") + ("ledger-mode" . "f8463744191b4feb9fea54190917663f7ba26102") + ("let-alist" . "ef3c02fa292b6e32769945bbbfb7f2e5ac574b64") + ("log4e" . "7df0c1ff4656f8f993b87064b1567618eadb5546") + ("lsp-mode" . "34de3040f01aeda4eceadc1ccd6a723120ee4598") + ("magit" . "8b45756390e43bfc3247dd85bf5f7738516e569a") + ("magit-gitflow" . "cc41b561ec6eea947fe9a176349fb4f771ed865b") + ("magit-popup" . "b8e886c4f2242d6c58f84d4549af712e86360db1") + ("markdown-mode" . "399df42755ccf31cecb61c9f5d8ad72bc30d7e4b") + ("matlab-mode" . "e14d97df706049ea2e2d6e5b515fdbd08cd94dd3") + ("melpa" . "ee055cc258692a92f727633306adf7df31267479") + ("notmuch" . "963e363a234f1c8bdf1ae68956f80a2538bee7dc") + ("ob-spice" . "a3581400b253330231573e100c39548e5d891cfd") + ("olivetti" . "0bc5e98b8456493084d1bd3df35e92a12c5da3b2") + ("openscad" . "176ea07abba6f5f8fb5a130143f23b397416c789") + ("orderless" . "1f1e0380e2a8cd4fc29b8cc2e00cb01b56d86fbc") + ("org-roam" . "f819720c510185af713522c592833ec9f2934251") + ("org-time-budgets" . "439e73b730a9e9434c93b3b1892780e5d128246a") + ("org-web-tools" . "ebc7888f4f4cad26ec1298edd7bf606a5ea2d564") + ("parsebib" . "3497b6068d78ae15ba1eaf94e4315d18e9ae6b00") + ("pass" . "919d8e3826d556433ab67d4ee21a509d209d1baa") + ("password-store" . "07b169ec32ad6961ed8625a0b932a663abcb01d2") + ("password-store-otp.el" . "04998c8578a060ab4a4e8f46f2ee0aafad4ab4d5") + ("pdf-tools" . "c510442ab89c8a9e9881230eeb364f4663f59e76") + ("peep-dired" . "1d410a4e48db07a942e54d3b83a85c7a7ec0aab3") + ("pinentry" . "cd942f755c38a7ac270ce858bb887ebdd59edd26") + ("popup-el" . "9d104d4bbbcb37bbc9d9ce762e74d41174683f86") + ("project" . "e4763443d23710559a92748801db5d6de25e6221") + ("rainbow-mode" . "f780ddb18c2a73a666d093f606df92058e5601ea") + ("redtick" . "d30637a536533830693eada29978f275af27aa26") + ("rustic" . "ed68fd3bb410869e1a4ce3943b5913ea88d9b509") + ("s.el" . "43ba8b563bee3426cead0e6d4ddc09398e1a349d") + ("sauron" . "5daade4836da5b1b2ab26d84128d6c38328a5d52") + ("shell-pop-el" . "4b4394037940a890a313d715d203d9ead2d156a6") + ("shr-tag-pre-highlight.el" . "6182f43a36b0f82ba6edcf6e423b5f69a46a814e") + ("spacemacs-theme" . "6c26717c0ec64af08ab3fd81e88ef03003543c5d") + ("speed-of-thought-lisp" . "ed2356a325c7a4a88ec1bd31381c8666e8997e97") + ("spice-mode" . "e5e0644f03f9696f56dd69e2b6979da7f30ed600") + ("spinner" . "2daa167bec1c7566d662d48613a94453536b524a") + ("spray" . "74d9dcfa2e8b38f96a43de9ab0eb13364300cb46") + ("ssh-tunnels" . "d32e2072f50bcbde787196abb5862735837dc8be") + ("straight.el" . "a7f94876b2bf96d2595706270be6630ecc94f0d3") + ("swiper" . "f8b1ab8c0ec331a4f8f6621f9021811075c71332") + ("tablist" . "faab7a035ef2258cc4ea2182f67e3aedab7e2af9") + ("toc-org" . "5deaec41ed0e5c51715737d7f74c5ae1b3c00387") + ("transient" . "88d935c7cb9f175871c4cfea7eef2c0514d03b06") + ("treepy.el" . "306f7031d26e4ebfc9ff36614acdc6993f3e23c3") + ("use-package" . "d2640fec376a8458a669e7526e63e5870d875118") + ("use-package-hydra" . "8cd55a1128fbdf6327bb38a199d206225896d146") + ("vundo" . "4b6551748b205dde157bccafcfdd4637071939c7") + ("whole-line-or-region" . "79731cbbf173dbb9dcce3457baa1056e906d98db") + ("window-numbering.el" . "10809b3993a97c7b544240bf5d7ce9b1110a1b89") + ("with-editor" . "48ca9bb49a1a7a37e85606de9d327a14030d4380") + ("xref" . "83cedce58124a81ff7f323d7fbf553fbeadfa4b5") + ("xterm-color" . "1a4012854c69a5cdaeb5a73d2ad705011892fca3") + ("yasnippet" . "5cbdbf0d2015540c59ed8ee0fcf4788effdf75b6") + ("yasnippet-snippets" . "be823d7e1a1a46454d60a9f3dabb16b68b5dd853") + ("zetteldeft" . "19943a39e1c5f53dae6fac107ce3a7d2e4c5f2f8")) +:alpha @@ -0,0 +1,1391 @@ +Tangle this to rc.lua for awesome to use it. + +#+BEGIN_SRC shell :results silent :tangle tangle/symlink.sh :shebang "#!/bin/bash" +ln -siv $(pwd)/tangle/rc.lua ~/.config/awesome/ +#+END_SRC +* External packages +I make use of these external awesome libraries/packages +- [[https://github.com/lcpz/lain][lain]] +- eminent to hide unused tags? +- [[https://github.com/pltanton/net_widgets][net_widgets]] +- [[https://github.com/deficient/battery-widget][battery_widget]] +- email & spotify widget from [[https://github.com/streetturtle/awesome-wm-widgets][awesome-wm-widgets]] +* General Tips (no code to tangle here) + :PROPERTIES: + :header-args:lua: :tangle no + :END: + To set wallpaper without restart: + #+BEGIN_SRC lua :tangle no + r=require("gears") + r.wallpaper.set(r.color.create_png_pattern("/home/fpi/Pictures/wallpaper/w")) + require("gears").wallpaper.centered("…") + #+END_SRC + +* Improvements to work on + :PROPERTIES: + :header-args:lua: :tangle no + :END: +** Overview & Reorganization of Keyboard layout + :PROPERTIES: + :header-args:ruby: :var t=kb_layout + :END: + + TODO: Easy accessible key to show spotify song! + #+NAME: kb_layout + #+CAPTION: Alle Tasten der QWERTY-Tastatur mit neo2 Belegung + | ESC | F1 | F2 | F3 | F4 | F5 | F6 | F7 | F8 | F9 | F10 | F11 | F12 | Home | End | Ins | Del | + | | ^ | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | - | ` | BCK | | | + | | TAB | x | v | l | c | w | k | h | g | f | q | ß | ´ | M3 | | | + | | M3 | u | i | a | e | o | s | n | r | t | d | y | ent | | | | + | | Sh | ü | ö | ä | p | z | b | m | , | . | j | Sh | | | | | + | | Fn | Ctrl | Sup | Alt | Spc | Spc | Spc | Alt | Druck | Ctrl | PgUp | Up | PgDn | | | | + | | | | | | | | | | | | Left | Dn | Right | | | | +*** Current Awesome Key Setup (5.1.2018) + - =Super+Mod5+Key=: start program + - =Super+Shift+Mod5+Key=: Switch to tag #α (Greek keys) + - =Super+Ctrl+Shift+Mod5+Key=: Tag menu of tag #α (Greek keys) +**** Super+Key + | l,h | in-/decrease master width | + | j,k | focus next/previous client | + | s | help | + | w | main menu | + | x | execute Lua | + | r | execute bash | + | TAB | go back (client level) | + | f | toggle fullscreen | + | m | t maximize | + | n | minimize | + | o | move to other screen | + | u | jump to urgent | + | p | run rofi | + | 1-9 | view tag #i | + | Esc | go back (tag level) | + | a | next non-empty tag | + | i | first empty tag | + | v | next empty tag | + | b | move window to (current) tag | + | d | temporary tag | + | →,← | next/prev non-empty tag | + | SPC | select next layout | +**** Super+Ctrl+Key + | r | reload awesome | + | Enter | move to master | + | l | toggle sticky | + | m | maximize vertically | + | n | restore minimized | + | SPC | toggle floating | + | l,h | de-/increase no of columns | + | j,k | focus next/prev screen | + | 1-9 | toggle tag #i | + | c | compact clients over all tags | + | s | spread clients of current tag | + | v | move client to next nonempty and follow | + | →,← | view next/prev tag | +**** Super+Shift+Key + | q | quit awesome | + | c | close | + | j,k | swap with next/prev client | + | m | maximize horizontally | + | u | toggle keep on top | + | x | repair no tiling window | + | l,h | de-/increase no of master clients | + | SPC | select prev layout | + | p | screen manager | + | 1-9 | move client to tag #i | + | →,← | move client to next/prev tag | +**** Super+Ctrl+Shift+Key + | 1-9 | toggle client on tag #i | + +*** New layout + hjkl replaced by nrtd. Other command organized mnemonically if + possible or grouped up.\\ + Abbrevs: c=client, t=tag, n=next, p=previous, m=master, w=width, n-e=non-empty, f=floating + |-----+-----+------+-----+-----+-----+-----+-----+-----+-------+------+------+-----+-------+-----+-----+-----| + | ESC | F1 | F2 | F3 | F4 | F5 | F6 | F7 | F8 | F9 | F10 | F11 | F12 | Home | End | Ins | Del | + | | ^ | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | - | ` | BCK | | | + | | TAB | x | v | l | c | w | k | h | g | f | q | ß | ´ | M3 | | | + | | M3 | u | i | a | e | o | s | n | r | t | d | y | ent | | | | + | | Sh | ü | ö | ä | p | z | b | m | , | . | j | Sh | | | | | + | | Fn | Ctrl | Sup | Alt | Spc | Spc | Spc | Alt | Druck | Ctrl | PgUp | Up | PgDn | | | | + | | | | | | | | | | | | Left | Dn | Right | | | | +**** Super+Key + | t bck | - | - | - | - | - | - | - | - | - | - | - | - | | | | | + | | [^] | view | t | #i | " | " | " | " | " | " | [0] | [-] | [`] | {BCK} | | | + | | c back | [x] | f e t | n e t | n ne t | [w] | [k] | run lua | /bash | fullscr | [q] | [ß] | [´] | {M3} | | | + | | {M3} | urgent | f c to cursor | emacs | quake | oth scr | help | de- | focus | n/p c | inc m w | [y] | open term | | | | + | | {Sh} | t back | c back | [ä] | rofi | minmize | [b] | t max | [,] | temp t | [j] | {Sh} | | | | | + | | {Fn} | {Ctrl} | {Sup} | {Alt} | next | lay- | out | {Alt} | {Druck} | {Ctrl} | [PgUp] | [Up] | [PgDn] | | | | + | | | | | | | | | | | | p/n n-e | [Dn] | tag | | | | +**** Super+Ctrl+Key + : Operations on tag level + | ESC | | | | | | | | | | | | | | | | | + | | | toggle | tag | #i | " | " | " | " | " | " | [0] | | | {BCK} | | | + | | {TAB} | [x] | [v] | mv c ne t+f | [c] | [w] | [k] | [h] | [g] | [f] | [q] | [ß] | | {M3} | | | + | | {M3} | [u] | [i] | [a] | [e] | [o] | [s] | in- | focus | n/p scr | dec col no | [y] | move m | | | | + | | {Sh} | [ü] | [ö] | [ä] | [p] | res min | [b] | m vert | [,] | [.] | [j] | {Sh} | | | | | + | | {Fn} | {Ctrl} | {Sup} | {Alt} | t | floa- | ting | {Alt} | {Druck} | {Ctrl} | [PgUp] | [Up] | [PgDn] | | | | + | | | | | | | | | | | | view p/n | [Dn] | t | | | | + +**** Super+Shift+Key + : Operations on client level + | ESC | | | | | | | | | | | | | | | | | + | | | move | c | to | tag | #i | " | " | " | " | [0] | | | {BCK} | | | + | | {TAB} | [x] | [v] | l | close c | | | | spread c | compact c | | | | {M3} | | | + | | {M3} | t on top | t sticky | | | | | in-/dec | swap w | n/p c | no master c | | | | | | + | | {Sh} | | | | | | | m hor | | | | {Sh} | | | | | + | | {Fn} | {Ctrl} | {Sup} | {Alt} | select | prev | " | {Alt} | {Druck} | {Ctrl} | | | | | | | + | | | | | | | | | | | | move c to | | p/n t | | | | +**** Super+Ctrl+Shift+Key + | ESC | | | | | | | | | | | | | | | | | + | | | toggle | c | on | tag | #i | " | " | " | " | [0] | | | {BCK} | | | + | | {TAB} | {dbg} | {dbg} | {dbg} | fix no tiling c | | | | | | quit aws | | | {M3} | | | + | | {M3} | {dbg} | {dbg} | {dbg} | | | | main menu | reload aws | | | | | | | | + | | {Sh} | {dbg} | {dbg} | {dbg} | | | | menu bar | | | | {Sh} | | | | | + | | {Fn} | {Ctrl} | {Sup} | {Alt} | Spc | Spc | Spc | {Alt} | {Druck} | {Ctrl} | | | | | | | + | | | | | | | | | | | | | | | | | | +*** Empty dummy + | ESC | | | | | | | | | | | | | | | | | + | | | | | | | | | | | | | | | {BCK} | | | + | | {TAB} | | | | | | | | | | | | | {M3} | | | + | | {M3} | | | | | | | | | | | | | | | | + | | {Sh} | | | | | | | | | | | {Sh} | | | | | + | | {Fn} | {Ctrl} | {Sup} | {Alt} | Spc | Spc | Spc | {Alt} | {Druck} | {Ctrl} | | | | | | | + | | | | | | | | | | | | | | | | | | +** TODO [#A] Key to create floating emacsclient + \to use =emacsclient -t= ? +for proper client.name: + +(make-frame + '((name . "FRAMEY"))) + +** [#D] "empty client" which acts like a normal client but doesn't actually contain anything + (best see-trough, click-trough), to help limit screen space when wanted +** move all clients on current tag to a selected (empty?) tag +** swap the current tag with another selected tag +** DONE Key/Script to toggle wibar display +- State "DONE" from [2019-07-21 Sun 16:54] +* make more use of rofi + - +select any window and move it to current tag using rofi window manager+ + -window-command "..." + - select any tag and move all their clients to active tag → combi mode: windows+tags + - +use rofi to select tag?+ + - show all available layouts and change to any. Images in rofi? or better + way to make spread view of layouts +** 2nd monitor setup + - commands to move all clients of current tag to current tag on other screen, + toggle all clients of current tag on current tag of other screen (mirror + mode), if already mirrored only place them on screen 1 + - tags and clients can't be displayed on two screens at once + - update screenmenu keyboard shortcut when connected screens change +** calender popup +** nm-applet icons +** DONE way to select all 25 tags individually instead of only 1-9 + - can't remember all tag numbers → possible to use keys of neo layout αβγ…? +** DONE on screen disconnect mark all tags of destroyed screen as volatile + they will be moved to another screen but destroyed as soon as all of their + clients have been moved to another tag+ + +* Config + :PROPERTIES: + :header-args:lua: :tangle tangle/rc.lua + :END: +** Libraries + + Debug_flag enables some debug functions, e.g. Super-Shift-s + #+BEGIN_SRC lua + debug_flag = true + #+END_SRC + General libraries: + #+BEGIN_SRC lua + -- Standard awesome library + local gears = require("gears") + local awful = require("awful") + require("awful.autofocus") + -- Widget and layout library + local wibox = require("wibox") + -- Theme handling library + local beautiful = require("beautiful") + -- Notification library + local naughty = require("naughty") + local menubar = require("menubar") + local hotkeys_popup = require("awful.hotkeys_popup").widget + #+END_SRC + Some custom ones I use: + #+BEGIN_SRC lua + local lain = require("lain") + local eminent = require("eminent") + --local shifty = require("shifty") -- don't use shifty, use tyrannical + --local tyrannical = require("tyrannical") + --tyrannical.settings.default_layout = awful.layout.suit.tile + -- Enable VIM help for hotkeys widget when client with matching name is opened: + require("awful.hotkeys_popup.keys.vim") + #+END_SRC +** Basic Error handling + #+BEGIN_SRC lua + -- {{{ Error handling + -- Check if awesome encountered an error during startup and fell back to + -- another config (This code will only ever execute for the fallback config) + if awesome.startup_errors then + naughty.notify({ preset = naughty.config.presets.critical, + title = "Oops, there were errors during startup!", + text = awesome.startup_errors }) + end + + -- Handle runtime errors after startup + do + local in_error = false + awesome.connect_signal("debug::error", function (err) + -- Make sure we don't go into an endless error loop + if in_error then return end + in_error = true + + naughty.notify({ preset = naughty.config.presets.critical, + title = "Oops, an error happened!", + text = tostring(err) }) + in_error = false + end) + end + -- }}} + #+END_SRC +** Custom scripts + These are executed upon startup and function independent of + awesome. + #+BEGIN_SRC lua + -- {{{ Autorun && screen lock + awful.util.spawn_with_shell("~/.config/awesome/autorun.sh") + awful.util.spawn_with_shell('~/.config/awesome/locker') + -- }}} + #+END_SRC +** Tyrannical Tag setup + This is no longer tangled, as Tyrannical settings seemed to provide + no benefit with the way I use tags and it did not work nicely with + screenful and creating and moving when adding/removing screens. + #+BEGIN_SRC lua :tangle no + --[[tyrannical.tags = { + { + name = "α", -- Call the tag "α" + init = true, -- Load the tag on startup + exclusive = false, -- Refuse any other type of clients (by classes) + screen = {1,2}, -- Create this tag on screen 1 and screen 2 + layout = awful.layout.suit.tile, -- Use the tile layout + selected = true, + -- class = { --Accept the following classes, refuse everything else (because of "exclusive=true") + -- "xterm" , "urxvt" , "aterm","URxvt","XTerm","konsole","terminator","gnome-terminal" + -- } + --screen = screen.count()>1 and 2 or 1,-- Setup on screen 2 if there is more than 1 screen, else on screen 1 + --exec_once = {"dolphin"}, --When the tag is accessed for the first time, execute this command + } , + { + name = "β", + init = true, screen = {1,2}}, + { name = "γ", + init = true, screen = {1,2}}, + { name = "δ", + init = true, screen = {1,2}}, + { name = "ε" , + init = true, screen = {1,2}}, + { name = "♫", + init = true, screen = {1,2}, + class = { "spotify" } + }, + { name = "ζ", + init = true, screen = {1,2}}, + { name = "η", + init = true, screen = {1,2}}, + { name = "θ", + init = true, screen = {1,2}, + fallback = true}, + { name = "ι", + init = true, screen = {1,2}}, + { name = "κ", + init = true, screen = {1,2}}, + { name = "λ", + init = true, screen = {1,2}}, + { name = "μ", + init = true, screen = {1,2}}, + { name = "ν", + init = true, screen = {1,2}}, + { name = "ξ", + init = true, screen = {1,2}}, + { name = "ο", + init = true, screen = {1,2}}, + { name = "π", + init = true, screen = {1,2}}, + { name = "ρ", + init = true, screen = {1,2}}, + { name = "σ", + init = true, screen = {1,2}}, + { name = "τ", + init = true, screen = {1,2}}, + { name = "υ", + init = true, screen = {1,2}}, + { name = "φ", + init = true, screen = {1,2}}, + { name = "χ", + init = true, screen = {1,2}}, + { name = "ψ", + init = true, screen = {1,2}}, + { name = "Ω", + init = true, screen = {1,2}} + } + --]] + #+END_SRC +** Some Variables + Set the theme, terminal, modkey and layouts to use. + #+BEGIN_SRC lua + -- {{{ Variable definitions + local theme = "~/.config/awesome/themes/mine/" + beautiful.init(theme.."theme.lua") + + -- This is used later as the default terminal and editor to run. + terminal = "tilix" + editor = os.getenv("EDITOR") or "nano" + editor_cmd = terminal .. " -e " .. editor + #+END_SRC + From the default rc.lua: + #+BEGIN_QUOTE + Default modkey.\\ + Usually, Mod4 is the key with a logo between Control and Alt. If + you do not like this or do not have such a key, I suggest you to + remap Mod4 to another key using xmodmap or other tools. However, + you can use another modifier like Mod1, but it may interact with + others. + #+END_QUOTE + #+BEGIN_SRC lua + modkey = "Mod4" + #+END_SRC + Table of layouts to cover with awful.layout.inc, order matters. + #+BEGIN_SRC lua + awful.layout.layouts = { + awful.layout.suit.tile, + awful.layout.suit.tile.left, + awful.layout.suit.tile.bottom, + --awful.layout.suit.tile.top, + awful.layout.suit.fair, + awful.layout.suit.fair.horizontal, + awful.layout.suit.spiral, + --awful.layout.suit.spiral.dwindle, + --awful.layout.suit.max, + awful.layout.suit.max.fullscreen, + awful.layout.suit.magnifier, + awful.layout.suit.corner.nw, + -- awful.layout.suit.corner.ne, + -- awful.layout.suit.corner.sw, + -- awful.layout.suit.corner.se, + lain.layout.termfair, + lain.layout.centerwork.horizontal, + lain.layout.centerwork, + + awful.layout.suit.floating, + } + -- }}} + #+END_SRC +** Helper Functions + #+BEGIN_SRC lua + -- {{{ Helper functions + local function client_menu_toggle_fn() + local instance = nil + + return function () + if instance and instance.wibox.visible then + instance:hide() + instance = nil + else + instance = awful.menu.clients({ theme = { width = 250 } }) + end + end + end + -- }}} + #+END_SRC +** Menu + #+BEGIN_SRC lua + -- {{{ Menu + -- Create a launcher widget and a main menu + myawesomemenu = { + { "hotkeys", function() return false, hotkeys_popup.show_help end}, + { "manual", terminal .. " -e man awesome" }, + { "edit config", editor_cmd .. " " .. awesome.conffile }, + { "restart", awesome.restart }, + { "quit", function() awesome.quit() end} + } + + mymainmenu = awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon }, + { "open terminal", terminal } + } + }) + + mylauncher = awful.widget.launcher({ image = beautiful.awesome_icon, + menu = mymainmenu }) + + -- Menubar configuration + menubar.utils.terminal = terminal -- Set the terminal for applications that require it + -- }}} + #+END_SRC +** TODO Wibar & boxes +*** Widgets +#+BEGIN_SRC lua + -- Keyboard map indicator and switcher + mykeyboardlayout = awful.widget.keyboardlayout() + + -- {{{ Wibar + -- Create a textclock widget + mytextclock = wibox.widget.textclock() + + -- load battery widget + local battery_widget = require("battery-widget") + -- define + --local baticon = wibox.widget.imagebox("/home/fpi/.config/awesome/themes/mine/ac.png") + battery = battery_widget({adapter="BAT0"}) + -- network widget + local net_widgets = require("net_widgets") + net_wireless = net_widgets.wireless({interface = "wlp4s0", + timeout = 5 + }) + -- lain widgets + local separators = lain.util.separators + local cpuicon = wibox.widget.imagebox("/home/fpi/.config/awesome/themes/mine/cpu.png") + --local cpu = lain.widget.cpu { + -- settings = function() + -- widget:set_markup(cpu_now.usage) + -- end + --} + local myredshift = wibox.widget{ + checked = false, + check_color = "#EB8F8F", + border_color = "#EB8F8F", + border_width = 1.2, + shape = function(cr, width, height) + gears.shape.rounded_bar(cr, width, 0.4*height) + end, + widget = wibox.widget.checkbox + } + lain.widget.contrib.redshift:attach( + myredshift, + function (active) + myredshift.checked = active + end + ) + --local cpu = awful.widget.watch('bash -c \"uptime|cut -d\\" \\" -f12,13,14\"', 3) + local cpu = awful.widget.watch('bash -c \"cat /proc/loadavg|cut -d\\" \\" -f1-3\"', 3) + + local volume = lain.widget.alsabar { + } + + require("awesome-wm-widgets.email-widget.email") + + require("awesome-wm-widgets.spotify-widget.spotify") +#+END_SRC +Quake +#+BEGIN_SRC lua +-- local quakeemacs = lain.util.quake({app="emacsclient -c -e '(progn (display-buffer (get-buffer-create \"Quake\")) (delete-window))';#", argname = "", name = "QuakeEmacs", secondcmd = "xprop -name 'Quake' -f WM_CLASS 8s -set WM_CLASS \"QuakeEmacs\"", followtag = true, loosepos = true}) +-- Command to create emacsclient with Quake buffer and set wm_class to QuakeDD +-- emacsclient -c -e '(progn (display-buffer (get-buffer-create "Quake")) (delete-window))'&;sleep 1;xprop -name "Quake" -f WM_CLASS 8s -set WM_CLASS "QuakeDD" +local quake = lain.util.quake({app="tilix", argname = "--new-process --name %s", followtag = true}) +local quake_emacs = lain.util.quake({app="emacsclient", name="_Quake_Emacs_", argname = "-e \"(fpi/make-floating-frame nil nil t \\\"*Quake Emacs*\\\")\"", followtag = true, height = 400}) +#+END_SRC +*** Wibox + #+BEGIN_SRC lua + -- Create a wibox for each screen and add it + local taglist_buttons = gears.table.join( + awful.button({ }, 1, function(t) t:view_only() end), + awful.button({ modkey }, 1, function(t) + if client.focus then + client.focus:move_to_tag(t) + end + end), + awful.button({ }, 3, awful.tag.viewtoggle), + awful.button({ modkey }, 3, function(t) + if client.focus then + client.focus:toggle_tag(t) + end + end), + awful.button({ }, 4, function(t) awful.tag.viewnext(t.screen) end), + awful.button({ }, 5, function(t) awful.tag.viewprev(t.screen) end) + ) + #+END_SRC + #+BEGIN_SRC lua + local tasklist_buttons = gears.table.join( + awful.button({ }, 1, function (c) + if c == client.focus then + c.minimized = true + else + -- Without this, the following + -- :isvisible() makes no sense + c.minimized = false + if not c:isvisible() and c.first_tag then + c.first_tag:view_only() + end + -- This will also un-minimize + -- the client, if needed + client.focus = c + c:raise() + end + end), + awful.button({ }, 3, client_menu_toggle_fn()), + awful.button({ }, 4, function () + awful.client.focus.byidx(1) + end), + awful.button({ }, 5, function () + awful.client.focus.byidx(-1) + end)) + #+END_SRC + #+BEGIN_SRC lua + local function set_wallpaper(s) + -- Wallpaper + if beautiful.wallpaper then + local wallpaper = beautiful.wallpaper + -- If wallpaper is a function, call it with the screen + if type(wallpaper) == "function" then + wallpaper = wallpaper(s) + end + gears.wallpaper.maximized(wallpaper, s, true) + end + end + #+END_SRC + #+BEGIN_SRC lua + -- Re-set wallpaper when a screen's geometry changes (e.g. different resolution) + screen.connect_signal("property::geometry", set_wallpaper) + #+END_SRC + + #+BEGIN_SRC lua + awful.screen.connect_for_each_screen(function(s) + + -- Wallpaper + set_wallpaper(s) + -- Each screen has its own tag table. + awful.tag({"α", "β", "γ", "δ", "ε","♫","ζ","η","θ","ι","κ","λ","μ","ν","ξ","ο","π","ρ","σ","τ", + "υ","φ","χ","ψ","Ω"}, s, awful.layout.layouts[1]) + + -- Create a promptbox for each screen + s.mypromptbox = awful.widget.prompt() + -- Create an imagebox widget which will contains an icon indicating which layout we're using. + -- We need one layoutbox per screen. + s.mylayoutbox = awful.widget.layoutbox(s) + s.mylayoutbox:buttons(gears.table.join( + awful.button({ }, 1, function () awful.layout.inc( 1) end), + awful.button({ }, 3, function () awful.layout.inc(-1) end), + awful.button({ }, 4, function () awful.layout.inc( 1) end), + awful.button({ }, 5, function () awful.layout.inc(-1) end))) + -- Create a taglist widget + s.mytaglist = awful.widget.taglist(s, awful.widget.taglist.filter.all, taglist_buttons) + + -- Create a tasklist widget + s.mytasklist = awful.widget.tasklist(s, awful.widget.tasklist.filter.currenttags, tasklist_buttons) + + -- Create a calendar widget + local cal_notification + mytextclock:connect_signal("button::release", + function() + if cal_notification == nil then + awful.spawn.easy_async([[bash -c "ncal -3MC | sed 's/_.\(.\)/+\1-/g'"]], + function(stdout, stderr, reason, exit_code) + cal_notification = naughty.notify{ + text = string.gsub(string.gsub(stdout, + "+", "<span foreground='red'>"), + "-", "</span>"), + font = "Ubuntu Mono 9", + timeout = 0, + width = auto, + destroy = function() cal_notification = nil end + } + end + ) + else + naughty.destroy(cal_notification) + end + end) + #+END_SRC + Actual wibox setup for top bar: + #+BEGIN_SRC lua + -- Create the wibox + s.mywibox = awful.wibar({ position = "top", screen = s, visible = false }) + -- Colors for right wibox widgets + local fg_col = "#303f30" + local bg_col = "#395039" + + -- Add widgets to the wibox + s.mywibox:setup { + layout = wibox.layout.align.horizontal, + { -- Left widgets + layout = wibox.layout.fixed.horizontal, + -- mylauncher, + s.mytaglist, + s.mypromptbox, + }, + s.mytasklist, -- Middle widget + { -- Right widgets + layout = wibox.layout.fixed.horizontal, + separators.arrow_left(fg_col,bg_col), + wibox.container.background(wibox.container.margin(wibox.widget {cpuicon, cpu, layout = wibox.layout.align.horizontal},1,2), bg_col), + separators.arrow_left(bg_col,fg_col), + -- volume.widget, + wibox.container.background(wibox.widget {battery, layout = wibox.layout.align.horizontal}, fg_col), + separators.arrow_left(fg_col,bg_col), + wibox.container.background(wibox.widget {email_widget, layout = wibox.layout.align.horizontal}, bg_col), + separators.arrow_left(bg_col,fg_col), + wibox.container.background(wibox.widget {mykeyboardlayout, layout = wibox.layout.align.horizontal}, fg_col), + -- wibox.container.background(wibox.widget {myredshift, layout = wibox.layout.align.vertical([]myredshift)}, fg_col), + separators.arrow_left(fg_col,bg_col), + wibox.container.background(wibox.widget {spotify_widget, layout = wibox.layout.fixed.horizontal}, bg_col), + separators.arrow_left(bg_col,fg_col), + { + wibox.container.place(myredshift), + layout = wibox.layout.stack + }, + separators.arrow_left(fg_col,bg_col), + wibox.container.background(wibox.widget {net_wireless, wibox.widget.systray(), layout = wibox.layout.align.horizontal}, bg_col), + separators.arrow_left(bg_col,fg_col), + wibox.container.background(wibox.widget {mytextclock,s.mylayoutbox, layout = wibox.layout.align.horizontal}, fg_col) + }, + } +#+end_src +#+begin_src lua +end) +-- }}} +#+END_SRC + Wie redshift einbauen? + #+BEGIN_SRC lua + -- wibox.container.background(wibox.widget{{widget=dummy}, {widget=myredshift}, {widget=dummy}, layout=wibox.layout.flex.vertical}, fg_col) , + -- { + -- wibox.container.place(myredshift),--.content_fill_vertical, + -- layout = wibox.layout.fixed.horizontal + -- }, + #+END_SRC + +** Bindings + Mouse + #+BEGIN_SRC lua + -- {{{ Mouse bindings + root.buttons(gears.table.join( + awful.button({ }, 3, function () mymainmenu:toggle() end), + awful.button({ }, 4, awful.tag.viewnext), + awful.button({ }, 5, awful.tag.viewprev) + )) + -- }}} + #+END_SRC + and Keyboard + #+BEGIN_SRC lua + -- {{{ Key bindings + globalkeys = gears.table.join( + --awful.key({ modkey }, "z", function() spawn("tilix --quake", "Tilix", nil, "class") end), + awful.key({ modkey }, "z", function() quake_emacs:toggle() end), + awful.key({ modkey }, "e", function() quake:toggle() end), + awful.key({ modkey }, "c", function() awful.placement.centered(client.focus) end), + awful.key({ modkey }, "ä", function() awful.spawn("emacsclient -e \"(fpi/make-floating-frame)\"") end), + awful.key({ modkey }, "ö", function() awful.spawn("emacsclient -e \"(fpi/make-floating-capture-frame)\"") end), + awful.key ({ modkey }, "w", function() + awful.screen.focused().mywibox.visible = not awful.screen.focused().mywibox.visible + end, + {description="toggle top wibar", group="awesome"}), + --awful.key({ modkey, }, "z", function () awful.screen.focused().quake:toggle() end), + awful.key({ modkey, }, "s", hotkeys_popup.show_help, + {description="show help", group="awesome"}), + awful.key({ modkey, "Control" }, "Left", awful.tag.viewprev, + {description = "view previous", group = "tag"}), + awful.key({ modkey, "Control" }, "Right", awful.tag.viewnext, + {description = "view next", group = "tag"}), + awful.key({ modkey, }, "Escape", awful.tag.history.restore, + {description = "go back", group = "tag"}), + + awful.key({ modkey, }, "j", + function () + awful.client.focus.byidx( 1) + end, + {description = "focus next by index", group = "client"} + ), + awful.key({ modkey, }, "k", + function () + awful.client.focus.byidx(-1) + end, + {description = "focus previous by index", group = "client"} + ), + --awful.key({ modkey, }, "w", function () mymainmenu:show() end, + -- {description = "show main menu", group = "awesome"}), + + -- Layout manipulation + awful.key({ modkey, "Shift" }, "j", function () awful.client.swap.byidx( 1) end, + {description = "swap with next client by index", group = "client"}), + awful.key({ modkey, "Shift" }, "k", function () awful.client.swap.byidx( -1) end, + {description = "swap with previous client by index", group = "client"}), + awful.key({ modkey, "Control" }, "j", function () awful.screen.focus_relative( 1) end, + {description = "focus the next screen", group = "screen"}), + awful.key({ modkey, "Control" }, "k", function () awful.screen.focus_relative(-1) end, + {description = "focus the previous screen", group = "screen"}), + awful.key({ modkey, }, "u", awful.client.urgent.jumpto, + {description = "jump to urgent client", group = "client"}), + awful.key({ modkey, }, "Tab", + function () + awful.client.focus.history.previous() + if client.focus then + client.focus:raise() + end + end, + {description = "go back", group = "client"}), + awful.key({modkey, "Control"}, "l", + function() + if client.focus then + client.focus.sticky = not client.focus.sticky + end + end, + {description = "Toggle sticky", group = "client"}), + + -- Standard program + awful.key({ modkey, }, "Return", function () awful.spawn(terminal) end, + {description = "open a terminal", group = "launcher"}), + awful.key({ modkey, "Control" }, "r", awesome.restart, + {description = "reload awesome", group = "awesome"}), + awful.key({ modkey, "Shift" }, "q", awesome.quit, + {description = "quit awesome", group = "awesome"}), + + awful.key({ modkey, }, "l", function () awful.tag.incmwfact( 0.05) end, + {description = "increase master width factor", group = "layout"}), + awful.key({ modkey, }, "h", function () awful.tag.incmwfact(-0.05) end, + {description = "decrease master width factor", group = "layout"}), + awful.key({ modkey, "Shift" }, "h", function () awful.tag.incnmaster( 1, nil, true) end, + {description = "increase the number of master clients", group = "layout"}), + awful.key({ modkey, "Shift" }, "l", function () awful.tag.incnmaster(-1, nil, true) end, + {description = "decrease the number of master clients", group = "layout"}), + awful.key({ modkey, "Control" }, "h", function () awful.tag.incncol( 1, nil, true) end, + {description = "increase the number of columns", group = "layout"}), + awful.key({ modkey, "Control" }, "l", function () awful.tag.incncol(-1, nil, true) end, + {description = "decrease the number of columns", group = "layout"}), + awful.key({ modkey, }, "space", function () awful.layout.inc( 1) end, + {description = "select next", group = "layout"}), + awful.key({ modkey, "Shift" }, "space", function () awful.layout.inc(-1) end, + {description = "select previous", group = "layout"}), + + awful.key({ modkey, "Control" }, "n", + function () + local c = awful.client.restore() + -- Focus restored client + if c then + client.focus = c + c:raise() + end + end, + {description = "restore minimized", group = "client"}), + + -- Prompt + --awful.key({ modkey }, "r", function () awful.screen.focused().mypromptbox:run() end, + -- {description = "run prompt", group = "launcher"}), + awful.key({ modkey }, "r", + function () + awful.prompt.run({ prompt = "Run: ", hooks = { + {{ },"Return",function(command) + local result = awful.util.spawn(command) + awful.screen.focused().mypromptbox.widget:set_text(type(result) == "string" and result or "") + return true + end}, + {{"Mod1" },"Return",function(command) + local result = awful.util.spawn(command,{intrusive=true}) + awful.screen.focused().mypromptbox.widget:set_text(type(result) == "string" and result or "") + return true + end}, + {{"Shift" },"Return",function(command) + local result = awful.util.spawn(command,{intrusive=true,ontop=true,floating=true}) + awful.screen.focused().mypromptbox.widget:set_text(type(result) == "string" and result or "") + return true + end} + }}, + awful.screen.focused().mypromptbox.widget,nil, + awful.completion.shell, + awful.util.getdir("cache") .. "/history") + end), + awful.key({ modkey }, "x", + function () + awful.prompt.run { + prompt = "Run Lua code: ", + textbox = awful.screen.focused().mypromptbox.widget, + exe_callback = awful.util.eval, + history_path = awful.util.get_cache_dir() .. "/history_eval" + } + end, + {description = "lua execute prompt", group = "awesome"}), + + -- Menubar + awful.key({ modkey, "Control" }, "p", function() menubar.show() end, + {description = "show the menubar", group = "launcher"}) + ) + #+END_SRC + Launcher Binding using rofi. Before rofi version 1.4 + #+BEGIN_SRC shell :tangle no :exports code :eval never + "rofi -show run -bw 0 -fullscreen -padding 420 -hide-scrollbar -terminal "..terminal.." -location 0 -width 30 -color-normal \"#00303f30,#ff778877,#00303f30,#00303f30,#ffffffff\" -color-active \"#00303f30,#ff778877,#00303f30,#00303f30,#ffffffff\"-color-window \"#df303f30,#000000,#00303f30\" " + #+END_SRC + + #+BEGIN_SRC lua + globalkeys = gears.table.join(globalkeys, + awful.key({ modkey }, "p", function() awful.spawn.with_shell("PATH=~/.local/bin:$PATH rofi -show run -theme "..theme.."rofi_theme.rasi") end, + {description = "run rofi", group = "launcher"}) + ) + #+END_SRC + #+BEGIN_SRC lua + clientkeys = gears.table.join( + awful.key({ modkey, }, "f", + function (c) + c.fullscreen = not c.fullscreen + c:raise() + end, + {description = "toggle fullscreen", group = "client"}), + awful.key({ modkey, "Shift" }, "c", function (c) c:kill() end, + {description = "close", group = "client"}), + awful.key({ modkey, "Control" }, "space", awful.client.floating.toggle , + {description = "toggle floating", group = "client"}), + awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end, + {description = "move to master", group = "client"}), + awful.key({ modkey, }, "o", function (c) c:move_to_screen() end, + {description = "move to screen", group = "client"}), + awful.key({ modkey, "Shift" }, "u", function (c) c.ontop = not c.ontop end, + {description = "toggle keep on top", group = "client"}), + awful.key({ modkey, }, "n", + function (c) + -- The client currently has the input focus, so it cannot be + -- minimized, since minimized clients can't have the focus. + c.minimized = true + end , + {description = "minimize", group = "client"}), + awful.key({ modkey, }, "m", + function (c) + c.maximized = not c.maximized + c:raise() + end , + {description = "(un)maximize", group = "client"}), + awful.key({ modkey, "Control" }, "m", + function (c) + c.maximized_vertical = not c.maximized_vertical + c:raise() + end , + {description = "(un)maximize vertically", group = "client"}), + awful.key({ modkey, "Shift" }, "m", + function (c) + c.maximized_horizontal = not c.maximized_horizontal + c:raise() + end , + {description = "(un)maximize horizontally", group = "client"}) + ) + #+END_SRC + #+BEGIN_SRC lua + -- Bind all key numbers to tags. + -- Be careful: we use keycodes to make it work on any keyboard layout. + -- This should map on the top row of your keyboard, usually 1 to 9. + for i = 1, 9 do + globalkeys = gears.table.join(globalkeys, + -- View tag only. + awful.key({ modkey }, "#" .. i + 9, + function () + local screen = awful.screen.focused() + local tag = screen.tags[i] + if tag then + tag:view_only() + end + end), + -- Toggle tag display. + awful.key({ modkey, "Control" }, "#" .. i + 9, + function () + local screen = awful.screen.focused() + local tag = screen.tags[i] + if tag then + awful.tag.viewtoggle(tag) + end + end), + -- Move client to tag. + awful.key({ modkey, "Shift" }, "#" .. i + 9, + function () + if client.focus then + local tag = client.focus.screen.tags[i] --awful.screen.focused().tags[i] + if tag then + client.focus:move_to_tag(tag) + end + end + end), + -- Toggle tag on focused client. + awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9, + function () + if client.focus then + local tag = client.focus.screen.tags[i] + if tag then + client.focus:toggle_tag(tag) + end + end + end) + ) + end + #+END_SRC + #+BEGIN_SRC lua + function tablelength(T) + local count = 0 + for _ in pairs(T) do count = count +1 end + return count + end + #+END_SRC + #+BEGIN_SRC lua + globalkeys = gears.table.join(globalkeys, + -- Move client to tag to the right/left + -- Because of tag:view_only() does not preserve the current viewed tags! + -- ##TODO Make tags.length global? + awful.key({ modkey, "Shift" }, "Right", + function () + if client.focus then + local tag = client.focus and client.focus.first_tag or nil --.screen.tags[i] + local next_tag_index = tag.index + 1 + if next_tag_index == tablelength(client.focus.screen.tags)+1 then + next_tag_index = 1 + end + local next_tag = client.focus.screen.tags[next_tag_index] + if tag then + client.focus:move_to_tag(next_tag) + next_tag:view_only() + end + end + end, + {description = "move focused client one tag to the right", group = "tag"}), + awful.key({ modkey, "Shift" }, "Left", + function () + if client.focus then + local tag = client.focus and client.focus.first_tag or nil --.screen.tags[i] + local next_tag_index = tag.index - 1 + if next_tag_index == 0 then + next_tag_index = tablelength(client.focus.screen.tags) + end + local next_tag = client.focus.screen.tags[next_tag_index] + if tag then + client.focus:move_to_tag(next_tag) + next_tag:view_only() + end + end + end, + {description = "move focused client one tag to the left", group = "tag"}), + awful.key({ modkey }, "Right", + function () + local screen = awful.screen.focused() + local start_tag = screen.selected_tag + local next_tag_index = start_tag.index + 1 + if next_tag_index == tablelength(screen.tags)+1 then + next_tag_index = 1 + end + local next_tag=screen.tags[next_tag_index] + while next(next_tag:clients()) == nil do + next_tag_index = next_tag.index + 1 + if next_tag_index == tablelength(screen.tags)+1 then + next_tag_index = 1 + end + next_tag=screen.tags[next_tag_index] + if next_tag_index == start_tag.index then + break + end + end + if next_tag then + next_tag:view_only() + end + end, + {description = "view next non-empty tag on the right", group = "tag"}), + awful.key({ modkey }, "Left", + function () + local screen = awful.screen.focused() + local start_tag = screen.selected_tag + local next_tag_index = start_tag.index - 1 + if next_tag_index == 0 then + next_tag_index = tablelength(screen.tags) + end + local next_tag=screen.tags[next_tag_index] + while next(next_tag:clients()) == nil do + next_tag_index = next_tag.index - 1 + if next_tag_index == 0 then + next_tag_index = tablelength(screen.tags) + end + next_tag=screen.tags[next_tag_index] + if next_tag_index == start_tag.index then + break + end + end + if next_tag then + next_tag:view_only() + end + end, + {description = "view next non-empty tag on the left", group = "tag"}), + awful.key({ }, "Print", function () awful.util.spawn("scrot -e 'mv $f ~/screenshots/ 2>/dev/null'", false) end) + ) + #+END_SRC + #+BEGIN_SRC lua + clientbuttons = gears.table.join( + awful.button({ }, 1, function (c) client.focus = c; c:raise() end), + awful.button({ modkey }, 1, awful.mouse.client.move), + awful.button({ modkey }, 3, awful.mouse.client.resize)) + #+END_SRC +** Tag Movement +*** Move Tag to other screen +#+BEGIN_SRC lua :tangle no + local function move_tag(args) + screen = args.screen or awful.screen.focused() + local oldscreen = args.tag.screen + if oldscreen ~= screen then + local oldsel = oldscreen.selected_tag + args.tag.screen = screen + + if oldsel == args.tag then + local newtag = awful.tag.find_fallback(oldscreen) + if newtag then + newtag:view_only() + end + end + -- Rename Tag + --if string.find(tag.name, "'$") == nil then + -- tag.name = tag.name .. "'" + --end + + -- Insert tag at what position? + end + end + + local function rename_tag(args) + local input = (args.name=='' or args.name == nil) and "NaN" or args.name + args.tag.name = input + end + + globalkeys = gears.table.join(globalkeys, + awful.key({ modkey, "Shift" }, "r", + function () + awful.prompt.run { + prompt = 'New name: ', + text = '', + bg_cursor = '#aaaaaa', + -- To use the default rc.lua prompt: + textbox = mouse.screen.mypromptbox.widget, + --textbox = atextbox, + exe_callback = function(input) + rename_tag({name=input, tag=awful.screen.focused().selected_tag}) + end + } + end, + {description = "rename current tag", group = "tag"}), + awful.key({ modkey, "Shift", "Control" }, "t", + function () + local targetscreen = nil + --for s in screen do + --if s.index == client.focus.screen.index + 1 then + --targetscreen = s + --break + --end + --end + --move_tag({tag=client.focus.first_tag, screen=s}) + --move_tag({tag=awful.screen.focused().selected_tag, screen=s}) + move_tag({tag=client.focus.first_tag, screen=awful.screen.focused()}) + end, + {description = "move tag to other screen", group = "tag"}) + ) +#+END_SRC +*** Move all clients of tag to other tag +#+BEGIN_SRC lua + local function move_tag_clients (source,target) + naughty.notify({text="Hi"}) + naughty.notify({text="Moving from "..source}) + naughty.notify({text=" to "..target}) + if args.target ~= source then + for _,c in pairs(source:clients()) do + c:move_to_tag(target) + end + naughty.notify({text="success"}) + end + end + + globalkeys = gears.table.join(globalkeys, + awful.key({ modkey, "Shift", "Control" }, "v", + function () + local source = client.focus.first_tag + local target = awful.screen.focused().selected_tag + if target ~= source then + for _,c in pairs(source:clients()) do + c:move_to_tag(target) + end + end + end, + {description = "move clients of tag to other screen", group = "tag"}) + ) +#+END_SRC + +#+RESULTS: +** Volume and Brightness + #+BEGIN_SRC lua + -- {{{ Volume notify & changing + volnotify = {} + volnotify.id = nil + function volnotify:notify (msg) + self.id = naughty.notify({ text = msg, timeout = 1, replaces_id = self.id}).id + end + + function volume(incdec) + awful.util.spawn_with_shell ("vol=$(amixer -D pulse set Master 5%" .. incdec .. "|tail -1|cut -d % -f 1|cut -d '[' -f 2) && echo \"volnotify:notify('Volume $vol%')\"|awesome-client", false) + end + + function togglemute() + awful.util.spawn_with_shell("vol=$(amixer -D pulse set Master toggle|tail -n 1|cut -d '[' -f 3|cut -d ']' -f 1) && echo \"volnotify:notify('Volume $vol')\"|awesome-client", false) + end + + globalkeys = awful.util.table.join(globalkeys, + awful.key({ }, "XF86AudioLowerVolume", function () volume("-") end), + awful.key({ }, "XF86AudioRaiseVolume", function () volume("+") end), + awful.key({ }, "XF86AudioMute", togglemute)) + -- }}} + #+END_SRC + #+BEGIN_SRC lua + -- {{{ Brightness keys & notify + brnotify = {} + brnotify.id = nil + function brnotify:notify (msg) + self.id = naughty.notify({ text = msg, timeout = 1, replaces_id = self.id}).id + end + + function brightness(incdec) + awful.util.spawn_with_shell ("xbacklight " .. incdec .. "10;br=$(LANG=C printf \"%.0f\" $(xbacklight)) && echo \"brnotify:notify('Brightness $br%')\"|awesome-client", false) + end + + globalkeys = awful.util.table.join(globalkeys, + awful.key({ }, "XF86MonBrightnessDown", function () brightness("-") end), + awful.key({ }, "XF86MonBrightnessUp", function () brightness("+") end)) + -- }}} + #+END_SRC +** Music keys +For now just for Spotify & vlc: +#+BEGIN_SRC lua +globalkeys = awful.util.table.join(globalkeys, + awful.key({ }, "XF86AudioPlay", function () + awful.spawn("sp play") + awful.spawn("dbus-send --type=method_call --dest=org.mpris.MediaPlayer2.vlc /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause") + end), + awful.key({ }, "XF86AudioPause", function () + awful.spawn("sp play") + awful.spawn("dbus-send --type=method_call --dest=org.mpris.MediaPlayer2.vlc /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause") + end), + awful.key({ }, "XF86AudioNext", function () + awful.spawn("sp next") + awful.spawn("dbus-send --type=method_call --dest=org.mpris.MediaPlayer2.vlc /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Next") + end), + awful.key({ }, "XF86AudioPrev", function () + awful.spawn("sp prev") + awful.spawn("dbus-send --type=method_call --dest=org.mpris.MediaPlayer2.vlc /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Previous") + end), + awful.key({ }, "XF86Explorer", function () + awful.spawn("sp next") + awful.spawn("dbus-send --type=method_call --dest=org.mpris.MediaPlayer2.vlc /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Next") + end), + awful.key({ }, "XF86LaunchA", function () + awful.spawn("sp prev") + awful.spawn("dbus-send --type=method_call --dest=org.mpris.MediaPlayer2.vlc /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Previous") + end) +) +#+END_SRC +Still missing: +- <XF86AudioForward> +- <XF86AudioRewind> +** Launcher shortcuts + Open some programs directly instead of calling them over rofi. I + use the CAPS Key as it is used as a modifier key in my keyboard + layout (Neo2). + #+BEGIN_SRC lua + -- {{{ Launcher shortcuts + globalkeys = awful.util.table.join(globalkeys, + awful.key({ modkey, "Mod5" }, "y", function () awful.util.spawn("thunderbird") end, + {description = "Start Thunderbird", group = "buttons | Mod5=Caps"}), + awful.key({ modkey, "Mod5"}, "k", function () awful.util.spawn("autopass") end, + {description = "Start autopass", group = "buttons | Mod5=Caps"})) -- Mod5 == Caps/Ebene 3 (xmodmap hilft) + -- }}} + #+END_SRC +** TODO Fix for broken windows + Sometimes clients end up wierdly maximized after exiting fullscreen + or right after start. This just unsets everything. + + \\Does this still happen as of now? + #+BEGIN_SRC lua + -- {{{ Repair windows starting in floating, vert and horizontal maximized + globalkeys = awful.util.table.join(globalkeys, + awful.key({ modkey, "Shift" }, "x", function () client.focus.maximized_horizontal = false + client.focus.maximized_vertical = false + client.focus.maximized = false end, + {description = "repair no tiling windows", group = "client"})) + -- }}} + #+END_SRC +** move tags on screen disconnect + #+BEGIN_SRC lua + -- awful.button({ }, 1, function (c) client.focus = c; c:raise() end), + + -- doesnt work with tyrannical??? + tag.connect_signal("request::screen", function(t) + clients = t:clients() + for s in screen do + if s ~= t.screen and clients and next(clients) then + t.selected = false + t.volatile = true + t.screen = s + t.name = t.name .. "'" + --awful.tag.setvolatile(true, t) + return + end + end + end); + #+END_SRC +** Some more libraries + Screenful and screenmenu manage adding and removal of screens + during runtime. Tagmanip/Clientmanip provide more functionality to + manipulate Clients and tags. + + #+BEGIN_SRC lua + require("awful.remote") + require("screenful") + require("tagmanip") + require("clientmanip") + local screenmenu = require("screenmenu") + + globalkeys = gears.table.join(globalkeys, + awful.key({ modkey, "Shift" }, "p", function() screenManager() end, + {description = "run screen manager", group = "screen"}), + awful.key({ modkey }, "b", function() moveWindowToCurrentTag() end, + {description = "select window and move to tag", group = "tag"})) + #+END_SRC +** Set Keys + #+BEGIN_SRC lua + -- Set keys + root.keys(globalkeys) + -- }}} + #+END_SRC +** Rules + #+BEGIN_SRC lua + -- {{{ Rules + -- Rules to apply to new clients (through the "manage" signal). + awful.rules.rules = { + -- All clients will match this rule. + { rule = { }, + properties = { border_width = beautiful.border_width * 2, + border_color = beautiful.border_normal, + focus = awful.client.focus.filter, + raise = true, + keys = clientkeys, + buttons = clientbuttons, + screen = awful.screen.preferred, + placement = awful.placement.no_overlap+awful.placement.no_offscreen + } + }, + + -- Floating clients. + { rule_any = { + instance = { + "DTA", -- Firefox addon DownThemAll. + "copyq", -- Includes session name in class. + "guake", + }, + class = { + "Arandr", + "Gpick", + "Kruler", + "MessageWin", -- kalarm. + "Sxiv", + "Wpa_gui", + "pinentry", + "veromix", + "xtightvncviewer"}, + + name = { + "Ediff", + "^**Floating Emacs**$", -- floating emacs client on exact match + "^**Capture**$", + "Event Tester", -- xev. + "Volume Control" -- pavuaudio (pulseaudio controller) + }, + role = { + "AlarmWindow", -- Thunderbird's calendar. + "pop-up", -- e.g. Google Chrome's (detached) Developer Tools. + } + }, properties = { floating = true, placement = awful.placement.centered }}, + + -- Add titlebars to normal clients and dialogs + { rule_any = {type = { "normal", "dialog" } + }, properties = { titlebars_enabled = false } + }, + + -- Set Firefox to always map on the tag named "2" on screen 1. + -- { rule = { class = "Firefox" }, + -- properties = { screen = 1, tag = "2" } }, + } + -- }}} + #+END_SRC +** Signals + #+BEGIN_SRC lua + -- {{{ Signals + -- Signal function to execute when a new client appears. + client.connect_signal("manage", function (c) + -- Set the windows at the slave, + -- i.e. put it at the end of others instead of setting it master. + -- if not awesome.startup then awful.client.setslave(c) end + + if awesome.startup and + not c.size_hints.user_position + and not c.size_hints.program_position then + -- Prevent clients from being unreachable after screen count changes. + awful.placement.no_offscreen(c) + end + end) + + -- Add a titlebar if titlebars_enabled is set to true in the rules. + client.connect_signal("request::titlebars", function(c) + -- buttons for the titlebar + local buttons = gears.table.join( + awful.button({ }, 1, function() + client.focus = c + c:raise() + awful.mouse.client.move(c) + end), + awful.button({ }, 3, function() + client.focus = c + c:raise() + awful.mouse.client.resize(c) + end) + ) + + awful.titlebar(c) : setup { + { -- Left + awful.titlebar.widget.iconwidget(c), + buttons = buttons, + layout = wibox.layout.fixed.horizontal + }, + { -- Middle + { -- Title + align = "center", + widget = awful.titlebar.widget.titlewidget(c) + }, + buttons = buttons, + layout = wibox.layout.flex.horizontal + }, + { -- Right + awful.titlebar.widget.floatingbutton (c), + awful.titlebar.widget.maximizedbutton(c), + awful.titlebar.widget.stickybutton (c), + awful.titlebar.widget.ontopbutton (c), + awful.titlebar.widget.closebutton (c), + layout = wibox.layout.fixed.horizontal() + }, + layout = wibox.layout.align.horizontal + } + end) + + -- Enable sloppy focus, so that focus follows mouse. + client.connect_signal("mouse::enter", function(c) + if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier + and awful.client.focus.filter(c) then + client.focus = c + end + end) + + client.connect_signal("focus", function(c) + c.border_color = beautiful.border_focus + c.opacity = 1 + end) + client.connect_signal("unfocus", function(c) + c.border_color = beautiful.border_normal + if c.sticky then + c.opacity = 1 + else + c.opacity = 0.8 + end + end) + + + -- }}} + #+END_SRC diff --git a/redshift.org b/redshift.org new file mode 100644 index 0000000..dc2ed38 --- /dev/null +++ b/redshift.org @@ -0,0 +1,66 @@ +Website: http://jonls.dk/redshift/ +#+PROPERTY: header-args:conf :tangle tangle/redshift.conf :tangle-mode (identity #o444) +** Config +#+BEGIN_SRC conf +[redshift] +; Set the day and night screen temperatures +temp-day=5700 +temp-night=3500 + +; Enable/Disable a smooth transition between day and night +; 0 will cause a direct change from day to night screen temperature. +; 1 will gradually increase or decrease the screen temperature. +transition=1 + +; Set the screen brightness. Default is 1.0. +;brightness=0.9 +; It is also possible to use different settings for day and night +; since version 1.8. +;brightness-day=0.7 +;brightness-night=0.4 +; Set the screen gamma (for all colors, or each color channel +; individually) +gamma=0.8 +;gamma=0.8:0.7:0.8 +; This can also be set individually for day and night since +; version 1.10. +;gamma-day=0.8:0.7:0.8 +;gamma-night=0.6 + +; Set the location-provider: 'geoclue', 'geoclue2', 'manual' +; type 'redshift -l list' to see possible values. +; The location provider settings are in a different section. +location-provider=manual + +; Set the adjustment-method: 'randr', 'vidmode' +; type 'redshift -m list' to see all possible values. +; 'randr' is the preferred method, 'vidmode' is an older API. +; but works in some cases when 'randr' does not. +; The adjustment method settings are in a different section. +adjustment-method=randr + +; Configuration of the location-provider: +; type 'redshift -l PROVIDER:help' to see the settings. +; ex: 'redshift -l manual:help' +; Keep in mind that longitudes west of Greenwich (e.g. the Americas) +; are negative numbers. +[manual] +lat=52.375892 +lon=9.732010 + +; Configuration of the adjustment-method +; type 'redshift -m METHOD:help' to see the settings. +; ex: 'redshift -m randr:help' +; In this example, randr is configured to adjust screen 1. +; Note that the numbering starts from 0, so this is actually the +; second screen. If this option is not specified, Redshift will try +; to adjust _all_ screens. +[randr] +;screen=0 +#+END_SRC + +** Symlink + + #+BEGIN_SRC sh :tangle tangle/symlink.sh :shebang "#!/bin/bash" + ln -siv $(pwd)/tangle/redshift.conf ~/.config/ + #+END_SRC diff --git a/rofi.org b/rofi.org new file mode 100644 index 0000000..f706789 --- /dev/null +++ b/rofi.org @@ -0,0 +1,141 @@ +#+begin_src shell :tangle tangle/symlink.sh :results silent :shebang "#!/bin/bash" +ln -siv $(pwd)/tangle/config.rasi ~/.config/rofi/ +#+end_src + +#+begin_src conf :tangle tangle/config.rasi :eval never +,* { + background: #303f30df; + background-color: #00000000; + foreground: #778877ff; + + selected-normal-foreground: #ffffffff; + normal-foreground: #778877ff; + alternate-normal-foreground: @normal-foreground; + active-foreground: #bbccbb; + selected-active-foreground: #ffffff; + alternate-active-foreground: @active-foreground; + + normal-background: #00000000; + alternate-normal-background: #00000000; + selected-normal-background: #00000000; + selected-active-background: #00000000; + active-background: #00000000; + alternate-active-background: #00000000; + + border-color: #000000aa; + spacing: 2; + separatorcolor: #00000000; + red: rgba ( 220, 50, 47, 100 % ); + blue: rgba ( 38, 139, 210, 100 % ); + lightbg: rgba ( 238, 232, 213, 100 % ); + lightfg: rgba ( 88, 104, 117, 100 % ); + + selected-urgent-foreground: @background; + urgent-foreground: @red; + alternate-urgent-foreground: @red; + selected-urgent-background: @red; + urgent-background: @background; + alternate-urgent-background: @lightbg; +} +#window { + background-color: @background; + border: 0; + padding: 50; + transparency: "background"; +} +#mainbox { + border: 0; + padding: 0; +} +#message { + border: 1px dash 0px 0px ; + border-color: @separatorcolor; + padding: 1px ; +} +#textbox { + text-color: @foreground; +} +#listview { + fixed-height: 0; + border: 2px dash 0px 0px ; + border-color: @separatorcolor; + spacing: 2px ; + scrollbar: false; + padding: 2px 0px 0px ; +} +#element { + border: 0; + padding: 1px ; +} +#element.normal.normal { + background-color: @normal-background; + text-color: @normal-foreground; +} +#element.normal.urgent { + background-color: @urgent-background; + text-color: @urgent-foreground; +} +#element.normal.active { + background-color: @active-background; + text-color: @active-foreground; +} +#element.selected.normal { + background-color: @selected-normal-background; + text-color: @selected-normal-foreground; +} +#element.selected.urgent { + background-color: @selected-urgent-background; + text-color: @selected-urgent-foreground; +} +#element.selected.active { + background-color: @selected-active-background; + text-color: @selected-active-foreground; +} +#element.alternate.normal { + background-color: @alternate-normal-background; + text-color: @alternate-normal-foreground; +} +#element.alternate.urgent { + background-color: @alternate-urgent-background; + text-color: @alternate-urgent-foreground; +} +#element.alternate.active { + background-color: @alternate-active-background; + text-color: @alternate-active-foreground; +} +#scrollbar { + width: 4px ; + border: 0; + handle-color: @normal-foreground; + padding: 0; +} +#sidebar { + border: 2px dash 0px 0px ; + border-color: @separatorcolor; +} +#button { + spacing: 0; + text-color: @normal-foreground; +} +#button.selected { + background-color: @selected-normal-background; + text-color: @selected-normal-foreground; +} +#inputbar { + spacing: 0; + text-color: @normal-foreground; + padding: 1px ; +} +#case-indicator { + spacing: 0; + text-color: @normal-foreground; +} +#entry { + spacing: 0; + text-color: @normal-foreground; +} +#prompt { + spacing: 0; + text-color: @normal-foreground; +} +#+end_src diff --git a/ssh_config.org.gpg b/ssh_config.org.gpg Binary files differnew file mode 100644 index 0000000..c657ed9 --- /dev/null +++ b/ssh_config.org.gpg |