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

View File

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