Skip to content
ddx0bPublic

About

Prime loves Emacs

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

neder.el

An Emacs “vivecoded” port of ThePrimeagen’s 99. It augments hand-written code rather than replacing it: you select a region, say what you want, and the answer comes back into that exact region under your review.

Neder is not an HTTP client. It spawns an agentic coding CLI (claude, opencode, …) as a subprocess, hands it a prompt assembled from your selection plus project context, and applies the result back to the buffer that asked for it.

Why this and not a chat buffer

Three different jobs, three different tools. Neder only does the middle one.

JobTool
Long agentic session, multi-file, repo-wideclaude-code-ide
Surgical in-buffer op on a regionNeder
Open-ended chatgptel

Key features

  • Region in, region out. The answer replaces the selection you made, in the buffer you made it in, even if the buffer shifted meanwhile.
  • Review before anything is written. The default apply style shows a unified diff and asks. Nothing reaches a source file unseen.
  • Mid-request edit detection. If you edit the region while the model is thinking, you are asked before its answer discards your edit.
  • Structured responses. Providers parse a JSON envelope, so the answer is a named field rather than prose to be guessed at. Cost and turn count come back with it.
  • Scoped context. Sends the enclosing function via tree-sitter, not a fixed line window, so the model never receives a form cut in half. Flymake diagnostics ride along.
  • Skills and file references. Write #skill or @path in a prompt and the content is injected, with completion for both.
  • Three ops, and a registry for your own. visual, ask, search, plus neder-run for ops you define in your config.
  • Cancellable. Every request can be stopped; a CLI that ignores SIGTERM gets SIGKILL.

How it works

region + prompt
      |
      v
prompt assembly ... operation text
                    user prompt
                    diagnostics
                    #skills and @files
                    CLAUDE.md / AGENTS.md walked up to project root
                    output contract
      |
      v
provider CLI as a subprocess (no shell, argv list)
      |
      v
response parsed from the JSON envelope
      |
      v
markers locate the original region --> diff --> you approve --> buffer

Two details matter.

Markers, not line numbers. The region is tracked with Emacs markers carrying their own buffer. Edits elsewhere in the file shift them correctly, and the answer cannot land in whatever buffer you happened to switch to. If the region was deleted outright, the request fails instead of guessing.

Two transports. By default the CLI is told to answer on stdout and touch nothing. Set neder-unsafe-skip-permissions and it is instead told to write to a temp file, matching upstream — that passes --dangerously-skip-permissions to claude, which lets it modify files and run commands with no confirmation. The default is the safe one.

Install

Requires Emacs 30.2 and a provider CLI on PATH.

Doom Emacs

The package is developed in place, so straight does not manage it.

;; config.el
(add-load-path! "~/projects/Neder")

(use-package! neder
  :defer t
  :commands (neder-visual neder-ask neder-search neder-run neder-open
             neder-stop-all-requests neder-info)
  :init
  (map! :leader
        (:prefix-map ("n" . "Neder")
         :desc "Visual selection prompt" :v  "v" #'neder-visual
         :desc "Ask about selection"     :v  "a" #'neder-ask
         :desc "Semantic search"         :nv "s" #'neder-search
         :desc "Reopen a past result"    :nv "o" #'neder-open
         :desc "Stop all requests"       :nv "k" #'neder-stop-all-requests
         :desc "Info"                    :nv "i" #'neder-info))
  :config
  (setq neder-provider 'claude
        neder-context-file-names '("CLAUDE.md" "AGENTS.md")
        neder-visual-apply-style 'confirm
        neder-context-strategy 'defun))

A GUI or daemon Emacs started from the desktop does not inherit the login shell’s PATH, so the CLI will not be found. Either fix exec-path or point at it directly:

(setq neder-executable-overrides '((claude . "~/.local/bin/claude")))

Usage

neder-visual — replace the selection

Select a region, run neder-visual, describe the change. The model’s answer replaces the selection.

Works well on a region that is a note to yourself:

def parse_config(path):
    # TODO read the file, parse it as TOML, raise ConfigError on bad input
    pass

Select the body, prompt implement this, review the diff, accept.

neder-ask — question without modification

Same selection, but the answer renders as Org in *neder-answer* and the source buffer is never touched. For “what does this do”, “why is this slow”, “what breaks if I change this”.

neder-search — agentic project search

No region needed. Describe what you are looking for; results land in a grep-mode buffer, so n / p / RET navigate them like any grep.

Unlike grep, this reads and reasons about the code, so “where do we retry failed uploads” works even when nothing contains the word retry.

The prompt buffer

Prompts open in a small neder-prompt-mode buffer.

KeyAction
C-c C-cSend
C-c C-kAbort
#Complete a skill name
@Complete a project file

Set neder-use-prompt-buffer to nil for a plain minibuffer prompt.

Skills

A skill is a directory holding a SKILL.md. Referencing #tdd in a prompt injects that file’s content into the request.

.agents/skills/tdd/SKILL.md
.claude/skills/pr/SKILL.md
~/.claude/skills/review/SKILL.md

Searched in neder-skill-directories order, so a project-local skill shadows a global one of the same name.

File references

@src/auth.py injects that file. Paths resolve from the project root and complete from git ls-files, so .gitignore is respected. Files over neder-max-reference-file-bytes (100 KiB) are skipped.

Other commands

CommandDoes
neder-openReopen a past result
neder-stop-requestCancel the most recent in-flight request
neder-stop-all-requestsCancel everything
neder-infoIn-flight and completed counts, session cost

Reviewing the answer

neder-visual-apply-style decides what happens when the answer arrives.

ValueBehaviour
confirmUnified diff, then yes/no. The default.
directReplace immediately.
ediffEdiff session; the proposed buffer is applied when it ends.

Every replacement is a single undo step regardless of style.

If the region changed while the request was running, you are asked before the answer is applied — the answer was computed from the old text, so applying it silently would discard your edit.

Defining your own op

Ops live in a registry, so a new workflow is config rather than a patch. neder-run drives any registered op:

(defun my/neder-diagnose-tests ()
  "Run the test suite and locate every failure."
  (interactive)
  (neder-run :op 'search
            :prompt "run the project's test suite, then report the location
of every failure with a note explaining the cause"))

Registering a genuinely new op takes two functions — one that builds the operation text, one that handles the response:

(neder-register-op
 (neder-op-create
  :name 'explain
  :region-p t          ; reads the active region
  :track-p nil         ; does not write back, so no markers
  :op-prompt (lambda (req)
               (format "Explain this code to a new teammate.\n%s"
                       (neder-request-selection req)))
  :complete (lambda (req response)
              (with-current-buffer (get-buffer-create "*explain*")
                (erase-buffer)
                (insert response)
                (pop-to-buffer (current-buffer))))))

Set :track-p only when the op writes its answer back to the region; that is what decides whether markers are taken and whether the overlap guard applies.

Providers

ProviderCLIDefault model
claudeclaudeclaude-sonnet-5-5
opencodeopencodeopencode/claude-sonnet-4-5

Switch with neder-provider; override the model with neder-model. Adding one is a build-command and a default model:

(neder-register-provider
 (neder-provider-create
  :name 'cursor-agent
  :display-name "CursorAgentProvider"
  :executable "cursor-agent"
  :default-model "sonnet-4.5"
  :build-command
  (lambda (model prompt unsafe)
    (append '("cursor-agent")
            (when unsafe '("--trust" "--force"))
            (list "--model" model "--print" prompt)))))

The prompt is always the last positional argument.

Give a provider a parse-response when its CLI can emit structured output. It receives stdout and returns a plist with :text and optionally :cost, :session-id, :turns and :error. This is what keeps a chatty preamble out of your source files.

Configuration reference

VariableDefaultMeaning
neder-provider'claudeWhich CLI to drive
neder-modelnilOverride the provider’s default model
neder-executable-overridesnilAbsolute path per provider
neder-visual-apply-style'confirmHow answers reach the buffer
neder-confirm-on-changed-selectiontAsk if the region changed mid-request
neder-context-strategy'defunEnclosing form, or a line window
neder-surrounding-context-lines100Window size when strategy is 'lines
neder-context-file-namesnile.g. "CLAUDE.md", walked to the root
neder-skill-directoriesthree defaultsWhere #skill looks
neder-reference-filestResolve @path references
neder-include-diagnosticstSend Flymake diagnostics
neder-include-hovernilSend LSP hover text (synchronous)
neder-use-prompt-buffertPrompt buffer instead of the minibuffer
neder-spinnertIn-buffer progress indicator
neder-request-timeout300Seconds before a request is cancelled
neder-max-concurrent-requests3In-flight cap
neder-unsafe-skip-permissionsnilLet the CLI write files and run commands
neder-debugnilLog to *neder-log*, mirror prompts

Tests

emacs -Q --batch -L . -l neder-tests.el -f ert-run-tests-batch-and-exit

The suite uses a stub provider whose argv is a shell command, so no model is ever called and the tests cost nothing.

Differences from upstream

Deliberate divergences, all of them Emacs-shaped:

  • Markers instead of extmarks, and an assert that the answer lands in the buffer that made the request.
  • atomic-change-group so a replacement is one undo step and cannot be half-applied.
  • Diff review before the buffer is touched. Upstream writes directly.
  • JSON response parsing, so safe mode does not depend on the model declining to write a preamble.
  • A request timeout, a concurrency cap, an overlap guard and SIGKILL escalation. Upstream has none of these.
  • neder-ask, which upstream has no equivalent of.
  • Not ported: vibe, tutorial, the Worker extension, the model and provider pickers.

License

MIT License. See LICENSE for details.

About

Prime loves Emacs

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages