I was trying some code from Elisp Cookbook, and I initially tought that this code:
(defun process-file (file) "Read the contents of a file into a temp buffer and then do something there." (when (file-readable-p file) (with-temp-buffer (insert-file-contents file) (goto-char (point-min)) (while (not (eobp)) ;; do something here with buffer content (forward-line)))))
Will create a new ( unnamed/unsaved ) buffer on my emacs window, having the contents of that file ( and maybe open it in the foreground ). However, this doesn't happen. Can you guide me towards this?
EDIT: I experimented a little, and got to this:
(defun myTest (file) (interactive "f") ; check if file is readable (when (file-readable-p file) ; create a new "untitled" buffer (let ((myBuf (get-buffer-create "untitled"))) ; make it the current displayed buffer (switch-to-buffer myBuf) (insert "Hello"))))
Is this the way to do it?
Since this is a buffer named "untitled", I can only have one of these in a session. Is there something I could use to have more than one, without resorting to random numbers?