Skip to content

Custom sluggification to remove diacterics or accented characters

[ Also see: Custom sluggification to remove non-ASCII characters. ]

For languages with diacretics, like ‘ê’ and ‘ñ’, users may want to instruct Denote to remove the diacretical marks from the underlying characters. This way, the file names will be uniform and easier to search through, instead of checking if, say, ‘être’ is written thus or as ‘etre’.

This is only for the sluggification of file name components (User-defined sluggification of file name components). Any front matter will retain the diacretics.

emacs-lisp
;; These are the same as the default Denote sluggification functions,
;; except they remove all diacretics from the underlying characters
;; (e.g.  ê becomes e while ñ becomes n).
(defun my-denote-sluggify-title (str)
  (downcase
   (denote-slug-hyphenate
    (replace-regexp-in-string "[][{}!@#$%^&*()+'\"?,.\|;:~`‘’“”/=]*" ""
                              (denote-slug-remove-accents str)))))

(defun my-denote-sluggify-signature (str)
  (downcase
   (denote-slug-put-equals
    (replace-regexp-in-string "[][{}!@#$%^&*()+'\"?,.\|;:~`‘’“”/-]*" ""
                              (denote-slug-remove-accents str)))))

(defun my-denote-sluggify-keyword (str)
  (downcase
   (replace-regexp-in-string "[][{}!@#$%^&*()+'\"?,.\|;:~`‘’“”/_ =-]*" ""
                             (denote-slug-remove-accents 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)))