#!/bin/zsh # Helper to fetch last return status function laststatus { return $? } kde-current-activity () { qdbus org.kde.ActivityManager /ActivityManager/Activities org.kde.ActivityManager.Activities.CurrentActivity } kde-current-activity-name () { qdbus org.kde.ActivityManager /ActivityManager/Activities org.kde.ActivityManager.Activities.ActivityName `kde-current-activity` } # Check if server has been started and start it otherwise emacs-server-start () { emacsclient -s "$(kde-current-activity-name)" -e '(version)' &> /dev/null || (/usr/bin/emacs --daemon="$(kde-current-activity-name)"; ); } # This ensures that the right server is started; # I guess it can be done with -a "" when calling emacsclient, but # eventually I want to start emacs servers when the activity changes, # so this would need to be done separately anyways. emacs-server-start # This ensures that a new frame is created if only the default (tty) # one is present. It also names the new frame, in case I decide to # create secondary frames (e.g. for the agenda). emacsclient -s "$(kde-current-activity-name)" -n -e "(if (> (length (frame-list)) 1) 't)" | grep t >/dev/null; if [ "$?" = "1" ]; then emacsclient -s "$(kde-current-activity-name)" -c --frame-parameters="(quote (name . \"main-frame on $(kde-current-activity-name)\"))" "$@" else emacsclient -s "$(kde-current-activity-name)" "$@" fi STATUS=$?; # This does not seem to be needed anymore #emacsclient -s "$(kde-current-activity-name)" -e '(recenter-top-bottom)' return $STATUS