Custom sluggification to remove non-ASCII characters
[ Also see: Custom sluggification to remove diacterics or accented characters. ]
A common use-case for Denote is to rename files such as videos downloaded from the Internet. Sometimes, those files have Unicode characters that (i) not all fonts support and (ii) create all sorts of problems with pattern matching, such as when searching through file names.
By default, Denote does not remove Unicode characters because users may actually want them (e.g. Latin characters with accents). Those who do, however, wish to keep everything limited to the ASCII range can use the following in their Emacs configuration (User-defined sluggification of file name components).
emacs-lisp
;; These are the same as the default Denote sluggification functions,
;; except they remove all non-ASCII characters.
(defun my-denote-sluggify-title (str)
(downcase
(denote-slug-hyphenate
(replace-regexp-in-string "[][{}!@#$%^&*()+'\"?,.\|;:~`‘’“”/=]*" ""
(denote-slug-keep-only-ascii str)))))
(defun my-denote-sluggify-signature (str)
(downcase
(denote-slug-put-equals
(replace-regexp-in-string "[][{}!@#$%^&*()+'\"?,.\|;:~`‘’“”/-]*" ""
(denote-slug-keep-only-ascii str)))))
(defun my-denote-sluggify-keyword (str)
(downcase
(replace-regexp-in-string "[][{}!@#$%^&*()+'\"?,.\|;:~`‘’“”/_ =-]*" ""
(denote-slug-keep-only-ascii str))))
(defcustom denote-file-name-slug-functions
'((identifier . identity) ; keep the original
(title . my-denote-sluggify-title)
(signature . my-denote-sluggify-signature)
(keyword . my-denote-sluggify-keyword)))