#!/bin/sh # Writes what `forward-word` needs from Emacs to Sources/OrgCore/Semantic/WordSyntax.swift: # the characters without word syntax in an org-mode buffer, and `char-script-table`. # Usage: scripts/update-word-syntax.sh [emacs] set -eu cd "$(dirname "$0")/.." emacs=${1:-emacs} out=Sources/OrgCore/Semantic/WordSyntax.swift { echo "// Generated by scripts/update-word-syntax.sh from $("$emacs" --version | head -1) and Org $("$emacs" -Q --batch --eval '(progn (require (quote org)) (princ (org-version)))')." echo echo "extension TextStats {" echo " /// Code points without word syntax in org-mode, sorted." echo " static let nonWord: [ClosedRange] = [" "$emacs" -Q --batch --eval ' (progn (require (quote org)) (with-temp-buffer (org-mode) (let ((c 0) start) (while (<= c #x110000) (let ((word (and (< c #x110000) (eq (char-syntax c) ?w)))) (cond ((and (not word) (not start) (< c #x110000)) (setq start c)) ((and (or word (= c #x110000)) start) (princ (format " 0x%X...0x%X,\n" start (1- c))) (setq start nil)))) (setq c (1+ c))))))' echo " ]" echo echo " /// \`char-script-table\`: where each script's range starts, and its script." echo " static let scripts: [(start: UInt32, script: UInt16)] = [" "$emacs" -Q --batch --eval ' (let ((c 0) (ids (make-hash-table)) prev) (while (< c #x110000) (let ((s (aref char-script-table c))) (unless (and (> c 0) (eq s prev)) (unless (gethash s ids) (puthash s (hash-table-count ids) ids)) (princ (format " (0x%X, %d),\n" c (gethash s ids))) (setq prev s))) (setq c (1+ c))))' echo " ]" echo "}" } > "$out"