I want to make my own shell command where i have a variable filename in the command. The filename is passed in an interactive function. I don't know how to save the filename passed as an argument to a variable and further use it to append the whole command.
1 Answer
To ask for a file name (or any other type of value), use interactive. (interactive "fFile: ") means to ask for an existing file (that's what f stands for), prompting with File:.
Then, to concatenate a number of strings, use the concat function.
So the function would look something like this:
(defun my-cat-file (filename)
(interactive "fFile: ")
(shell-command (concat "cat " filename)))
1 Comment
Ishu Gupta
Thanks a lot. It really helped me. Can you just suggest any command that automatically takes the present file when i press enter (just like % in .vimrc file. basically i want that interactive command should not invoke automatically when i dont pass any argument as filename while calling the function and automatically takes the present file.