---
- name: emacs | Create doom directory
  file:
    path: '{{ xdg_dir.config_home }}/doom'
    state: directory
    mode: '755'

- name: emacs | Copy files
  copy:
    src: emacs/
    dest: '{{ xdg_dir.config_home }}/doom/'
    mode: '644'
    directory_mode: '755'

- name: emacs | Copy doom config
  template:
    src: emacs/config.j2
    dest: '{{ xdg_dir.config_home }}/doom/config.el'
    mode: '644'

- name: emacs | Clone Doom Emacs
  git:
    depth: 1
    repo: https://github.com/doomemacs/doomemacs.git
    dest: '{{ xdg_dir.config_home }}/emacs'

- name: emacs | Run 'doom install'
  command:
    cmd: '{{ xdg_dir.config_home }}/emacs/bin/doom -y install'
    creates: '{{ xdg_dir.config_home }}/emacs/.local/env'

- name: emacs | Compile and install parinfer-rust
  vars:
    parinfer_dir: '{{ xdg_dir.config_home }}/emacs/.local/etc/parinfer-rust'
  tags: parinfer
  block:
    - name: emacs | Clone parinfer-rust repository
      git:
        depth: 1
        repo: https://github.com/eraserhd/parinfer-rust.git
        dest: '{{ parinfer_dir }}'

    - name: emacs | Build parinfer-rust
      command: /usr/bin/cargo build --release --features emacs
      args:
        chdir: '{{ parinfer_dir }}'
        creates: '{{ parinfer_dir }}/target/release/libparinfer_rust.so'
