User-defined sluggification of file name components
The user option denote-file-name-slug-functions controls the sluggification of file name components (Sluggification of file name components). The default method is outlined above and in the previous section (The file-naming scheme).
The value of this user option is an alist where each element is a cons cell of the form ‘(COMPONENT . METHOD)’. For example, here is the default value:
'((title . denote-sluggify-title)
(signature . denote-sluggify-signature)
(keyword . denote-sluggify-keyword))- The ‘
COMPONENT’ is an unquoted symbol among ‘title’, ‘signature’, ‘keyword’, which refers to the corresponding component of the file name. - The ‘
METHOD’ is a function to format the given component. This function must take a string as its parameter and return the string formatted for the file name. Note that even in the case of the ‘keyword’ component, the function receives one string representing a single keyword and returns it formatted for the file name. Joining the keywords together is handled internally by Denote.
One commonly requested deviation from the sluggification rules is to not sluggify individual keywords, such that the user’s input is taken as-is. This can be done as follows:
(setq denote-file-name-slug-functions
'((title . denote-sluggify-title)
(keyword . identity)
(signature . denote-sluggify-signature)))The identity function simply returns the string it receives, thus not altering it in any way.
Another approach is to keep the sluggification but not downcase the string. We can do this by modifying the original functions used by Denote. For example, we have this:
;; The original function for reference
(defun denote-sluggify-title (str)
"Make STR an appropriate slug for title."
(downcase
(denote-slug-hyphenate
(replace-regexp-in-string "[][{}!@#$%^&*()+'\"?,.\|;:~`‘’“”/=]*" "" str))))
;; Our variant of the above, which does the same thing except from
;; downcasing the string.
(defun my-denote-sluggify-title (str)
"Make STR an appropriate slug for title."
(denote-slug-hyphenate
(replace-regexp-in-string "[][{}!@#$%^&*()+'\"?,.\|;:~`‘’“”/=]*" "" str)))
;; Now we use our function to sluggify titles without affecting their
;; letter casing.
(setq denote-file-name-slug-functions
'((title . my-denote-sluggify-title) ; our function here
(signature . denote-sluggify-signature)
(keyword . denote-sluggify-keyword)))Follow this principle for all the sluggification functions (Custom sluggification to remove non-ASCII characters).
To access the source code, use either of the following built-in methods:
- Call the command
find-libraryand search fordenote. Then navigate to the symbol you are searching for. - Invoke the command
describe-symbol, search for the symbol you are interested in, and from the resulting Help buffer either click on the first link or do ‘M-x help-view-source’ (bound to ‘s’ in Help buffers, by default).
Remember that deviating from the default file-naming scheme of Denote will make things harder to use in the future, as files can/will have permutations that create uncertainty. The sluggification scheme and concomitant restrictions we impose by default are there for a very good reason: they are the distillation of years of experience. Here we give you what you wish, but bear in mind it may not be what you need. You have been warned.