<commit_before>###############################################################################
# .shared_rc.d/emacs.sh
#
# Emacs
#
# GNU Emacs text editor
#
# https://www.gnu.org/software/emacs/
###############################################################################

# emacsd
#
# Control the emacs daemon.
emacsd() {
  if [[ "${1}" =~ '^-h|--help$' ]]
  then
    cat <<HEREDOC
Usage:
  emacsd (start | status | stop | restart)
  emacsd -h | --help

Options:
  -h --help  Display this usage information.

Description:
  Control the emacs daemon.
HEREDOC
  elif [[ "${1}" =~ '^start|up$' ]]
  then
    if ! emacsd status &>/dev/null
    then
      emacs --daemon &>/dev/null \
        && printf "\`emacs --daemon\` started.\n"
    else
      printf "\`emacs --daemon\` is already running.\n"
      return 1
    fi
  elif [[ "${1}" =~ ^stat ]]
  then
    if [[ "$(pgrep -lf emacs)" =~ 'emacs --daemon' ]]
    then
      printf "\`emacs --daemon\` is running.\n"
      return 0
    else
      printf "\`emacs --daemon\` is not running.\n"
      return 1
    fi
  elif [[ "${1}" =~ '^stop|down$' ]]
  then
    if emacsd status &>/dev/null
    then
      # Source, with other approaches:
      # http://stackoverflow.com/q/1167484
      emacsclient -e "(kill-emacs)" \
        && printf "\`emacs --daemon\` stopped.\n"
    else
      printf "\`emacs --daemon\` is not running.\n"
      return 1
    fi
  elif [[ "${1}" =~ ^r ]]
  then
    emacsd status &>/dev/null && emacsd stop
    emacsd start
  else
    emacsd -h
    return 1
  fi
}

# emacsc
#
# Wrapper for `emacsclient` with tweaked functionality.
emacsc() {
  if [[ "${1}" =~ '^-h|--help$' ]]
  then
    cat <<HEREDOC<commit_msg>Make `emacsd status` functionality the default.<commit_after>###############################################################################
# .shared_rc.d/emacs.sh
#
# Emacs
#
# GNU Emacs text editor
#
# https://www.gnu.org/software/emacs/
###############################################################################

# emacsd
#
# Control the emacs daemon.
emacsd() {
  if [[ "${1}" =~ '^-h|--help$' ]]
  then
    cat <<HEREDOC
Usage:
  emacsd (start | status | stop | restart)
  emacsd -h | --help

Options:
  -h --help  Display this usage information.

Description:
  Control the emacs daemon.
HEREDOC
  elif [[ "${1}" =~ '^start|up$' ]]
  then
    if ! emacsd status &>/dev/null
    then
      emacs --daemon &>/dev/null \
        && printf "\`emacs --daemon\` started.\n"
    else
      printf "\`emacs --daemon\` is already running.\n"
      return 1
    fi
  elif [[ "${1}" =~ '^stop|down$' ]]
  then
    if emacsd status &>/dev/null
    then
      # Source, with other approaches:
      # http://stackoverflow.com/q/1167484
      emacsclient -e "(kill-emacs)" \
        && printf "\`emacs --daemon\` stopped.\n"
    else
      printf "\`emacs --daemon\` is not running.\n"
      return 1
    fi
  elif [[ "${1}" =~ ^r ]]
  then
    emacsd status &>/dev/null && emacsd stop
    emacsd start
  else
    if [[ "$(pgrep -lf emacs)" =~ 'emacs --daemon' ]]
    then
      printf "\`emacs --daemon\` is running.\n"
      return 0
    else
      printf "\`emacs --daemon\` is not running.\n"
      return 1
    fi
  fi
}

# emacsc
#
# Wrapper for `emacsclient` with tweaked functionality.
emacsc() {
  if [[ "${1}" =~ '^-h|--help$' ]]
  then
    cat <<HEREDOC
{'fraction_non_alphanumeric': 0.2546972860125261, 'fraction_numerical': 0.010140172979421413, 'mean_word_length': 2.454170957775489, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4708353', 'n_tokens_mistral': 1206, 'n_tokens_neox': 1174, 'n_words': 312}