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 7729279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:55:45+00:00 2026-06-01T05:55:45+00:00

I have been using emacs for a while but not so familiar with lisp

  • 0

I have been using emacs for a while but not so familiar with lisp programming. Its been just couple of days I started coding Python on emacs. I found python-mode to be quite useful and I want to explore it further. I found a few emacs lips functions on internet, tewaked them a bit to make the interface userfriendly. I am trying to achieve following actions

I usually start emacs with 2 vertical windows, one with python source and other is a shell. I should be able to do following using keyboard bindings

  • switch between buffers (working)
  • execute a region (working)
    but replaces the source buffer with shell buffer. I want to execute selected region in original shell buffer.
  • execute a line (working)
    but same issue as above. when i pres say , the line should be executed in python shell without replacing any buffers. so copy the line, switch to python shell, execute line, switch back to python source buffer.

I am not able to achieve switching action above. Following is my code from my init.el file

(defun goto-python-shell ()
  "Go to the python command window (start it if needed)"
  (interactive)
  (setq current-python-script-buffer (current-buffer))
  (if (boundp 'current-python-shell-buffer)
    (switch-to-buffer-other-window current-python-shell-buffer)
    (py-shell))
  (end-of-buffer)
 )

 (defun goto-python-source ()
   "switch back to source window"
   (interactive)
  (setq current-python-shell-buffer (current-buffer))
   (switch-to-buffer-other-window current-python-script-buffer)
 )

 (defun py-execute-statement-and-step ()
   "select a statement, submit as a region and then step forward"
   (interactive)
   (beginning-of-line 1)
   (let ((beg (point)))
     (py-next-statement 1)
     ; if last statement.
        (if (= (point) beg) (end-of-buffer ))
 ; (switch-to-buffer-other-window current-python-shell-buffer)
   (py-execute-region beg (point))
   (switch-to-buffer-other-window current-python-script-buffer)
   )
 )

 ; some key bindings
 (define-key python-mode-map (quote [f9]) 'py-execute-statement-and-step)
 ;(define-key python-mode-map (quote [f10]) `py-execute-region)
 ;py-shell-switch-buffers-on-execute
 (define-key python-mode-map (quote [f10]) `py-shell-switch-buffers-on-execute)
 (define-key python-mode-map (quote [f11]) `py-execute-buffer)
 (define-key python-mode-map (quote [f12]) `goto-python-shell)
 (define-key py-shell-map (quote [f12]) `goto-python-source)

Please advice.

Also since i am new to python-mode, can someone share nice initializations for using python-mode similar to above?

thanks much for your help.

Regards,
AJ

  • 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-06-01T05:55:46+00:00Added an answer on June 1, 2026 at 5:55 am

    You should take a look at the first answer to this question and customize the py-shell-switch-buffers-on-execute variable.

    This way you won’t need all your custom functions to make python-mode work like you want (i.e. keeping the source buffer active)

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

Sidebar

Related Questions

I have been using emacs for a while for mainly python programming, and have
I have been using Emacs since version 18. Emacs Lisp isn't my routine programming
I have been using Emacs for more than three years now but it still
I have been using ajax loaded data for a while now, but I am
We have been using CruiseControl for quite a while with NUnit and NAnt. For
I have been using Castle MonoRail for the last two years, but in a
I have been using C# for a while now, and going back to C++
I have been using ASP.NET for years, but I can never remember when using
I have been using Ruby for a while now and I find, for bigger
I have been using IoC for a little while now and I am curious

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.