FeatureRequest: Handle special characters in zettels filenames
buhtz opened this issue · 7 comments
The problem:
Using "special" characters like &
, :
or "
in a zettel's title while make this characters be part of the filename. In Linux this is not a problem but in windows it is.
In my use case I created such zettel in Debian 11 emacs and synced them via nextCloud to a Windows10 machine. Of course I got errors from nextCloud because of that chars.
Solution:
I do not have a concret technical solution because I do not really understand how title-to-filename-transformation or emacs itself works.
If you see a way it would be great to handle this automaticlly. For example special characters could be replaced by underlines _
or something else. But doesn't this influence the way zettel titles are displayed in links on other zettels's?
Maybe you see a way?
Or just make an option to give a warning about forbidden chars in title/filename?
Hi buhtz, this issue was previously discussed here: #63
The good news is: you can configure Deft to take care of this And Zetteldeft separates filenames and file titles, so this is easily achieved. See the discussion in PR #42, where it is explained how you could use deft-file-naming-rules
to achieve what you want.
Perhaps, after you've configured your setup, you can share it here? I could add a note on this to the zd-tutorial
knowledge base, which would explain how to configure this for Windows systems' filenaming rules.
EDIT: Replaced zetteldeft-file-naming-rule
with deft-file-naming-rules
Sorry, the Issues and PR your linked to are far above my knowledge. I do not understand them.
Without knowing what it does I tried
(setq deft-file-naming-rules
'((noslash . "-")
(nospace . "-")
(case-fn . downcase)))
No effect. There is no difference between title and resulting filename except the datestring.
$ ls
'2021-10-08-1537 äöü ß ? "test" : &.org'
'2021-10-08-1540 % $ ? ".org'
And zetteldeft-file-naming-rules
is not mentioned anywhere in the PR.
To learn how to use this, try C-h
v
deft-file-naming-rules
to check out the Deft documentation and read up on the different possibilities.
You can also write your own function to replace specific characters in the file name strings, as explained here: #31 (comment)
I don't use these features myself, but I hope this helps you out.
And zetteldeft-file-naming-rules is not mentioned anywhere in the PR.
My mistake! I meant to type deft-file-naming-rules
.
My mistake! I meant to type
deft-file-naming-rules
.
IMHO it would improve the docu if you would have a special section about features and functionalities that does not come from zetteldeft
but from deft
or other emacs parts. Me as a user I do not think like a machine or in separated emacs modules/modes.
I use zetteldeft not more. I want to change zetteldeft filenaming and of course I want to do that with zetteldeft. I does not come to my mind that another emacs module could be involved in such a basic feature.
I am aware that this is part of emacs concept and if someone use emacs she/he also decides to "make some steps into the machine". But "some" not all. As a "user of zetteldeft" I do not want to think about other modes. It would help me, but I assume it is unusual, to create surrogate functions for zetteldeft (e.g. zetteldeft-file-nameing-rules
) simply calling the "real" function (e.g. deft-file-nameing-rule
).
So I looked into the docu of the variable/function(?). The docu uses setq
but I assume this is not needed when I use usepackage
right?
This is part of my init file.
99 (use-package deft
100 :ensure t
101 :custom
102 (deft-extensions '("org" "md" "txt"))
103 (deft-directory "~/tab-cloud/zettel")
104 (deft-use-filename-as-title t)
105 (deft-file-nameing-rules
106 ’((nospace . "_"))
107 )
108 )
109
110 (use-package zetteldeft
111 :ensure t
112 :after deft
113 :config (zetteldeft-set-classic-keybindings))
To make it simple I used foo bar
as title of a new zettel. But it is not transformed into *foo_bar.org
but *foo bar.org
. The space is still there but I set nospace
. So what did I missunerstood? Or is someting wrong with my syntax?
When I understood the docu correct this variable does not do a lot. It just replaces slashes and spaces and take care of upper- or lowercase letters - not more. What is about my :
, or "
or etc...
How can I treat them?
There seems to be a typo in your config: nameing
should be naming
. But otherwise it looks fine to me.
To replace other characters, you could write your own function. Based on this example, you might do something like this:
(defun my-filter (str)
(replace-regexp-in-string ":" "_" str))
(setq deft-file-naming-rules '((noslash . "-")
(nospace . "-")
(case-fn . my-filter)))
You'd have to expand the my-filter
function to filter more than just :
's, but this is the basic idea.
IMHO it would improve the docu if you would have a special section about features and functionalities that does not come from
zetteldeft
but fromdeft
or other emacs parts. Me as a user I do not think like a machine or in separated emacs modules/modes. I use zetteldeft not more. I want to change zetteldeft filenaming and of course I want to do that with zetteldeft. I does not come to my mind that another emacs module could be involved in such a basic feature.
Zetteldeft is specifically intended as expansion of Deft. In other words: Deft is the core of Zetteldeft (at least it is for now), so it doesn't make sense to me to duplicate configuration options.