feat: add new command conlang-store-heading-vuepress
This commit is contained in:
parent
07afc05210
commit
291e0f055b
@ -48,14 +48,9 @@
|
|||||||
; Vuepress headings ;
|
; Vuepress headings ;
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
(defun conlanging--get-heading-slug ()
|
(defun conlanging--slugify (str)
|
||||||
"Select and return a heading and its slug."
|
"Slugify STR."
|
||||||
(let* ((settings (cdr (assq major-mode counsel-outline-settings)))
|
(let* ((slug (downcase str))
|
||||||
(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
|
;; only keep alphanumeric characters
|
||||||
(slug (replace-regexp-in-string "[^[:alnum:]]+" " " slug))
|
(slug (replace-regexp-in-string "[^[:alnum:]]+" " " slug))
|
||||||
(slug (string-trim slug))
|
(slug (string-trim slug))
|
||||||
@ -68,14 +63,33 @@
|
|||||||
(slug (replace-regexp-in-string "[óòōôö]" "o" slug))
|
(slug (replace-regexp-in-string "[óòōôö]" "o" slug))
|
||||||
(slug (replace-regexp-in-string "[ńǹñ]" "n" slug))
|
(slug (replace-regexp-in-string "[ńǹñ]" "n" slug))
|
||||||
(slug (replace-regexp-in-string "[úùûü]" "u" slug))
|
(slug (replace-regexp-in-string "[úùûü]" "u" slug))
|
||||||
(slug (replace-regexp-in-string "ý" "y" slug))
|
(slug (replace-regexp-in-string "ý" "y" slug)))
|
||||||
(slug (replace-regexp-in-string " " "-" 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)))
|
`(,heading . ,slug)))
|
||||||
|
|
||||||
(defun conlanging--get-filename-no-ext ()
|
(defun conlanging--get-filename-no-ext ()
|
||||||
"Get file name of current buffer without its extension."
|
"Get file name of current buffer without its extension."
|
||||||
(file-name-sans-extension (file-name-nondirectory (buffer-file-name (buffer-base-buffer)))))
|
(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
|
;;;###autoload
|
||||||
(defun conlanging-insert-heading-vuepress ()
|
(defun conlanging-insert-heading-vuepress ()
|
||||||
"Insert vuepress-compatible link to heading."
|
"Insert vuepress-compatible link to heading."
|
||||||
|
Loading…
Reference in New Issue
Block a user