scripts/update-char-fold.sh

b3620724ba167f6d64229f61c4cb5b7612687077
orgstar/scripts/update-char-fold.sh

40 lines · 1528 bytes · executable

 1#!/bin/sh
 2# Writes `char-fold-table` from Emacs to Sources/OrgCore/Keymap/CharFold.swift, for
 3# evil-snipe's `evil-snipe-char-fold`.
 4# Usage: scripts/update-char-fold.sh [emacs]
 5set -eu
 6cd "$(dirname "$0")/.."
 7emacs=${1:-emacs}
 8out=Sources/OrgCore/Keymap/CharFold.swift
 9{
10  echo "// Generated by scripts/update-char-fold.sh from $("$emacs" --version | head -1)."
11  echo
12  echo "extension CharFold {"
13  echo "    /// \`char-fold-table\`: a line per character with an entry, its code point in hex, a tab"
14  echo "    /// and the Emacs regexp it matches."
15  echo "    static let table = \"\"\""
16  "$emacs" -Q --batch --eval '
17(progn
18  (set-language-environment "UTF-8")
19  (require (quote char-fold))
20  (let (rows)
21    (map-char-table
22     (lambda (k v)
23       (when v
24         (dolist (c (if (consp k) (number-sequence (car k) (cdr k)) (list k)))
25           (push (cons c v) rows))))
26     char-fold-table)
27    (setq rows (sort rows (lambda (a b) (< (car a) (car b)))))
28    (dolist (row rows)
29      (princ (format "    %X\t" (car row)))
30      (mapc (lambda (c)
31              (princ (cond ((eq c ?\\) "\\\\")
32                           ((eq c ?\") "\\\"")
33                           ((or (< c 32) (and (/= c 32) (memq (get-char-code-property c (quote general-category)) (quote (Mn Mc Me Cc Cf Co Cn Cs Zl Zp Zs)))))
34                            (format "\\u{%X}" c))
35                           (t (char-to-string c)))))
36            (cdr row))
37      (princ "\n"))))' | iconv -f utf-8 -t utf-8
38  echo "    \"\"\""
39  echo "}"
40} > "$out"
Keyboard shortcuts

Global

⌘K
Command palette & jump
/
Focus search
?
Show this help
g d
Dashboard
g e
Explore repositories
g n
Notifications

Repository & editor

t
Find file in repository
y
Copy immutable SHA permalink
g c
Code tab
g i
Issues tab
g m
Merge requests tab
g b
Builds tab
⌘↵
Submit active form