Compare commits

..

9 Commits

3 changed files with 181 additions and 153 deletions

View File

@@ -1,7 +1,9 @@
[[file:https://cdn.rawgit.com/syl20bnr/spacemacs/442d025779da2f62fc86c2082703697714db6514/assets/spacemacs-badge.svg]] [[file:https://cdn.rawgit.com/syl20bnr/spacemacs/442d025779da2f62fc86c2082703697714db6514/assets/spacemacs-badge.svg]]
#+TITLE: Conlanging layer #+TITLE: Conlanging layer
#+author: Lucien “Pundrak” Cartier-Tilet #+AUTHOR: Lucien “Pundrak” Cartier-Tilet
#+PROPERTY: header-args :noweb yes :exports code
#+PROPERTY: header-args:dot :tangle no :exports code
[[img/conlang_flag.png]] [[img/conlang_flag.png]]
@@ -10,16 +12,19 @@
- [[#features][Features]] - [[#features][Features]]
- [[#graphviz-trees][Graphviz trees]] - [[#graphviz-trees][Graphviz trees]]
- [[#install][Install]] - [[#install][Install]]
- [[#key-bindings][Key bindings]] - [[#licence][Licence]]
- [[#documentation][Documentation]]
- [[#functionalities][Functionalities]]
- [[#graphviz-trees-generation][Graphviz trees generation]]
* Description * Description
This layer adds support for conlanging. This layer adds features for conlanging.
** Features ** Features
- Generate graphviz trees based on Elisp trees - Generate graphviz trees based on Elisp trees
- Replace some text by its runic equivalent (supports the Mattér and - Replace some text by its runic equivalent (supports the Mattér and
Eittlandic languages) Eittlandic languages)
- Adds phonetics to Ňyqy text - Adds phonetics to Proto-Ñyqy text
- Provides custom shortcuts - Provides custom shortcuts
** Graphviz trees ** Graphviz trees
@@ -65,9 +70,9 @@
[[file:img/vowels-example.png]] [[file:img/vowels-example.png]]
This example tree is only a binary tree, but a single node can have up to ten This example tree is only a binary tree, but a single node can have up to ten
children. See some examples in the [[https://labs.phundrak.fr/phundrak/langue-phundrak-fr/blob/master/nyqy.org][Ňyqy source file]]. children. See some examples in the [[https://labs.phundrak.com/phundrak/langue-phundrak-fr/blob/master/proto-nyqy.org][Ñyqy source file]].
It is planned to merge [[https://labs.phundrak.fr/phundrak/distinctive-features-chooser][this project]] into this layer in order to facilitate It is planned to merge [[https://labs.phundrak.com/phundrak/distinctive-features-chooser][this project]] into this layer in order to facilitate
the creation of trees based on distinctive features. the creation of trees based on distinctive features.
* Install * Install
@@ -83,18 +88,84 @@
You can then reload your configuration file with ~SPC f e R~, or restart Emacs You can then reload your configuration file with ~SPC f e R~, or restart Emacs
with ~SPC q r~ or ~SPC q R~. with ~SPC q r~ or ~SPC q R~.
* Key bindings * Licence
All the code included in this repository is licensed under the GPLv3 license.
See [[file:LICENCE]].
| Key Binding | Description | * Documentation
|---------------+-------------------------------------------------------------------------| The following is the documentation of the source code of the ~conlanging~
| ~SPC l e l~ | (org-mode only) Translate Einnlandish transliteration into native latin | layer. It is divided in two main parts, describing the two main files of the
| ~SPC l e r~ | (org-mode only) Translate Einnlandish transliteration into runes | layer: ~funcs.el~ and ~keybindings.el~. First of all, lets simply describe
| ~SPC l m L~ | (org-mode only) Translate Mattér transliteration into LaTeX runes | the ~layer.el~ file.
| ~SPC l m l~ | (org-mode only) Translate Mattér transliteration into native latin | #+BEGIN_SRC emacs-lisp :tangle layers.el
| ~SPC l m r~ | (org-mode only) Translate Mattér transliteration into runes | (configuration-layer/declare-layer 'conlanging)
| ~SPC o l e o~ | Open Eittlandic file | #+END_SRC
| ~SPC o l h o~ | Open Hjelp file |
| ~SPC o l m o~ | Open Mattér file | And thats enough for the ~layer.el~ file! Now, onto the ~funcs.el~ file.
| ~SPC o l n o~ | Open Ňyqy file |
| ~SPC o l o~ | Open the conlanging directory | ** Functionalities
| ~SPC o l t o~ | Open Tãso file | :PROPERTIES:
:HEADER-ARGS: :tangle funcs.el
:END:
Here will be detailed the functionalities of the ~conlanging~ layer. It can
be divided in several parts.
*** Graphviz trees generation
As described above, it is possible to create graphviz trees from Elisp trees
made from lists. This feature is coded in two functions: one that creates
the tree itself, and one that generates nodes. The first one that generates
nodes is declared as a private function (actually, its just prefixed with
~conlanging//~ following Spacemacs [[https://www.spacemacs.org/doc/CONVENTIONS.html#spacemacs-core-and-layer][naming convention]]).
#+BEGIN_SRC emacs-lisp
(defun conlanging//declare-node (t-node-text t-node-generation)
"Declares a node in the graphviz source code. The nodes identifier will be
`t-node-generation', and it will bear the label `t-node-text'."
(format "%d[label=\"%s\"];" t-node-generation
t-node-text))
#+END_SRC
This can result in a graphviz node declared like so:
#+BEGIN_SRC dot
231[label="This is a label"];
#+END_SRC
All nodes generated by the function have a unique identifier in the form of
a number, and its content is only defined by its label. By default, the tree
created from the graphviz code gives a tree from top to bottom with the
label not surrounded by anything. Lets declare our whole function:
#+BEGIN_SRC emacs-lisp
(defun conlanging/tree-to-dot (t-tree &optional t-current-generation t-previous-generation)
"Translates an Elisp t-tree with any number of children per node
to a corresponding graphviz file that can be executed from dot.
Arguments:
- `t-tree': t-tree to convert
- `t-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.
- `t-previous-generation': generation number from previous named
node"
(cond
((null t-previous-generation) ;; first call
(concat "graph{graph[dpi=300];node[shape=plaintext];graph[bgcolor=\"transparent\"];"
(conlanging//declare-node (car t-tree) 0)
(conlanging/tree-to-dot (cdr t-tree) 1 0)
"}"))
((null t-tree) "") ;; last call in this branch
((atom (car t-tree)) ;; '("text" () () ()) manage the label
(concat (conlanging//declare-node (car t-tree)
t-current-generation)
;; make link
(concat (number-to-string t-previous-generation) " -- "
(number-to-string t-current-generation) ";")
(conlanging/tree-to-dot (cdr t-tree)
(+ 1
(* 10 t-current-generation))
t-current-generation)))
((listp (car t-tree)) ;; '(() () ()) manage the branches
(concat (conlanging/tree-to-dot (car t-tree) ;; child of current node
t-current-generation
t-previous-generation)
(conlanging/tree-to-dot (cdr t-tree)
(+ 1 t-current-generation)
t-previous-generation)))))
#+END_SRC

126
funcs.el
View File

@@ -1,9 +1,9 @@
;;; funcs.el --- Conlanging Layer functions File for Spacemacs ;;; funcs.el --- Conlanging Layer functions File for Spacemacs
;; ;;
;; Copyright (c) 2019-2020 Lucien Cartier-Tilet ;; Copyright (c) 2018-2020 Lucien Cartier-Tilet
;; ;;
;; Author: Lucien Cartier-Tilet <phundrak@phundrak.fr> ;; Author: Lucien Cartier-Tilet <lucien@phundrak.com>
;; URL: https://github.com/syl20bnr/spacemacs ;; URL: https://labs.phundrak.com/phundrak/conlang-layer
;; ;;
;; This file is not part of GNU Emacs. ;; This file is not part of GNU Emacs.
;; ;;
@@ -14,7 +14,7 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun conlanging//declare-node (t-node-text t-node-generation) (defun conlanging//declare-node (t-node-text t-node-generation)
"Declares a node in the graphviz source code. The nodes identifier will be "Declares a node in the graphviz source code. The nodes identifier will be
~node-generation~, and it will bear the label ~node-text~." `node-generation', and it will bear the label `node-text'."
(format "%d[label=\"%s\"];" t-node-generation (format "%d[label=\"%s\"];" t-node-generation
t-node-text)) t-node-text))
@@ -201,78 +201,75 @@ corresponding runes during org-mode export"
(conlanging//replace-string-by-char t-text conlanging//matter-latin-to-runes))) (conlanging//replace-string-by-char t-text conlanging//matter-latin-to-runes)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Eittlanda ; ; Eittlandic ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defvar conlanging//eittlanda-latin-to-latex '((", *" . "\\\\tripledot") (defvar conlanging//eittlandic-latin-to-latex '((", *\\|\\. *" . "\\\\tripledot")
("\\. *" . "\\\\tripledot")
(" +" . ":") (" +" . ":")
("hv" . "x") ("hv" . "x")
("ø" . "\\\\o") ("í" . "i")
("œ" . "\\\\oO") ("é" . "\\\\e")
("v" . "w") ("ę\\" . "æ")
("ó" . "v") ("ý" . "y")
("ń" . "\\\\ndot")) ("œ" . "ø")
("ú" . "u")
("ó" . "o")
("á\\" . "a")
("j" . "i"))
"Equivalence between the Eittlandic orthography in the Latin "Equivalence between the Eittlandic orthography in the Latin
script and the LaTeX code for the Runic script. The first element script and the LaTeX code for the Runic script. The first element
of a pair is the Latin script orthography, the second is the of a pair is the Latin script orthography, the second is the
Runic LaTeX code equivalent.") Runic LaTeX code equivalent.")
(defvar conlanging//eittlanda-latin-to-runes '((", *" . "") (defvar conlanging//eittlandic-latin-to-runes '((", *\\|\\. *" . "")
("\\. *" . "") (" +\\|:" . "")
(" +" . "")
(":" . "")
("hv" . "") ("hv" . "")
("i" . "") ("i\\\\|j" . "")
("y" . "") ("é" . "")
("u" . "") ("e\\\\" . "")
("e" . "") ("y\\" . "")
("ø" . "") ("ø\\" . "")
("o" . "") ("u\\\\|v\\|w" . "")
("œ" . "") ("o\\" . "")
("ó" . "") ("a\\\\" . "")
("æ" . "")
("a" . "")
("m" . "")
("n" . "")
("ń" . "")
("p" . "") ("p" . "")
("b" . "") ("b" . "")
("f" . "")
("t" . "") ("t" . "")
("d" . "") ("d" . "")
("k" . "")
("g" . "")
("f" . "")
("þ" . "") ("þ" . "")
("ð" . "") ("ð" . "")
("s" . "") ("s" . "")
("k" . "")
("g" . "")
("h" . "") ("h" . "")
("v" . "") ("m" . "")
("n" . "")
("r" . "") ("r" . "")
("l" . "")) ("l" . ""))
"Equivalence between the Eittlandic orthography in the Latin "Equivalence between the Eittlandic orthography in the Latin
script and the Runic script. The first element of a pair is the script and the Runic script. The first element of a pair is the
Latin script orthography, the second is the Runic equivalent.") Latin script orthography, the second is the Runic equivalent.")
(defun conlanging/eittlanda-to-runes () (defun conlanging/eittlandic-to-runes ()
"Replaces transliterated Eittlandic with its runic writing system" "Replaces transliterated Eittlandic with its runic writing system"
(interactive) (interactive)
(conlanging//replace-char-by-table conlanging//eittlanda-latin-to-runes)) (conlanging//replace-char-by-table conlanging//eittlandic-latin-to-runes))
(defun conlanging/eittlanda-to-latex () (defun conlanging/eittlandic-to-latex ()
"Replaces transliterated Eittlandic with its corresponding runes" "Replaces transliterated Eittlandic with its corresponding runes"
(interactive) (interactive)
(conlanging//replace-char-by-table conlanging//eittlanda-latin-to-latex)) (conlanging//replace-char-by-table conlanging//eittlandic-latin-to-latex))
(defun conlanging/eittlanda-org-export-runes (t-text) (defun conlanging/eittlandic-org-export-runes (t-text)
"Replaces transliterated Eittlandic with its corresponding "Replaces transliterated Eittlandic with its corresponding
runes during org-mode export" runes during org-mode export"
(interactive) (interactive)
(if (org-export-derived-backend-p org-export-current-backend (if (org-export-derived-backend-p org-export-current-backend
'latex) 'latex)
(concat "\\textarm{" (concat "\\textarm{"
(conlanging//replace-string-by-char t-text conlanging//eittlanda-latin-to-latex) (conlanging//replace-string-by-char t-text conlanging//eittlandic-latin-to-latex)
"}") "}")
(conlanging//replace-string-by-char t-text conlanging//eittlanda-latin-to-runes))) (conlanging//replace-string-by-char t-text conlanging//eittlandic-latin-to-runes)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Ñyqy ; ; Ñyqy ;
@@ -280,8 +277,8 @@ runes during org-mode export"
(defvar conlanging//nyqy-phonetics '(("q" t t "q" "ħ") (defvar conlanging//nyqy-phonetics '(("q" t t "q" "ħ")
("g" t t "ɢ" "ʢ") ("g" t t "ɢ" "ʢ")
("ñ" t t "ɴ" "m") ("ñ" t t "ɴ" "m")
("c" t t "t͡ʃ" "ɬ") ("c" t t "c" "ɬ")
("j" t t "d͡ʒ" "ɮ") ("j" t t "ɟ" "ɮ")
("w" t t "w" "l") ("w" t t "w" "l")
("p" t nil "χ" "p") ("p" t nil "χ" "p")
("b" t nil "ʁ" "b") ("b" t nil "ʁ" "b")
@@ -293,8 +290,8 @@ runes during org-mode export"
("ú" nil "u") ("ú" nil "u")
("i" nil "ɪ") ("i" nil "ɪ")
("u" nil "ʊ") ("u" nil "ʊ")
("é" nil "ø") ("ø" nil "ø")
("ó" nil "ɤ") ("œ" nil "ɤ")
("e" nil "ɛ") ("e" nil "ɛ")
("o" nil "ɔ") ("o" nil "ɔ")
(" " nil " ") (" " nil " ")
@@ -336,8 +333,7 @@ Arguments:
(defun conlanging/nyqy-to-phonetics (t-text &optional t-nyqy t-phonetics t-met-consonant (defun conlanging/nyqy-to-phonetics (t-text &optional t-nyqy t-phonetics t-met-consonant
t-dorsal) t-dorsal)
"Returns the phonetics equivalent of the Ñyqy `t-text', either "Returns the phonetics equivalent of the Ñyqy `t-text'.
as a tooltip in HTML or plain text for LaTeX exports.
Arguments: Arguments:
- `t-text': text to convert to phonetics - `t-text': text to convert to phonetics
@@ -350,20 +346,18 @@ Arguments:
is required to be dorsal, `nil' otherwise" is required to be dorsal, `nil' otherwise"
(interactive) (interactive)
(cond (cond
((eq nil t-phonetics) ;; first call to the function
;; first call to the function
((eq nil t-phonetics)
(conlanging/nyqy-to-phonetics t-text (conlanging/nyqy-to-phonetics t-text
(split-string (downcase t-text) (split-string (downcase t-text) "" t)
""
t)
"")) ""))
((eq nil t-nyqy) ;; no more to convert
(progn ;; no more to convert
(format (concat "@@html:<span class=\"tooltip\"><i>%s</i><span class=\"tooltiptext\">/%s/</span></span>@@" ((eq nil t-nyqy)
"@@latex:\\textit{%s} (/%s/)@@") t-phonetics)
t-text
t-phonetics ;; default option
t-text
t-phonetics)))
(t (let* ((cur-char (car t-nyqy)) ;; default option (t (let* ((cur-char (car t-nyqy)) ;; default option
(cur-phon (seq-find (lambda (elt) (cur-phon (seq-find (lambda (elt)
(string= (car elt) (string= (car elt)
@@ -387,3 +381,19 @@ Arguments:
(conlanging//nyqy-get-phoneme cur-phon nil)) (conlanging//nyqy-get-phoneme cur-phon nil))
t-met-consonant t-met-consonant
t-dorsal)))))) t-dorsal))))))
(defun conlanging/nyqy-to-org (t-text)
"Returns the phonetics equivalent of the Ñygy `t-text' properly
formatted for org so it gets exported as a tooltip in HTML or as
LaTeX code for LaTeX exports.
Arguments:
- `t-text': text to convert to phonetics"
(let ((phonetics (conlanging/nyqy-to-phonetics t-text))
(text t-text))
(format (concat "@@html:<span class=\"tooltip\"><i>%s</i><span class=\"tooltiptext\">/%s/</span></span>@@"
"@@latex:\\textit{%s} (/%s/)@@")
text
phonetics
text
phonetics)))

View File

@@ -1,72 +1,19 @@
;;; packages.el --- conlanging layer packages file for Spacemacs. ;;; keybindings.el --- conlanging layer packages file for Spacemacs.
;; ;;
;; Copyright (c) 2012-2018 Sylvain Benner & Contributors ;; Copyright (c) 2018-2020 Lucien Cartier-Tilet
;; ;;
;; Author: Lucien Cartier-Tilet <phundrak@phundrak.fr> ;; Author: Lucien Cartier-Tilet <lucien@phundrak.com>
;; URL: https://github.com/syl20bnr/spacemacs ;; URL: https://labs.phundrak.com/phundrak/conlang-layer
;; ;;
;; This file is not part of GNU Emacs. ;; This file is not part of GNU Emacs.
;; ;;
;;; License: GPLv3 ;;; License: GPLv3
(spacemacs/declare-prefix "ol" "conlanging") (spacemacs/set-leader-keys-for-major-mode 'org-mode
(spacemacs/declare-prefix "olh" "Hjelp") "ler" 'conlanging/eittlanda-to-runes
(spacemacs/declare-prefix "olho" "hjelp.org") "lel" 'conlanging/eittlanda-to-latex
(spacemacs/declare-prefix "olm" "Mattér") "lmr" 'conlanging/matter-to-runes
(spacemacs/declare-prefix "olmo" "matter.org") "lml" 'conlanging/matter-to-native-latin
(spacemacs/declare-prefix "ole" "Einnlanda")
(spacemacs/declare-prefix "oleo" "eittlanda.org")
(spacemacs/declare-prefix "oln" "Ñyqy")
(spacemacs/declare-prefix "olno" "nyqy.org")
(spacemacs/declare-prefix "olne" "nyqy.org (English)")
(spacemacs/declare-prefix "olo" "Conlang directory")
(spacemacs/declare-prefix "olO" "Conlang root directory")
(spacemacs/declare-prefix "olt" "Tãso")
(spacemacs/declare-prefix "olto" "taso.org")
(spacemacs/declare-prefix-for-mode 'org-mode
"ml" "conlanging")
(spacemacs/declare-prefix-for-mode 'org-mode
"mle" "Eittlanda")
(spacemacs/declare-prefix-for-mode 'org-mode
"mlm" "Mattér")
(spacemacs/set-leader-keys "oleo"
(lambda ()
(interactive)
(find-file "~/Documents/conlanging/web/eittland.org"))
"olho"
(lambda ()
(interactive)
(find-file "~/Documents/conlanging/web/hjelp.org"))
"olmo"
(lambda ()
(interactive)
(find-file "~/Documents/conlanging/web/matter.org"))
"olno"
(lambda ()
(interactive)
(find-file "~/Documents/conlanging/web/nyqy.org"))
"olne"
(lambda ()
(interactive)
(find-file "~/Documents/conlanging/web/en/nyqy.org"))
"olO"
(lambda ()
(interactive)
(dired "~/Documents/conlanging"))
"olo"
(lambda ()
(interactive)
(dired "~/Documents/conlanging/web"))
"olto"
(lambda ()
(interactive)
(find-file "~/Documents/conlanging/web/taso.org")))
(spacemacs/set-leader-keys-for-major-mode
'org-mode "ler" 'conlanging/eittlanda-to-runes
"lel" 'conlanging/eittlanda-to-latex "lmr"
'conlanging/matter-to-runes "lml" 'conlanging/matter-to-native-latin
"lmL" 'conlanging/matter-to-latex) "lmL" 'conlanging/matter-to-latex)
;;; keybindings.el ends here ;;; keybindings.el ends here