0

Emacs workflow is smooth. Usually we want it smoother. But I would like to make it less smooth..

This might be a strange question. I use emacs and mu4e to deal with my mails. However, the workflow is so smooth that sometimes I found myself checking it impulsively without thinking..

I wonder if there's a way to tweak this workflow (by adding some elips code?) to restrict myself from checking it too often!

I'm pretty new to emacs, and would like to learn some practical elisp-codes. This could be my first one to start with. Any pointers to relevant tutorial / documentations are appreciated.

  • 1
    what command do you use to check email, and how often do you close/reopen emacs? – John Kitchin Nov 2 at 23:24
  • I believe I use this mu4e-get-mail-command "mbsync -c ~/.emacs.d/.mbsyncrc gmail" to fetch email. – Student Nov 3 at 1:14
  • Almost never close it! I have moved into it =) – Student Nov 3 at 1:15
  • 1
    I mean what M-x command do you use to check your email. You can advise that command so it checks when the last time you ran it, and won't run it if it is less than some interval you choose. – John Kitchin Nov 3 at 12:41
  • That is brilliant! I wrote a shell script that works! – Student Nov 3 at 14:00
0

Following @John's advice, I wrote a primitive shell script that checks the difference between current time and the last check time. If the difference is not larger than $mercy, then it won't proceed. Otherwise, mail will be checked and time will be recorded in the same file (unit: linux epoch time).

#!/bin/bash

### Content ###
# This shell script restricts myself from
# impulsively checking my email too frequently.
#
# After running mail check command, the current time will
# be recorded in the end of this script.

### Config ###
checkMailCommand="mbsync -c ~/.emacs.d/.mbsyncrc gmail"
mercy=28800 # in second

### Main Script ###
scriptDir=$HOME/.scripts/checkmail
currentTime=$(date '+%s' -d $(date -Is))
lastCheckTime=$(cat $scriptDir | tail -1 | sed '/^\# */!d; s///;q')
timeDiff=$(($currentTime - $lastCheckTime))

if [[ $timeDiff -gt $mercy ]]; then
    $checkMailCommand
    echo "# $currentTime" >> $scriptDir
else
    echo "You check your mail too frequently --"
    echo "check it again $(($mercy - $timeDiff)) seconds later!"
    echo "  or change config in $scriptDir."
    echo "Exiting in 5 seconds.."
    sleep 5
fi

exit

### checkmail history (unit: linux epoch time) ###
# 1572789737

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.