Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6471967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:17:11+00:00 2026-05-25T06:17:11+00:00

I was trying some code from Elisp Cookbook , and I initially tought that

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T06:17:11+00:00Added an answer on May 25, 2026 at 6:17 am

    The elisp way to generate a unique buffer name is to use generate-new-buffer-name. The documentation is:

    (generate-new-buffer-name NAME &optional IGNORE)
    

    Return a string that is the name of no existing buffer based on NAME.
    If there is no live buffer named NAME, then return NAME. Otherwise
    modify name by appending `’, incrementing NUMBER (starting at
    2) until an unused name is found, and then return that name. Optional
    second argument IGNORE specifies a name that is okay to use (if it is
    in the sequence to be tried) even if a buffer with that name exists.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert some code from C# to C so that it can
I'm trying to parse a html doc using some code I found from this
There is some code that I'm trying to convert from IList to IEnumerable :
I'm trying to write some C# code that calls a method from an unmanaged
I'm trying to compile some code from a Windows API. It says that certain
I am trying to read some Java code from a tutorial, I don't understand
This is ridiculous. I am trying to download some code from scala trac: http://lampsvn.epfl.ch/trac/scala/browser/scala-tool-support/trunk/src/vim
Was trying to compile some code from this SO question and run into this
I am trying to compile some code from a project that is no longer.
I am trying to create a countdown using javascript. I got some code from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.