Customise the ${slug}

Is there a way to customise the ${slug} element of the capture template?

Looks like you can define your own function, and set this customizing variable to use it.

(defcustom org-roam-title-to-slug-function #'org-roam--title-to-slug
  "Function to be used in converting a title to the filename slug.
Function should return a filename string based on title."
1 Like

Thanks - that’s perfect. May I ask how you found this? I assume it’s discoverable in Emacs in some way, and I figure that if I can know how to discover such things I’ll ask fewer annoying questions :slight_smile:

No worries. Don’t find these annoying :slight_smile:

For user options, two or three ways. For Org-roam, I usually start with reading source (Option 2 below) these days (as I have read its source so many times).

  1. M-x customize
    And search for Org Roam in the search box.
    And then find the string you are looking for.

  2. Read source
    Easy to navigate via C-h f (functions) or C-h v (variables) to the main .el file—for Org-roam, org-roam.el. Look for defcustom, which is a macro to define a customizing variable. As Emacs convention, customizing variables usually appear at the beginning of the source, so you can look through them to have a feel of what sort of things are designed to be customizable.

    You can usually expect the documentation string (the text between “” added as part of the defcustom definition) to be a good guide. In addition, I also look for places where the variable is used. I just search the text string in the source. Alternatively, helpful-variable gives you “where used” search—I don’t use it often, but might be useful.

  3. Read user manual
    C-h i. Org-roam has an in-system user manual. For the case of slug config, it does not seem to be on the manual. But usually, I try to glance through at least the main chapters of the manual to have a feel of the package.

3 Likes

That’s super helpful - thank you!

1 Like

Is it still possible to do this in v2?

I no longer see org-roam-title-to-slug-function in the code - only org-roam-node-slug, and I’m not sure this is customisable.

No, I didn’t think so. I thought there was a comment from Jethro about it in this Discourse or Slack. I suggest you search – if I recall correctly, you would need to provide an advice function and vaguely remember someone provided a sample code. It could have been a GitHub issue. One of these places.

1 Like

Thank you for the pointer :+1:

I have found some discussion here: Customization for character replacement generated slug by aruscher · Pull Request #1544 · org-roam/org-roam · GitHub

It looks like the suggestion is to override the whole org-roam-node-slug function.

1 Like

Would it be alright for you to add this to the wiki (or anyone who feel up for it) by any chance?
I feel that the solution would benefit many people.

1 Like

I have added it in: Hitchhiker's Rough Guide to Org roam V2 · org-roam/org-roam Wiki · GitHub

2 Likes

Thank you :pray: