4

In deft mode I can change the default text extension using

(setq deft-extension "txt")

Is there any way to support multiple file types? (e.g. I have a mix of .txt .md and .org files in my directory)

ws6079
  • 155
  • 5
  • Could you link to deft-mode? – Malabarba Nov 12 '14 at 14:06
  • oh sorry: it's this one http://jblevins.org/projects/deft/ – ws6079 Nov 12 '14 at 14:07
  • The short answer is no, deft only supports a single file extension at the moment. It would need to be updated. What about creating new notes, would you still want a single extension used as the default? One of the goals of deft is not to think about file names / extensions, I believe. – glucas Nov 12 '14 at 14:59
  • I see that it is more difficult than a simple regexp as I was hoping. I like the way [nvALT](http://brettterpstra.com/projects/nvalt/) handles file extensions: several are recognized, and one is specified as a default for new files. – ws6079 Nov 12 '14 at 15:04

4 Answers4

1

As pointed out by @glucas this does not seem to be possible right now. A somewhat acceptable workaround for multiple file types is (for me) to set

(setq deft-extension "")

which matches all files in the directory. Unfortunately new files then have an dot extension . e.g., todo_test..

ws6079
  • 155
  • 5
  • To deal with the new file issue, maybe you could advise `deft-new-file-named` and use `let` to set the extension for the duration of that call? – glucas Nov 13 '14 at 15:48
1

Building on the workaround in @ws6079's answer, you can use advice to specify a default extension for new files.

Here's an example that defaults to txt (using Emacs 24.4-style advice):

(setq deft-extension "")
(defvar deft-default-extension "txt")

(defun my/deft-default-extension (orig-func &rest args)
  (let ((deft-extension deft-default-extension))
    (apply orig-func args)))

(when (not (version< emacs-version "24.4"))         
  (advice-add 'deft-new-file :around #'my/deft-default-extension))
ws6079
  • 155
  • 5
glucas
  • 20,175
  • 1
  • 51
  • 83
0

From the file deft.el, this works

(setq deft-extensions '("txt" "tex" "org")
Anusha
  • 419
  • 4
  • 14
0

Pretty big bump, but it really can be just a simple regexp as you (@ws6079) suggested in a comment. The following works for .org and .txt files:

(setq deft-extension "\\(\\.org\\'\\|\\.txt\\'\\)")

I don't know if support for this had been added since you first asked.

Angel
  • 3
  • 2
  • Thanks, unfortunately that still doesn't seem to work properly for my version. Specifically, the names of newly created file names are messed up. – ws6079 Feb 05 '15 at 12:28