This repository has been archived on 2020-12-27. You can view files and clone it, but cannot push or open issues or pull requests.
conlang-layer/funcs.el

217 lines
10 KiB
EmacsLisp
Raw Normal View History

2019-07-21 14:48:11 +00:00
;;; 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
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; 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 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
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)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Mattér ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2019-08-13 14:39:23 +00:00
(setq conlanging//matter-latin-to-runes '((", *" . "")
("\\. *" . "")
2019-08-13 14:39:23 +00:00
(" +" . "")
("ċ" . "")
("ch" . "")
("ae" . "")
("æ" . "")
("dh" . "")
("z" . "")
("ð" . "")
("th" . "")
("s" . "")
("þ" . "")
("w" . "")
2019-08-13 14:39:23 +00:00
("ƿ" . "")
("g" . "")
("" . "")
("ea" . "")
("f" . "")
("u" . "")
("o" . "")
("r" . "")
("c" . "")
("h" . "")
("n" . "")
("i" . "")
("j" . "")
2019-08-13 14:39:23 +00:00
("p" . "")
("v" . "")
2019-08-13 14:39:23 +00:00
("t" . "")
("b" . "")
("e" . "")
("m" . "")
("l" . "")
("d" . "")
("é" . "")
("a" . "")
("y" . "")))
(setq conlanging//matter-latin-to-native '((" +" . " ")
("ch" . "ċ")
("ae" . "æ")
("th" . "þ")
2019-08-13 14:39:23 +00:00
("s" . "þ")
("dh" . "ð")
2019-08-13 14:39:23 +00:00
("z" . "ð")
("w" . "ƿ")
("j" . "i")))
2019-08-13 14:39:23 +00:00
(setq conlanging//matter-latin-to-latex '((", *" . ":")
("\\. *" . "*")
(" +" . ".")
("ch" . "I")
("ċ" . "I")
("ae" . "æ")
("ea" . "\\\\ea")
("ƿ" . "w")
("dh" . "s")
("z" . "s")
("ð" . "s")
("th" . "þ")
("s" . "þ")
("v" . "\\\\ng")
("é " . "\\\\oe")))
(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 transliterated Mattér 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 ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq conlanging//eittlanda-latin-to-latex '((", *" . "\\\\tripledot")
("\\. *" . "\\\\tripledot")
2019-08-13 14:39:23 +00:00
(" +" . ":")
2019-09-11 18:00:36 +00:00
("hv" . "x")
2019-08-13 14:39:23 +00:00
("ø" . "\\\\o")
2019-09-12 17:12:27 +00:00
("œ" . "\\\\oO")
("v" . "w")
2019-08-13 14:39:23 +00:00
("ó" . "v")
("ń" . "\\\\ndot")))
(setq conlanging//eittlanda-latin-to-runes '((", *" . "")
("\\. *" . "")
2019-08-13 14:39:23 +00:00
(" +" . "")
(":" . "")
2019-09-11 18:00:36 +00:00
("hv" . "")
2019-08-13 14:39:23 +00:00
("i" . "")
("y" . "")
("u" . "")
("e" . "")
("ø" . "")
("o" . "")
2019-09-12 17:12:27 +00:00
("œ" . "")
2019-08-13 14:39:23 +00:00
("ó" . "")
("æ" . "")
("a" . "")
("m" . "")
("n" . "")
("ń" . "")
("p" . "")
("b" . "")
("t" . "")
("d" . "")
("k" . "")
("g" . "")
("f" . "")
("þ" . "")
("ð" . "")
("s" . "")
("h" . "")
("v" . "")
2019-08-13 14:39:23 +00:00
("r" . "")
("l" . "")))
2019-07-21 14:48:11 +00:00
(defun conlanging/eittlanda-to-runes ()
"Replaces transliterated Eittlandic with its runic writing system"
(interactive)
(conlanging//replace-char-by-table conlanging//eittlanda-latin-to-runes))
2019-07-21 14:48:11 +00:00
(defun conlanging/eittlanda-to-latex ()
"Replaces transliterated Eittlandic with its corresponding runes"
2019-08-13 14:39:23 +00:00
(interactive)
(conlanging//replace-char-by-table conlanging//eittlanda-latin-to-latex))
2019-08-13 14:39:23 +00:00
(defun conlanging/eittlanda-org-export-runes (text)
"Replaces transliterated Eittlandic with its corresponding
runes during org-mode export"
2019-07-21 14:48:11 +00:00
(interactive)
2019-08-13 14:39:23 +00:00
(if (org-export-derived-backend-p org-export-current-backend
'latex)
(concat "\\textarm{"
(conlanging//replace-string-by-char text conlanging//eittlanda-latin-to-latex)
2019-08-13 14:39:23 +00:00
"}")
(conlanging//replace-string-by-char text conlanging//eittlanda-latin-to-runes)))