Add function for inserting vuepress-compatible in orgmode buffers

This commit is contained in:
Lucien Cartier-Tilet 2023-07-02 01:50:55 +02:00
parent f20fb14f8e
commit 7695bd78b4
Signed by: phundrak
GPG Key ID: BD7789E705CB8DCA

View File

@ -3,7 +3,7 @@
;; Author: Lucien Cartier-Tilet
;; Maintainer: Lucien Cartier-Tilet
;; Version: 0.1.0
;; Package-Requires: ((emacs "24") (org "9") (eieio "1"))
;; Package-Requires: ((emacs "24") (org "9") (ivy "0.13") (counsel "0.13"))
;; Homepage: https://labs.phundrak.com/phundrak/conlanging.el
;; This file is not part of GNU Emacs
@ -38,8 +38,53 @@
;;; Code:
(require 'seq)
(require 'counsel)
(require 'ivy)
(require 'conlanging-graphviz)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; 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#%s][%s]]" filename slug text))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Text transformation ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;