Initial commit

Add ol-conlang.el and test org file to repository
This commit is contained in:
Lucien Cartier-Tilet 2022-04-09 00:20:33 +02:00
commit 98500cb6d2
Signed by: phundrak
GPG Key ID: BD7789E705CB8DCA
2 changed files with 133 additions and 0 deletions

98
ol-conlang.el Normal file
View File

@ -0,0 +1,98 @@
;;; ol-conlang.el --- Links for conlang dictionaries -*- lexical-binding: t -*-
;; Author: Lucien Cartier-Tilet <lucien@phundrak.com>
;; Maintainer: Lucien Cartier-Tilet <lucien@phundrak.com>
;; 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 <https://www.gnu.org/licenses/>.
;;; 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 "<a href=\"/dictionary/%s\">%s</a>"
(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

35
test.org Normal file
View File

@ -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: