1

I create short text files in a folder c:/Dropbox/daily/ and insert them in various documents using shortcut C-x i. I would like to define a shortcut so that I don't have to type the path of folder again and again while allowing me to choose the file in the folder interactively.

NickD
  • 27,023
  • 3
  • 23
  • 42
Vaibhav
  • 573
  • 3
  • 15

1 Answers1

1

You can simply use read-file-name for that:

(defun my-insert-daily (file)
  (interactive (list (read-file-name "Select file: " "c:/Dropbox/daily/")))
  (insert-file-contents-literally file))

(global-set-key (kbd "C-x i") #'my-insert-daily)
dalanicolai
  • 6,108
  • 7
  • 23
  • It works but results in ^M as an end character in every line. Can it be fixed – Vaibhav Sep 06 '22 at 09:22
  • 1
    Thanks for the answer – Vaibhav Sep 06 '22 at 09:22
  • I am not sure, I don't use Windows. But I guess the one either the answer [here](https://emacs.stackexchange.com/a/5800/26163) or [here](https://superuser.com/a/216407) might fix it. Let me know if it does, in which case I can complete the answer. – dalanicolai Sep 06 '22 at 13:19