commit 98500cb6d22ec15028e2fe8c7e7517a2bc39c6ea Author: Lucien Cartier-Tilet Date: Sat Apr 9 00:20:33 2022 +0200 Initial commit Add ol-conlang.el and test org file to repository diff --git a/ol-conlang.el b/ol-conlang.el new file mode 100644 index 0000000..cc2dc53 --- /dev/null +++ b/ol-conlang.el @@ -0,0 +1,98 @@ +;;; ol-conlang.el --- Links for conlang dictionaries -*- lexical-binding: t -*- + +;; Author: Lucien Cartier-Tilet +;; Maintainer: Lucien Cartier-Tilet +;; Version: 0.1.0 +;; Package-Requires: ((emacs "26") (org "9.5")) +;; Homepage: https://labs.phundrak.com/phundrak/ol-conlang +;; Keywords: outlines + + +;; 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 . + + +;;; Commentary: + +;; commentary + +;;; Code: + +(require 'org) +(require 'ol) +(require 'org-element) + +(defun org-link-conlang-open (path arg) + "Open a conlang dictionary link. +PATH is the path to a word or a language, as a string." + (let* ((destructured-path (split-string path ":")) + (language (car destructured-path)) + (word (cadr destructured-path)) + (match (org-find-property "language" language))) + (if (not match) + (error "No match for language: %s" language) + (goto-char match) + (when word + (let (pos) + (org-map-entries (lambda () + (let ((elem (org-element-property :WORD (org-element-at-point))) + (word-pos (plist-get (cadr (org-element-at-point)) :begin))) + (when (string= elem word) + (setf pos word-pos)))) + (org-re-property "word" word) + 'tree) + (goto-char pos)))))) + +(defun org-link-conlang-export (path desc backend info) + "Export a conlang dictionary type link. +PATH leads either to a language or to a word of a language. DESC +is the description of the link, or nil. BACKEND is a symbol +representing the packend used for export. INFO is a plist +containing the export paramenters." + (let* ((destructured-path (split-string path ":")) + (language (car destructured-path)) + (word (cadr destructured-path)) + (generic-uri (if word (concat language "-" word) language))) + (pcase backend + (`html + (format "%s" + (if word + (concat language "/" word) + language) + (or word language))) + (`latex + (if desc + (format "\\href{%s}{%s}" generic-uri desc) + (format "\\url{%s}" generic-uri))) + (`ascii + (if (not desc) + (format "<%s>" generic-uri) + (concat (format "[%s]" desc) + (and (not (plist-get info :ascii-links-to-notes)) + (format " (<%s>)" generic-uri))))) + (`texinfo + (if (not desc) + (format "@uref{%s}" generic-uri) + (format "@urif{%s, %s}" generic-uri desc))) + (_ generic-uri)))) + +(org-link-set-parameters "conlang" + :follow #'org-link-conlang-open + :export #'org-link-conlang-export) + +(provide 'org-link-conlang) +(provide 'ol-conlang) + +;;; ol-conlang.el ends here diff --git a/test.org b/test.org new file mode 100644 index 0000000..251670e --- /dev/null +++ b/test.org @@ -0,0 +1,35 @@ +A direct link to [[condict:English][English]] and another to [[condict:Mbabaram][Mbabaram]]. + +* English +:PROPERTIES: +:language: english +:END: +** chair +:PROPERTIES: +:word: chair +:END: + +** dog +:PROPERTIES: +:word: dog +:END: +Not to be mistaken with [[condict:Mbabaram:dog][dog (Mbabaram)]] + +** phone +:PROPERTIES: +:word: phone +:END: + +* Mbabaram +:PROPERTIES: +:language: mbabaram +:END: +** dog +:PROPERTIES: +:word: dog +:END: +Not to be mistaken with [[condict:English:dog][dog (English)]] +** gug +:PROPERTIES: +:word: gug +:END: