Updated naming convention

Arguments are now preceded by the prefix `t-`
This commit is contained in:
Lucien Cartier-Tilet 2020-03-25 12:21:20 +01:00
parent 81fc628935
commit ea9637ff5a
Signed by: phundrak
GPG Key ID: BD7789E705CB8DCA

188
funcs.el
View File

@ -12,46 +12,46 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Tree ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun conlanging//declare-node (node-text 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
~node-generation~, and it will bear the label ~node-text~."
(format "%d[label=\"%s\"];" node-generation
node-text))
(format "%d[label=\"%s\"];" t-node-generation
t-node-text))
(defun conlanging/tree-to-dot (tree &optional current-generation previous-generation)
"Translates an Elisp tree with any number of children per node
(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:
- `tree': tree to convert
- `current-generation': generation number, incremented when
- `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.
- `previous-generation': generation number from previous named
- `t-previous-generation': generation number from previous named
node"
(cond
((null previous-generation) ;; first call
((null t-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)
(conlanging//declare-node (car t-tree) 0)
(conlanging/tree-to-dot (cdr t-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)
((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 previous-generation) " -- "
(number-to-string current-generation) ";")
(conlanging/tree-to-dot (cdr tree)
(concat (number-to-string t-previous-generation) " -- "
(number-to-string t-current-generation) ";")
(conlanging/tree-to-dot (cdr t-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)))))
(* 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)))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Common ;
@ -79,7 +79,7 @@ none the word the cursor is over"
boundary-word
(cons beg end))))
(defun conlanging//replace-char-by-table (correspondance-table)
(defun conlanging//replace-char-by-table (t-correspondance-table)
"Replaces selected texts 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
@ -92,20 +92,20 @@ with."
(buffer-substring-no-properties beg end))
(setq-local regionp
(conlanging//replace-string-by-char regionp
correspondance-table))
t-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)))
(defun conlanging//find-elem-in-list (t-elem t-list)
"In a t-list containing lists, returns the element of `t-list'
whose first element equals `t-elem'"
(if t-list
(if (string= (caar t-list)
t-elem)
(car t-list)
(conlanging//find-elem-in-list t-elem
(cdr t-list)))
nil))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -203,16 +203,16 @@ latin writing system"
(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
(defun conlanging/matter-org-export-runes (t-text)
"Replaces the transliterated Mattér `t-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 t-text conlanging//matter-latin-to-latex)
"}")
(conlanging//replace-string-by-char text conlanging//matter-latin-to-runes)))
(conlanging//replace-string-by-char t-text conlanging//matter-latin-to-runes)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Eittlanda ;
@ -277,16 +277,16 @@ Runic LaTeX code equivalent.")
(interactive)
(conlanging//replace-char-by-table conlanging//eittlanda-latin-to-latex))
(defun conlanging/eittlanda-org-export-runes (text)
(defun conlanging/eittlanda-org-export-runes (t-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 t-text conlanging//eittlanda-latin-to-latex)
"}")
(conlanging//replace-string-by-char text conlanging//eittlanda-latin-to-runes)))
(conlanging//replace-string-by-char t-text conlanging//eittlanda-latin-to-runes)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Ñyqy ;
@ -327,77 +327,77 @@ 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-consonant (t-elem)
(nth 1 t-elem))
(defun conlanging//nyqy-is-dorsal (elem)
(nth 2 elem))
(defun conlanging//nyqy-is-dorsal (t-elem)
(nth 2 t-elem))
(defun conlanging//nyqy-get-phoneme (phoneme &optional is-consonant is-dorsal)
"Extracts a phoneme from `phoneme'.
(defun conlanging//nyqy-get-phoneme (t-phoneme &optional t-is-consonant t-is-dorsal)
"Extracts a phoneme from `t-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)))
- `t-phoneme': array from `conlanging//nyqy-phonetics'
- `t-is-consonant': whether `t-phoneme' represents a
consonant (default: `nil')
- `t-is-dorsal': whether `t-phoneme' should be a dorsal
consonant (default: `nil')"
(if t-is-consonant
(if t-is-dorsal
(nth 3 t-phoneme)
(nth 4 t-phoneme))
(nth 2 t-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.
(defun conlanging/nyqy-to-phonetics (t-text &optional t-nyqy t-phonetics t-met-consonant
t-dorsal)
"Returns the phonetics equivalent of the Ñyqy `t-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"
- `t-text': text to convert to phonetics
- `t-nyqy': for internal use only, `t-text' argument but as a
list of characters
- `t-phonetics': for internal use only, result phonetics, array
- `t-met-consonant': for internal use only, `t' if a consonant
has been met previously, `nil' otherwise
- `t-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)
((eq nil t-phonetics) ;; first call to the function
(conlanging/nyqy-to-phonetics t-text
(split-string (downcase t-text)
""
t)
""))
((eq nil nyqy) ;; no more to convert
((eq nil t-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
t-text
t-phonetics
t-text
t-phonetics)))
(t (let* ((cur-char (car t-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
(t-dorsal (if (or t-met-consonant
(not is-consonant))
dorsal
t-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))
(conlanging/nyqy-to-phonetics t-text
(cdr t-nyqy)
(concat t-phonetics
(conlanging//nyqy-get-phoneme cur-phon t t-dorsal))
t
(not dorsal))
(conlanging/nyqy-to-phonetics text
(cdr nyqy)
(concat phonetics
(not t-dorsal))
(conlanging/nyqy-to-phonetics t-text
(cdr t-nyqy)
(concat t-phonetics
(conlanging//nyqy-get-phoneme cur-phon nil))
met-consonant
dorsal))))))
t-met-consonant
t-dorsal))))))