Compare commits

..

2 Commits

Author SHA1 Message Date
291e0f055b
feat: add new command conlang-store-heading-vuepress
Some checks failed
CI / build (29.4) (push) Has been cancelled
CI / build (snapshot) (push) Has been cancelled
2024-09-21 16:07:15 +02:00
07afc05210
chore: fix Eask configuration 2024-09-21 16:06:52 +02:00
3 changed files with 28 additions and 10 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
/*.elc
/.eask/
/dist/

1
Eask
View File

@ -11,6 +11,7 @@
(script "test" "echo \"Error: no test specified\" && exit 1")
(source "gnu")
(source "melpa")
(depends-on "emacs" "26.1")
(depends-on "ivy" "0.13")

View File

@ -48,14 +48,9 @@
; 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))
(defun conlanging--slugify (str)
"Slugify STR."
(let* ((slug (downcase str))
;; only keep alphanumeric characters
(slug (replace-regexp-in-string "[^[:alnum:]]+" " " slug))
(slug (string-trim slug))
@ -68,14 +63,33 @@
(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)))
(slug (replace-regexp-in-string "ý" "y" slug)))
(replace-regexp-in-string " " "-" slug)))
(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 (conlanging--slugify heading)))
`(,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-store-heading-vuepress ()
"Store in kill ring a Vuepress link to current heading."
(interactive)
(let* ((filename (conlanging--get-filename-no-ext))
(heading (nth 4 (org-heading-components)))
(slug (conlanging--slugify heading)))
(org-link--add-to-stored-links (format "file:./%s.md#%s" filename slug)
heading)))
;;;###autoload
(defun conlanging-insert-heading-vuepress ()
"Insert vuepress-compatible link to heading."