93 lines
4.0 KiB
EmacsLisp
93 lines
4.0 KiB
EmacsLisp
;;; conlanging.el --- Helper functions for conlanging -*- lexical-binding: t -*-
|
|
|
|
;; Author: Lucien Cartier-Tilet
|
|
;; Maintainer: Lucien Cartier-Tilet
|
|
;; Version: 0.1.0
|
|
;; Package-Requires: ((emacs "29") (org "9") (ivy "0.13") (counsel "0.13") (dash "2.19"))
|
|
;; Homepage: https://labs.phundrak.com/phundrak/conlanging.el
|
|
;; Keywords: convenience
|
|
|
|
;; 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.
|
|
;; Actually, it is made only for me. As such, there is no chance to
|
|
;; 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)
|
|
(require 'counsel)
|
|
(require 'ivy)
|
|
(require 'conlanging-graphviz)
|
|
(require 'conlanging-eittlandic)
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
; Vuepress headings ;
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
(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 (downcase heading))
|
|
;; 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))
|
|
(slug (replace-regexp-in-string "ý" "y" slug))
|
|
(slug (replace-regexp-in-string " " "-" slug)))
|
|
`(,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)))))
|
|
|
|
;;;###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)))
|
|
(insert (format "[[file:./%s.md#%s][%s]]" filename slug text))))
|
|
|
|
(provide 'conlanging)
|
|
|
|
;;; conlanging.el ends here
|