-
- if pgrep -G iank -u iank -f 'emacs --daemon' &>/dev/null; then
- emacsfiles="$(emacsclient --eval "$(cat /usr/local/bin/unsaved-buffers.el)"| sed '/^"nil"$/d;s/^"(/E: /;s/)"$//')"
- if [[ $emacsfiles ]]; then
- chars+=("$emacsfiles")
+ # We do this once every 5 minutes, since this is not a grave problem.
+ # For formatted elisp, see /b/ds/unsaved-buffers.el
+ elisp='(format "%s" (-reduce-from (lambda (acc buf) (let ((bpath (buffer-file-name buf))) (if (and bpath (buffer-modified-p buf)) (cons bpath acc ) acc))) nil (buffer-list)))'
+ if [[ ! $last_emacs_check || $emacsfiles ]] || (( last_emacs_check < EPOCHSECONDS - 300 )); then
+ if pgrep -G iank -u iank -f 'emacs --daemon' &>/dev/null; then
+ # i dun care if this fails
+ emacsfiles="$(timeout 1 emacsclient -a /usr/bin/true --eval "$elisp" 2>/dev/null | sed '/^"nil"$/d;s/^"(/E: /;s/)"$//' ||:)"
+ if [[ $emacsfiles ]]; then
+ chars+=("$emacsfiles")
+ fi