zetteldeft icon indicating copy to clipboard operation
zetteldeft copied to clipboard

Disallow Certain Characters in the Filename

Open beetleb opened this issue 4 years ago • 7 comments

Can we disallow certain characters from being part of the filename? As an example I recently made a title that ended with a question mark. Deft could not handle it (not sure if it's an Emacs thing, or my OS, but the error came from Deft). The annoying part was that even if I tried to manually save it with a different file name Deft would override any attempts to do so. I had to start a new note and copy/pasted the content.

Of course, figuring out what characters to strip may be a challenge. Instead of taking that challenge, perhaps let the user specify it in an alist and simply strip out characters that reside therein?

beetleb avatar Jan 21 '20 02:01 beetleb

If its an error related to deft, I'm not sure we should try to fix it in zetteldeft.

Also, I'm not sure it's a deft related error in the first place: I tried creating a note with a ? in the title and experienced no issues. Can you elaborate on the type of error you receive?

EFLS avatar Jan 22 '20 10:01 EFLS

It may be a Windows thing, then - I maintain a Zettelkasten on both systems. I'll try to double check to see if the problem is coming from deft or zd or Windows.

Would you reject a patch if I made one? I think at the end of the day the concern is whether Windows users can reasonably use zd. Almost everything in Emacs (except perhaps magit) works as well on Windows as on Linux.

beetleb avatar Jan 22 '20 15:01 beetleb

Yeah, I don't think windows allows ? in filenames.

If you write something to strip these characters feel free to share it, I might include it (as long as it's optional).

EFLS avatar Jan 22 '20 15:01 EFLS

I experimented and it does seem that Windows does not allow question marks. If I fix this I'll send you the MR.

beetleb avatar Jan 23 '20 02:01 beetleb

I've also experienced this issue and noticed that a colon also isn't allowed. There's a complete list of valid/invalid characters here:

https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file

pmiddend avatar May 07 '20 18:05 pmiddend

Thanks the new renaming functions of PR #42, Zetteldeft now respects deft-file-naming-rules.

This means you could use something like:

(defun test-filter (str)
  (downcase (replace-regexp-in-string "?" "" str)))

(setq deft-file-naming-rules '((noslash . "-")
			       (nospace . "-")
			       (case-fn . test-filter)))

Now ? will be removed from your filenames.

All thanks to @natdash!

EFLS avatar Jul 08 '20 20:07 EFLS

If someone on Windows could test whether this is an acceptable workaround, please share your experiences.

EFLS avatar Aug 11 '20 16:08 EFLS