Skip to content
nick-maderightPublic

About

View .docx tracked changes and comments in Emacs, rendered as org-mode

Resources

Stars

38 stars

Watchers

1 watching

Forks

Repository files navigation

docx-view

Read a .docx file in Emacs with its tracked changes and its comments intact, rendered as org-mode.

Word documents arrive from collaborators full of revision marks and margin comments, and that is exactly the part every text-mode reader throws away. Pandoc’s own org writer discards revision and comment spans, so pandoc -t org gives you clean prose while losing the whole review without saying so, and that review is the part docx-view keeps.

Reading is all it does. It never writes to a .docx and it does not convert one, and it refuses a save with an error instead of accepting it and discarding the text, so the document you are reading cannot be damaged by a stray C-x C-s.

What it looks like

Here is a document with an insertion, a deletion, a substitution and a comment.

** Fox Report
[[dvchg:c0][(1)]]The quick [[dvchg:ins-1][very]] [[dvchg:del-2][brown]] fox jumps over the lazy dog.

We should [[dvchg:del-3][utilize]][[dvchg:ins-4][use]] plain words.

** Comments (1)
- [1] Alice Smith, 2026-08-01 03:00
  Which dog?

In the buffer each link shows only its description, colored by kind and by author. Insertions are underlined, deletions struck through, and comment markers get a face of their own. The link target carries the change identity, which is what makes navigation, the change list and imenu work.

Org emphasis characters cannot express this, so links do the work instead. Org requires /slashes/ to sit at a word boundary, and a tracked change routinely begins mid-word or against a CJK character, where the markup would not render at all. A link works in both places.

Install

docx-view requires Emacs 27.1 or newer, pandoc, and unzip. It has no Emacs Lisp dependencies at all.

use-package with :vc (Emacs 30 or newer)

(use-package docx-view
  :vc (:url "https://github.com/nick-maderight/docx-view" :rev :newest))

Keep the :rev :newest. The default, :last-release, means the newest commit that changed the Version: header. Nothing has bumped that header since the first commit, so the default installs the first commit rather than current code.

use-package with elpaca

(use-package docx-view
  :ensure (:host github :repo "nick-maderight/docx-view"))

A recipe in :ensure requires elpaca-use-package-mode already on, which elpaca’s own bootstrap block enables.

From source, on any supported Emacs

(add-to-list 'load-path "/path/to/docx-view")
(require 'docx-view)

That is the whole setup. Opening any .docx, .docm, .dotx or .dotm then puts you in docx-view-mode, because the package autoloads its own auto-mode-alist entry.

Pandoc must be on exec-path. If it lives somewhere Emacs cannot see, set docx-view-pandoc-program to its absolute path.

Use

Open a file the way you open any other, with C-x C-f, or call M-x docx-view for a prompt that offers only Word documents. In Dired, M-x docx-view-dired-view opens the file at point.

KeyCommandEffect
C-c C-cdocx-view-cycle-modecycle all changes, accepted, rejected
C-c C-vdocx-view-set-modechoose one of those three directly
C-c C-ndocx-view-next-changemove to the next change
C-c C-pdocx-view-previous-changemove to the previous change
C-c C-odocx-view-show-at-pointdescribe the change or comment under point
C-c C-ldocx-view-list-changesevery change in one buffer, RET jumps to it
C-c C-adocx-view-filter-authormark one reviewer’s changes, empty input clears
C-c C-edocx-view-open-externallyhand the file to the system’s own application
gdocx-view-revertre-read from disk
qquit-windowleave

The buffer runs org-mode itself, with org-mode-map as its parent keymap, so folding, imenu, speed keys and org navigation all work as usual.

All three view modes come from a single pandoc run. docx-view asks for --track-changes=all once and derives the accepted and rejected views from that same tree, which makes switching modes instant and keeps the three views from ever disagreeing.

Options

These live in the docx-view customize group.

OptionDefaultMeaning
docx-view-default-modeallwhich revisions a document shows when first opened
docx-view-render-commentssectionsection, inline or none
docx-view-render-change-markerlinklink, or plain for face-only marking with no markup
docx-view-render-author-colors7 colorsthe palette assigned to authors in order of appearance
docx-view-render-metadata-drawertgive each heading a property drawer of change counts
docx-view-startup-foldednilopen with headings folded
docx-view-show-warningstreport in the echo area what could not be represented
docx-view-pandoc-program"pandoc"name of, or absolute path to, pandoc
docx-view-pandoc-extra-argsnilextra pandoc arguments, such as --extract-media=DIR
docx-view-unzip-program"unzip"must accept -p, meaning write member to stdout

With docx-view-render-comments set to section, a comment appears as a numbered marker in the prose and its text goes to a section at the end, where a threaded discussion keeps its structure. inline puts the text in the prose immediately after the range it annotates, which reads well for one short comment and badly for a thread. none keeps the markers and leaves the text to C-c C-o and the change list.

Styling comes from six faces that theme like any others. They are docx-view-insertion, docx-view-deletion, docx-view-paragraph-change, docx-view-comment-marker, docx-view-comment-range and docx-view-comment-resolved.

How it works

Each layer gets a file of its own, so that a change to any one of them stays contained.

  • docx-view-pandoc.el owns the pandoc subprocess and the shape of its JSON output. The request is for JSON and not for org, because the JSON AST is the only form that still carries the revision and comment spans. Filtering for the accepted and rejected views happens here, over the parsed tree.
  • docx-view-ooxml.el reads the parts of the archive that pandoc does not report. Comment authors, timestamps, reply threading and resolved state live in word/comments.xml, word/commentsExtended.xml and word/people.xml, and while pandoc surfaces the comment text it leaves the metadata around it behind. This layer extracts single members with unzip -p and parses them with the built-in XML parser.
  • docx-view-render.el turns the filtered tree into org text, records where every change landed, and builds the comment section.
  • docx-view.el is the mode itself, holding the keymap, the menu, the overlays, navigation, the change list, imenu, and the guards that keep the buffer from ever being written back. A read-only buffer can still be saved, so the refusal lives on write-contents-functions and carries the permanent-local-hook property to survive a major mode change.

What pandoc cannot see

Pandoc’s docx reader represents insertions, deletions and paragraph-level insertions and deletions, and it reports comment text. Moves, formatting-only revisions, and table row and cell revisions are outside what it represents. Those are read straight from the OOXML instead and listed in an “Other revisions” section, so the document tells you they exist instead of dropping them without a word.

When something cannot be placed in the text at all, say a comment anchored nowhere, it is reported in the echo area and still shown in the comment section. A viewer that hides what it could not represent is worse than one that says so.

Development

make test      # run the ERT suite
make compile   # byte-compile with every warning an error
make lint      # package-lint and checkdoc
make check     # all three, which is what CI runs

Plain make is a deliberate choice. Eldev and cask are both good, but each is one more thing to install before a contributor can run the tests, and this package’s whole claim is that it requires nothing but Emacs and pandoc.

The 68 tests cover each layer and the mode. The fixtures under test/fixtures are hand-built OOXML rather than documents saved by Word, so each one exercises one feature of the format and the suite has no dependency on a Word installation. test/fixtures/generate-fixtures.py rebuilds them.

Tests that require pandoc skip instead of failing when it is absent, so the suite still says something useful on a machine without it.

CI runs the suite on Emacs 27.1, 27.2, 28.2, 29.4, 30.2 and snapshot on Linux, and on 28.1 and 30.2 on macOS. The macOS floor is 28.1 rather than 27.1 because macos-latest is Apple Silicon and nix-emacs-ci, which purcell/setup-emacs builds from, does not build anything below 28.1 for aarch64-darwin. The 27.1 floor is still tested, on Linux.

License

GPL-3.0-or-later. See LICENSE.

About

View .docx tracked changes and comments in Emacs, rendered as org-mode

Resources

Stars

38 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages