Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating files with a different extension than ".txt" does not prompt for the correct extension #4

Closed
Nathan-Furnal opened this issue Sep 13, 2021 · 4 comments

Comments

@Nathan-Furnal
Copy link

Hi, I'm willing to correct this issue in a pull request, in the mean time, I think it'd be better to have a a customizable file extension to create new files.

(defcustom xeft-default-file-extension ".txt"
  "The default file extension for new file creation."
  :type 'string)

Also, this allows this to modify the following functions :

(defcustom xeft-filename-fn
  (lambda (search-phrase)
    (concat search-phrase xeft-default-file-extension))
  "A function that takes the search phrase and returns a filename."
  :type 'function)

And avoid the bug in xeft-create-note which was defaulting to asking for a text extension even though it was not the case. I also removed inserting the file name and create an empty buffer instead.

(defun xeft-create-note ()
  "Create a new note with the current search phrase as the title."
  (interactive)
  (let* ((search-phrase (xeft--get-search-phrase))
         (file-path (expand-file-name
                     (funcall xeft-filename-fn search-phrase)
                     xeft-directory))
         (exists-p (file-exists-p file-path)))
    ;; If there is no match, create the file without confirmation,
    ;; otherwise prompt for confirmation. NOTE: this is not DRY, but
    ;; should be ok.
    (when (or (search-forward "Press RET to create a new note" nil t)
    ;; changed here for the prompt
              (y-or-n-p (format "Create file %s%s? " search-phrase xeft-default-file-extension)))
      (find-file file-path)
    ;; changed here for new file creation
      (unless exists-p
	(write-region "" nil file-path))
      (run-hooks 'xeft-find-file-hook))))

Cheers, thanks for the great package!

@casouri
Copy link
Owner

casouri commented Sep 13, 2021

Thanks. I applied all the changes you mentioned except for not inserting the search phrase when creating a new note. Why do you not want the title? It is not a good idea to remove the first line since xeft uses it as title when showing search results.

@Nathan-Furnal
Copy link
Author

Because I mainly org files and not text files, which means it does not display the title on top of the description. I'm not really sure what would be optimal here, maybe displaying the file name? This is what I get for example for one entry :

Screenshot_20210913_195849

@casouri
Copy link
Owner

casouri commented Sep 13, 2021

My suggestion is to put the title meta on the first line. Xeft will filter out #+TITLE: automatically.

@Nathan-Furnal
Copy link
Author

Alright that makes sense, thanks for that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants