Skip to content

feat: add overleaf-create-file to create new project documents#33

Open
tigerjack wants to merge 4 commits into
vale981:devfrom
tigerjack:claude/charming-heisenberg-99nmt6
Open

feat: add overleaf-create-file to create new project documents#33
tigerjack wants to merge 4 commits into
vale981:devfrom
tigerjack:claude/charming-heisenberg-99nmt6

Conversation

@tigerjack

Copy link
Copy Markdown

Warning

I created this pull request because I find it useful. I don't know what your
policies are regarding AI-generated code, and I used a lot of assistance from
Claude.

Summary

Adds an interactive command overleaf-create-file that creates a new document
in the current Overleaf project and connects the current buffer to it. This lets
you author a file locally and push it to Overleaf without first creating it in
the web UI.

Motivation

Today a buffer can only connect to a document that already exists in the project
(the "Select file" prompt is built from the existing rootFolder), so adding a
new file means creating it in the browser first. This command closes that gap.

What it does

  • M-x overleaf-create-file (bound to n in overleaf-command-map) prompts for
    a name, creates the document on the server (POST /project/<id>/doc), sets
    overleaf-document-id to the returned id, and connects the buffer.
  • The file-local variables (overleaf-url, overleaf-project-id,
    overleaf-document-id) are written as soon as the connection is established, so
    the new file is bound and persisted immediately.

Implementation

  • overleaf--project-root-folders caches each project's root folder id, captured
    from joinProjectResponse, and is used as the parentFolderId for new docs.
    (The command therefore requires having connected to the project once in the
    session; it errors with a clear message otherwise.)
  • overleaf--fetch-project-meta reads the CSRF token (ol-csrfToken) from the
    project page (and tries the root folder id from the page as a fallback).
  • overleaf--http-post-json performs the POST and returns (status . body) so
    failures surface the server response.
  • Menu entry + README updated; new command bound to n.

Testing

Verified against overleaf.com: POST /project/<id>/doc with body
{"name": ..., "parentFolderId": <rootFolderId>} and an X-Csrf-Token header
returns 200 with {"name": ..., "_id": "<24-hex>"}, the file appears in the
project tree, and the buffer connects and syncs.

Notes

  • The page scrape for the root folder id isn't present on all instances, hence
    the joinProjectResponse cache is the primary source.

vale981 and others added 4 commits April 17, 2026 14:54
Adds an interactive command `overleaf-create-file' that creates a new
document on the Overleaf server (via the web API) and connects the
current buffer to it, so a brand-new local file can be pushed to a
project without first creating it in the web UI.

- Cache each project's root folder id (captured from joinProjectResponse)
  in `overleaf--project-root-folders', used as the parent folder for new
  documents.
- Add web-API helpers `overleaf--fetch-project-meta' (scrapes the CSRF
  token and root folder id from the project page) and
  `overleaf--http-post-json' (POST with informative status/body return).
- Bind the command to `n' in `overleaf-command-map', add a menu entry,
  and document it in the README.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MCRf4hfJxiH76ic1TE4riS
After creating a new document and connecting, write the file-local
variables (overleaf-url, overleaf-project-id, overleaf-document-id) as
soon as the connection is established instead of waiting for the first
edit, so a newly created file is bound and persisted right away.

Adds `overleaf--persist-when-connected', a small poll-until-connected
helper used by `overleaf-create-file'.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MCRf4hfJxiH76ic1TE4riS
@vale981

vale981 commented Jul 3, 2026

Copy link
Copy Markdown
Owner

hey sorry for the late response. my standards regarding AI submissions is that you have to be sure that /you/ understand the code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants