404 lines
19 KiB
EmacsLisp
404 lines
19 KiB
EmacsLisp
;;; funcs.el --- Conlanging Layer functions File for Spacemacs
|
||
;;
|
||
;; Copyright (c) 2019-2020 Lucien Cartier-Tilet
|
||
;;
|
||
;; Author: Lucien Cartier-Tilet <phundrak@phundrak.fr>
|
||
;; URL: https://github.com/syl20bnr/spacemacs
|
||
;;
|
||
;; This file is not part of GNU Emacs.
|
||
;;
|
||
;;; License: GPLv3
|
||
|
||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||
; Tree ;
|
||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||
(defun conlanging//declare-node (node-text node-generation)
|
||
"Declares a node in the graphviz source code. The node’s identifier will be
|
||
~node-generation~, and it will bear the label ~node-text~."
|
||
(format "%d[label=\"%s\"];" node-generation
|
||
node-text))
|
||
|
||
(defun conlanging/tree-to-dot (tree &optional current-generation previous-generation)
|
||
"Translates an Elisp tree with any number of children per node
|
||
to a corresponding graphviz file that can be executed from dot.
|
||
Arguments:
|
||
- `tree': tree to convert
|
||
- `current-generation': generation number, incremented when
|
||
changing from a node to another node from the same generation,
|
||
multiplied by 10 when going from a node to one of its children.
|
||
- `previous-generation': generation number from previous named
|
||
node"
|
||
(cond
|
||
((null previous-generation) ;; first call
|
||
(concat "graph{graph[dpi=300];node[shape=plaintext];graph[bgcolor=\"transparent\"];"
|
||
(conlanging//declare-node (car tree) 0)
|
||
(conlanging/tree-to-dot (cdr tree) 1 0)
|
||
"}"))
|
||
((null tree) "") ;; last call in this branch
|
||
((atom (car tree)) ;; '("text" () () ()) manage the label
|
||
(concat (conlanging//declare-node (car tree)
|
||
current-generation)
|
||
;; make link
|
||
(concat (number-to-string previous-generation) " -- "
|
||
(number-to-string current-generation) ";")
|
||
(conlanging/tree-to-dot (cdr tree)
|
||
(+ 1
|
||
(* 10 current-generation))
|
||
current-generation)))
|
||
((listp (car tree)) ;; '(() () ()) manage the branches
|
||
(concat (conlanging/tree-to-dot (car tree) ;; child of current node
|
||
current-generation
|
||
previous-generation)
|
||
(conlanging/tree-to-dot (cdr tree)
|
||
(+ 1 current-generation)
|
||
previous-generation)))))
|
||
|
||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||
; Common ;
|
||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||
(defun conlanging//replace-string-by-char (t-string t-correspondance-table)
|
||
"Return a copy of t-string converted with the correspondance
|
||
table"
|
||
(interactive)
|
||
(while t-correspondance-table
|
||
(let ((cur-from-char (car (car t-correspondance-table)))
|
||
(cur-to-char (cdr (car t-correspondance-table))))
|
||
(setq t-string (replace-regexp-in-string cur-from-char cur-to-char
|
||
t-string))
|
||
(setq t-correspondance-table (cdr t-correspondance-table))))
|
||
t-string)
|
||
|
||
(defun conlanging//get-boundary ()
|
||
"Get the boundary of either the selected region, or if there is
|
||
none the word the cursor is over"
|
||
(interactive)
|
||
(let* ((beg (region-beginning))
|
||
(end (region-end))
|
||
(boundary-word (bounds-of-thing-at-point 'word)))
|
||
(if (= beg end)
|
||
boundary-word
|
||
(cons beg end))))
|
||
|
||
(defun conlanging//replace-char-by-table (correspondance-table)
|
||
"Replaces selected text’s strings according to the table passed
|
||
as argument. The table is a list of pairs, the first element of
|
||
the pair is a regex to be searched in the selected text and the
|
||
second element of the pair the string it has to be replaced
|
||
with."
|
||
(let* ((cur-boundary (conlanging//get-boundary))
|
||
(beg (car cur-boundary))
|
||
(end (cdr cur-boundary)))
|
||
(setq-local regionp
|
||
(buffer-substring-no-properties beg end))
|
||
(setq-local regionp
|
||
(conlanging//replace-string-by-char regionp
|
||
correspondance-table))
|
||
(delete-region beg end)
|
||
(goto-char beg)
|
||
(insert regionp)))
|
||
|
||
(defun conlanging//find-elem-in-list (elem list)
|
||
"In a list containing lists, returns the element of `list'
|
||
whose first element equals `elem'"
|
||
(if list
|
||
(if (string= (caar list)
|
||
elem)
|
||
(car list)
|
||
(conlanging//find-elem-in-list elem
|
||
(cdr list)))
|
||
nil))
|
||
|
||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||
; Mattér ;
|
||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||
(defvar conlanging//matter-latin-to-runes '((", *" . "᛬")
|
||
("\\. *" . "᛭")
|
||
(" +" . "᛫")
|
||
("ċ" . "ᛇ")
|
||
("ch" . "ᛇ")
|
||
("ae" . "ᚫ")
|
||
("æ" . "ᚫ")
|
||
("dh" . "ᛋ")
|
||
("z" . "ᛋ")
|
||
("ð" . "ᛋ")
|
||
("th" . "ᚦ")
|
||
("s" . "ᚦ")
|
||
("þ" . "ᚦ")
|
||
("w" . "ᚹ")
|
||
("ƿ" . "ᚹ")
|
||
("g" . "ᚷ")
|
||
("ᵹ" . "ᚷ")
|
||
("ea" . "ᛠ")
|
||
("f" . "ᚠ")
|
||
("u" . "ᚢ")
|
||
("o" . "ᚩ")
|
||
("r" . "ᚱ")
|
||
("c" . "ᚳ")
|
||
("h" . "ᚻ")
|
||
("n" . "ᚾ")
|
||
("i" . "ᛁ")
|
||
("j" . "ᛄ")
|
||
("p" . "ᛈ")
|
||
("v" . "ᛝ")
|
||
("t" . "ᛏ")
|
||
("b" . "ᛒ")
|
||
("e" . "ᛖ")
|
||
("m" . "ᛗ")
|
||
("l" . "ᛚ")
|
||
("d" . "ᛞ")
|
||
("é" . "ᛟ")
|
||
("a" . "ᚪ")
|
||
("y" . "ᚣ"))
|
||
"Equivalence between the Mattér orthography in the Latin script
|
||
and the Runic script. The first element of a pair is the Latin
|
||
script orthography, the second is the Runic equivalent.")
|
||
|
||
(defvar conlanging//matter-latin-to-native '((" +" . " ")
|
||
("ch" . "ċ")
|
||
("ae" . "æ")
|
||
("th" . "þ")
|
||
("s" . "þ")
|
||
("dh" . "ð")
|
||
("z" . "ð")
|
||
("w" . "ƿ")
|
||
("j" . "i"))
|
||
"Equivalence between the Mattér orthography in its native Latin
|
||
script and the transliterated Mattér Latin script. The first
|
||
element of a pair is the transliterated Latin script orthography,
|
||
the second is the native Latin script equivalent.")
|
||
|
||
(defvar conlanging//matter-latin-to-latex '((", *" . ":")
|
||
("\\. *" . "*")
|
||
(" +" . ".")
|
||
("ch" . "I")
|
||
("ċ" . "I")
|
||
("ae" . "æ")
|
||
("ea" . "\\\\ea")
|
||
("ƿ" . "w")
|
||
("dh" . "s")
|
||
("z" . "s")
|
||
("ð" . "s")
|
||
("th" . "þ")
|
||
("s" . "þ")
|
||
("v" . "\\\\ng")
|
||
("é " . "\\\\oe"))
|
||
"Equivalence between the Mattér orthography in the Latin script
|
||
and the LaTeX code for the Runic script. The first element of a
|
||
pair is the Latin script orthography, the second is the Runic
|
||
LaTeX code equivalent.")
|
||
|
||
(defun conlanging/matter-to-runes ()
|
||
"Replaces transliterated Mattér with its runic writing system"
|
||
(interactive)
|
||
(conlanging//replace-char-by-table conlanging//matter-latin-to-runes))
|
||
|
||
(defun conlanging/matter-to-native-latin ()
|
||
"Replaces transliterated Mattér with its corresponding native
|
||
latin writing system"
|
||
(interactive)
|
||
(conlanging//replace-char-by-table conlanging//matter-latin-to-native))
|
||
|
||
(defun conlanging/matter-to-latex ()
|
||
"Replaces transliterated Mattér with its corresponding runes"
|
||
(interactive)
|
||
(conlanging//replace-char-by-table conlanging//matter-latin-to-latex))
|
||
|
||
(defun conlanging/matter-org-export-runes (text)
|
||
"Replaces the transliterated Mattér `text' with its
|
||
corresponding runes during org-mode export"
|
||
(interactive)
|
||
(if (org-export-derived-backend-p org-export-current-backend
|
||
'latex)
|
||
(concat "\\textarm{"
|
||
(conlanging//replace-string-by-char text conlanging//matter-latin-to-latex)
|
||
"}")
|
||
(conlanging//replace-string-by-char text conlanging//matter-latin-to-runes)))
|
||
|
||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||
; Eittlanda ;
|
||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||
(defvar conlanging//eittlanda-latin-to-latex '((", *" . "\\\\tripledot")
|
||
("\\. *" . "\\\\tripledot")
|
||
(" +" . ":")
|
||
("hv" . "x")
|
||
("ø" . "\\\\o")
|
||
("œ" . "\\\\oO")
|
||
("v" . "w")
|
||
("ó" . "v")
|
||
("ń" . "\\\\ndot"))
|
||
"Equivalence between the Eittlandic orthography in the Latin
|
||
script and the LaTeX code for the Runic script. The first element
|
||
of a pair is the Latin script orthography, the second is the
|
||
Runic LaTeX code equivalent.")
|
||
|
||
(defvar conlanging//eittlanda-latin-to-runes '((", *" . "⁝")
|
||
("\\. *" . "⁝")
|
||
(" +" . "᛬")
|
||
(":" . "᛬")
|
||
("hv" . "ᛪ")
|
||
("i" . "ᛁ")
|
||
("y" . "ᛦ")
|
||
("u" . "ᚢ")
|
||
("e" . "ᛂ")
|
||
("ø" . "ᚯ")
|
||
("o" . "ᚮ")
|
||
("œ" . "ᚰ")
|
||
("ó" . "ᚤ")
|
||
("æ" . "ᛅ")
|
||
("a" . "ᛆ")
|
||
("m" . "ᛘ")
|
||
("n" . "ᚾ")
|
||
("ń" . "ᛀ")
|
||
("p" . "ᛔ")
|
||
("b" . "ᛒ")
|
||
("t" . "ᛐ")
|
||
("d" . "ᛑ")
|
||
("k" . "ᚴ")
|
||
("g" . "ᚵ")
|
||
("f" . "ᚠ")
|
||
("þ" . "ᚦ")
|
||
("ð" . "ᚧ")
|
||
("s" . "ᛋ")
|
||
("h" . "ᚼ")
|
||
("v" . "ᚥ")
|
||
("r" . "ᚱ")
|
||
("l" . "ᛚ"))
|
||
"Equivalence between the Eittlandic orthography in the Latin
|
||
script and the Runic script. The first element of a pair is the
|
||
Latin script orthography, the second is the Runic equivalent.")
|
||
|
||
(defun conlanging/eittlanda-to-runes ()
|
||
"Replaces transliterated Eittlandic with its runic writing system"
|
||
(interactive)
|
||
(conlanging//replace-char-by-table conlanging//eittlanda-latin-to-runes))
|
||
|
||
(defun conlanging/eittlanda-to-latex ()
|
||
"Replaces transliterated Eittlandic with its corresponding runes"
|
||
(interactive)
|
||
(conlanging//replace-char-by-table conlanging//eittlanda-latin-to-latex))
|
||
|
||
(defun conlanging/eittlanda-org-export-runes (text)
|
||
"Replaces transliterated Eittlandic with its corresponding
|
||
runes during org-mode export"
|
||
(interactive)
|
||
(if (org-export-derived-backend-p org-export-current-backend
|
||
'latex)
|
||
(concat "\\textarm{"
|
||
(conlanging//replace-string-by-char text conlanging//eittlanda-latin-to-latex)
|
||
"}")
|
||
(conlanging//replace-string-by-char text conlanging//eittlanda-latin-to-runes)))
|
||
|
||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||
; Ñyqy ;
|
||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||
(defvar conlanging//nyqy-phonetics '(("q" t t "q" "ħ")
|
||
("g" t t "ɢ" "ʢ")
|
||
("ñ" t t "ɴ" "m")
|
||
("c" t t "t͡ʃ" "ɬ")
|
||
("j" t t "d͡ʒ" "ɮ")
|
||
("w" t t "w" "l")
|
||
("p" t nil "χ" "p")
|
||
("b" t nil "ʁ" "b")
|
||
("m" t nil "ʀ" "m")
|
||
("n" t nil "j" "n")
|
||
("s" t nil "x" "s")
|
||
("z" t nil "ɣ" "z")
|
||
("y" nil "y")
|
||
("ú" nil "u")
|
||
("i" nil "ɪ")
|
||
("u" nil "ʊ")
|
||
("é" nil "ø")
|
||
("ó" nil "ɤ")
|
||
("e" nil "ɛ")
|
||
("o" nil "ɔ")
|
||
(" " nil " ")
|
||
("," nil " ")
|
||
(";" nil " ")
|
||
("." nil " "))
|
||
"List of Ñyqy characters and their phonetics equivalent.
|
||
|
||
The first value is the translitteration of a sound in Ñyqy. The
|
||
second is whether or not it represents a consonant.
|
||
|
||
If it is a consonant, then the third value is whether it is a
|
||
dorsal consonant by default or not. Then we have the consonant's
|
||
dorsal prononciation and its non-dorsal pronunciation.
|
||
|
||
If it is not a consonant, then the third value is its
|
||
pronunciation already.")
|
||
|
||
(defun conlanging//nyqy-is-consonant (elem)
|
||
(nth 1 elem))
|
||
|
||
(defun conlanging//nyqy-is-dorsal (elem)
|
||
(nth 2 elem))
|
||
|
||
(defun conlanging//nyqy-get-phoneme (phoneme &optional is-consonant is-dorsal)
|
||
"Extracts a phoneme from `phoneme'.
|
||
|
||
Arguments:
|
||
- phoneme: array from `conlanging//nyqy-phonetics'
|
||
- is-consonant: whether `phoneme' represents a
|
||
consonant (default: nil)
|
||
- is-dorsal: whether `phoneme' should be a dorsal
|
||
consonant (default: nil)"
|
||
(if is-consonant
|
||
(if is-dorsal
|
||
(nth 3 phoneme)
|
||
(nth 4 phoneme))
|
||
(nth 2 phoneme)))
|
||
|
||
(defun conlanging/nyqy-to-phonetics (text &optional nyqy phonetics met-consonant
|
||
dorsal)
|
||
"Returns the phonetics equivalent of the Ñyqy `text', either as
|
||
a tooltip in HTML or plain text for LaTeX exports.
|
||
|
||
Arguments:
|
||
- text: text to convert to phonetics
|
||
- nyqy: for internal use only, `text' argument but as a list of
|
||
characters
|
||
- phonetics: for internal use only, result phonetics, array
|
||
- met-consonant: for internal use only, `t' if a consonant has
|
||
been met previously, `nil' otherwise
|
||
- dorsal: for internal use only, `t' if the current consonant is
|
||
required to be dorsal, `nil' otherwise"
|
||
(interactive)
|
||
(cond
|
||
((eq nil phonetics) ;; first call to the function
|
||
(conlanging/nyqy-to-phonetics text
|
||
(split-string (downcase text)
|
||
""
|
||
t)
|
||
""))
|
||
((eq nil nyqy) ;; no more to convert
|
||
(progn
|
||
(format (concat "@@html:<span class=\"tooltip\"><i>%s</i><span class=\"tooltiptext\">/%s/</span></span>@@"
|
||
"@@latex:\\textit{%s} (/%s/)@@")
|
||
text
|
||
phonetics
|
||
text
|
||
phonetics)))
|
||
(t (let* ((cur-char (car nyqy)) ;; default option
|
||
(cur-phon (seq-find (lambda (elt)
|
||
(string= (car elt)
|
||
cur-char))
|
||
conlanging//nyqy-phonetics))
|
||
(is-consonant (conlanging//nyqy-is-consonant cur-phon))
|
||
(dorsal (if (or met-consonant
|
||
(not is-consonant))
|
||
dorsal
|
||
(conlanging//nyqy-is-dorsal cur-phon))))
|
||
(if is-consonant
|
||
(conlanging/nyqy-to-phonetics text
|
||
(cdr nyqy)
|
||
(concat phonetics
|
||
(conlanging//nyqy-get-phoneme cur-phon t dorsal))
|
||
t
|
||
(not dorsal))
|
||
(conlanging/nyqy-to-phonetics text
|
||
(cdr nyqy)
|
||
(concat phonetics
|
||
(conlanging//nyqy-get-phoneme cur-phon nil))
|
||
met-consonant
|
||
dorsal))))))
|