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.

1 Answer 1

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)
3
  • It works but results in ^M as an end character in every line. Can it be fixed
    – Vaibhav
    Sep 6, 2022 at 9:22
  • 1
    Thanks for the answer
    – Vaibhav
    Sep 6, 2022 at 9:22
  • I am not sure, I don't use Windows. But I guess the one either the answer here or here might fix it. Let me know if it does, in which case I can complete the answer. Sep 6, 2022 at 13:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.