2021-06-01 01:17:03 +02:00
|
|
|
;;; conlanging.el --- Helper functions for conlanging -*- lexical-binding: t -*-
|
|
|
|
|
|
|
|
;; Author: Lucien Cartier-Tilet
|
|
|
|
;; Maintainer: Lucien Cartier-Tilet
|
|
|
|
;; Version: 0.1.0
|
2024-09-14 14:03:40 +02:00
|
|
|
;; Package-Requires: ((emacs "29") (org "9") (ivy "0.13") (counsel "0.13") (dash "2.19") (s "1.13"))
|
2021-06-01 01:17:03 +02:00
|
|
|
;; Homepage: https://labs.phundrak.com/phundrak/conlanging.el
|
2024-09-12 23:12:45 +02:00
|
|
|
;; Keywords: convenience
|
2021-06-01 01:17:03 +02:00
|
|
|
|
|
|
|
;; This file is not part of GNU Emacs
|
|
|
|
|
|
|
|
;; This program is free software: you can redistribute it and/or modify
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
|
|
|
|
|
|
|
;; This program is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
|
|
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
;; This package is not made in order to be used by a lot of people.
|
2024-09-12 23:12:45 +02:00
|
|
|
;; Actually, it is made only for me. As such, there is no chance to
|
2021-06-01 01:17:03 +02:00
|
|
|
;; find it on any ELPA or MELPA.
|
|
|
|
;;
|
|
|
|
;; Functions and variables in this package are just helpers for myself
|
|
|
|
;; in order to write more easily the documentation on my conlangs.
|
|
|
|
;; This includes stuff such as automatic generation of text in
|
|
|
|
;; non-latin scripts or LaTeX-specific text from transliterated text,
|
|
|
|
;; graphviz trees for some stuff like syntax and feature trees, and
|
|
|
|
;; finally functions for creating automatic phonetics of a language a
|
|
|
|
;; tad complex when it comes to its pronunciation.
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
(require 'seq)
|
2023-07-02 01:50:55 +02:00
|
|
|
(require 'counsel)
|
|
|
|
(require 'ivy)
|
2023-05-26 13:36:03 +02:00
|
|
|
(require 'conlanging-graphviz)
|
2024-09-12 22:48:14 +02:00
|
|
|
(require 'conlanging-eittlandic)
|
2024-09-21 16:13:40 +02:00
|
|
|
(require 'org)
|
2021-06-01 01:17:03 +02:00
|
|
|
|
2023-07-02 01:50:55 +02:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
; Vuepress headings ;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
2024-09-21 16:07:15 +02:00
|
|
|
(defun conlanging--slugify (str)
|
|
|
|
"Slugify STR."
|
|
|
|
(let* ((slug (downcase str))
|
2023-07-02 01:50:55 +02:00
|
|
|
;; only keep alphanumeric characters
|
|
|
|
(slug (replace-regexp-in-string "[^[:alnum:]]+" " " slug))
|
|
|
|
(slug (string-trim slug))
|
|
|
|
(slug (replace-regexp-in-string "[[:space:]]+" " " slug))
|
|
|
|
;; stripping diacritics off of characters
|
|
|
|
(slug (replace-regexp-in-string "[àáâäåā]" "a" slug))
|
|
|
|
(slug (replace-regexp-in-string "ç" "c" slug))
|
|
|
|
(slug (replace-regexp-in-string "[èéêë]" "e" slug))
|
|
|
|
(slug (replace-regexp-in-string "[íìîï]" "i" slug))
|
|
|
|
(slug (replace-regexp-in-string "[óòōôö]" "o" slug))
|
|
|
|
(slug (replace-regexp-in-string "[ńǹñ]" "n" slug))
|
|
|
|
(slug (replace-regexp-in-string "[úùûü]" "u" slug))
|
2024-09-21 16:07:15 +02:00
|
|
|
(slug (replace-regexp-in-string "ý" "y" slug)))
|
|
|
|
(replace-regexp-in-string " " "-" slug)))
|
|
|
|
|
|
|
|
(defun conlanging--get-heading-slug ()
|
|
|
|
"Select and return a heading and its slug."
|
|
|
|
(let* ((settings (cdr (assq major-mode counsel-outline-settings)))
|
|
|
|
(heading (substring-no-properties (ivy-read "Heading: " (counsel-outline-candidates settings)
|
|
|
|
:preselect (max (1- counsel-outline--preselect) 0))))
|
|
|
|
;; keep only lowest heading
|
|
|
|
(heading (replace-regexp-in-string "\\`.*/" "" heading))
|
|
|
|
(slug (conlanging--slugify heading)))
|
2023-07-02 01:50:55 +02:00
|
|
|
`(,heading . ,slug)))
|
|
|
|
|
|
|
|
(defun conlanging--get-filename-no-ext ()
|
|
|
|
"Get file name of current buffer without its extension."
|
|
|
|
(file-name-sans-extension (file-name-nondirectory (buffer-file-name (buffer-base-buffer)))))
|
|
|
|
|
2024-09-21 16:07:15 +02:00
|
|
|
;;;###autoload
|
|
|
|
(defun conlanging-store-heading-vuepress ()
|
|
|
|
"Store in kill ring a Vuepress link to current heading."
|
|
|
|
(interactive)
|
|
|
|
(let* ((filename (conlanging--get-filename-no-ext))
|
|
|
|
(heading (nth 4 (org-heading-components)))
|
|
|
|
(slug (conlanging--slugify heading)))
|
|
|
|
(org-link--add-to-stored-links (format "file:./%s.md#%s" filename slug)
|
|
|
|
heading)))
|
|
|
|
|
2023-07-02 01:50:55 +02:00
|
|
|
;;;###autoload
|
|
|
|
(defun conlanging-insert-heading-vuepress ()
|
|
|
|
"Insert vuepress-compatible link to heading."
|
|
|
|
(interactive)
|
|
|
|
(let* ((slug-head (conlanging--get-heading-slug))
|
|
|
|
(heading (car slug-head))
|
|
|
|
(slug (cdr slug-head))
|
|
|
|
(filename (conlanging--get-filename-no-ext))
|
|
|
|
(text (completing-read "Text: " `(,heading) nil nil heading)))
|
2024-09-12 21:09:54 +02:00
|
|
|
(insert (format "[[file:./%s.md#%s][%s]]" filename slug text))))
|
2023-07-02 01:50:55 +02:00
|
|
|
|
2021-06-01 01:17:03 +02:00
|
|
|
(provide 'conlanging)
|
|
|
|
|
|
|
|
;;; conlanging.el ends here
|