More readable regexes, fix a potential issue with a dash

This commit is contained in:
Lucien Cartier-Tilet 2022-08-24 03:24:16 +02:00
parent bc48314435
commit 1646098bfa
Signed by: phundrak
GPG Key ID: BD7789E705CB8DCA
1 changed files with 11 additions and 10 deletions

View File

@ -86,16 +86,17 @@ case, the CUSTOM_ID of the entry is returned."
(interactive)
(org-with-point-at pom
(let* ((orgpath (mapconcat #'identity (org-get-outline-path) "-"))
(heading (replace-regexp-in-string
"[_-]+$" ""
(replace-regexp-in-string
"[_-][_-]+" "-"
(replace-regexp-in-string
"[^[:alpha:][:digit:]-_]"
"-"
(if (string= orgpath "")
(org-get-heading t t t t)
(concat orgpath "-" (org-get-heading t t t t)))))))
;; Get heading text
(heading (if (string-empty-p orgpath)
(org-get-heading t t t t)
(concat orgpath "-" (org-get-heading t t t t))))
;; Remove non-alphanum, hyphens, and underscore
(heading (replace-regexp-in-string "[^[:alnum:]\\-_]" "" heading))
;; Replace repeated dashes or underscores with a single dash
(heading (replace-regexp-in-string "[_-]+" "-" heading))
;; Remove leading and trailing dashes and underscores
(heading (replace-regexp-in-string "^[_-]+\\|[_-]+$" "" heading))
(id (org-entry-get nil "CUSTOM_ID")))
(cond
((and id