No description
Find a file
2021-08-12 09:20:02 -05:00
matrix-spec-r0.6.1.org Tidy: Blocks 2021-08-12 09:20:02 -05:00
README.org Tidy: Blocks 2021-08-12 09:20:02 -05:00

Matrix Spec in Org format

This orphan branch has a version of the Matrix client-server spec in Org format. It was produced by this Pandoc command:

  pandoc -f html-empty_paragraphs-native_divs-native_spans -t org --strip-comments --wrap=none Client-Server\ API.html >matrix-spec.or
g

Then various cleanups were done, some of which are included below:

Cleanups

Change JSON example blocks to source blocks

This also changes the type of blocks that are HTTP request examples which appear to contain JSON.

  (let ((reporter (make-progress-reporter "Changing block types" 0 (buffer-size))))
    (save-excursion
      (goto-char (point-min))
      (while (re-search-forward (rx bol "#+BEGIN_" (group "EXAMPLE") (0+ blank) eol) nil t)
        (save-restriction
          (org-narrow-to-block)
          (goto-char (match-end 0))
          (forward-line 1)
          (when (save-match-data
                  (or (re-search-forward (rx (0+ blank) "{") (point-at-eol) t)
                      (re-search-forward (rx bol (0+ blank) "}" (0+ blank) "\n" "#+END") nil t)))
            ;; Appears to be a JSON block.
            (goto-char (match-end 1))
            (replace-match "SRC" t t nil 1)
            (insert " json")
            (re-search-forward (rx bol "#+END_" (group "EXAMPLE") (0+ blank) eol) nil)
            (replace-match "SRC" t t nil 1)))
        (progress-reporter-update reporter (point)))))

Reindent source blocks

  (defun ap/org-in-block-p ()
    "Non-nil when point belongs to a block.

  Return first block name matched, or nil.  Beware that in case of
  nested blocks, the returned name may not belong to the closest
  block from point."
    (save-match-data
      (let ((case-fold-search t)
            (lim-up (save-excursion (outline-previous-heading)))
            (lim-down (save-excursion (outline-next-heading))))
        (org-between-regexps-p "^[ \t]*#\\+begin_" "^[ \t]*#\\+end_"
                               lim-up lim-down))))

  (defun ap/indent-whole-buffer ()
    "Indent whole buffer."
    (interactive)
    (delete-trailing-whitespace)
    (indent-region (point-min) (point-max) nil))

  (defun ap/org-indent-src-block ()
    (interactive)
    (when (ap/org-in-block-p)
      (org-edit-src-code)
      (insert (replace-regexp-in-string
               " +" " " (delete-and-extract-region (point-min) (point-max))))
      (ap/indent-whole-buffer)
      (whitespace-cleanup)
      (org-edit-src-exit)))

  (save-excursion
    (goto-char (point-min))
    (while (re-search-forward (rx "#+BEGIN_" (or "EXAMPLE" "SRC")) nil t)
      (ap/org-indent-src-block)))

Unescape underscores

Some content keys have backslashes before underscores, for some reason. Let's remove those and realign their tables.

  (save-excursion
    (goto-char (point-min))
    (while (re-search-forward (rx "\\_") nil t)
      (replace-match "_" t t)
      (when (org-at-table-p)
        (org-table-align))))