Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customization for character replacement generated slug #1544

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 16 additions & 5 deletions org-roam.el
Expand Up @@ -163,6 +163,21 @@ Marks from the Latin alphabet."
:type '(repeat character)
:group 'org-roam)

(defcustom org-roam-slug-name-replacement-rules
'(("[^[:alnum:][:digit:]]" . "_") ;; convert anything not alphanumeric
("__*" . "_") ;; remove sequential underscores
("^_" . "") ;; remove starting underscore
("_$" . "")) ;; remove ending underscore
"Replacement rules applied after Unicode normalization to get the slug.

By default the following rules are applied:
1. All not alphanumeric characters are replaced by underscores
2. Sequential underscores are replaced by a single underscore
3. Starting underscores are removed
4. Ending underscores are removed"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great. So much passive voice, though: are applied, are replaced (2×), are removed (2×). Why not go with apply, replace, and remove?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used passive voice because something is done with something. I will check the other docs and revise this text if necessary.

:type '(alist :key-type regexp :value-type string)
:group 'org-roam)

;;;; ID Utilities
(defun org-roam-id-at-point ()
"Return the ID at point, if any.
Expand Down Expand Up @@ -462,11 +477,7 @@ OLD-FILE is cleared from the database, and NEW-FILE-OR-DIR is added."
(ucs-normalize-NFD-string s)))))
(cl-replace (title pair)
(replace-regexp-in-string (car pair) (cdr pair) title)))
(let* ((pairs `(("[^[:alnum:][:digit:]]" . "_") ;; convert anything not alphanumeric
("__*" . "_") ;; remove sequential underscores
("^_" . "") ;; remove starting underscore
("_$" . ""))) ;; remove ending underscore
(slug (-reduce-from #'cl-replace (strip-nonspacing-marks title) pairs)))
(let ((slug (-reduce-from #'cl-replace (strip-nonspacing-marks title) org-roam-slug-name-replacement-rules)))
(downcase slug)))))

(defvar org-roam-node-map
Expand Down