;;; 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))) (`conlang-md (format "" language (if word (format "word=\"%s\" " word) "") (if desc (format "desc=\"%s\" " 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