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

  • SEARCH
  • Home
  • 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 722271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:58:13+00:00 2026-05-14T05:58:13+00:00

Working with Python in Emacs if I want to add a try/except to a

  • 0

Working with Python in Emacs if I want to add a try/except to a block of code, I often find that I am having to indent the whole block, line by line. In Emacs, how do you indent the whole block at once.

I am not an experienced Emacs user, but just find it is the best tool for working through ssh. I am using Emacs on the command line(Ubuntu), not as a gui, if that makes any difference.

  • 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-14T05:58:14+00:00Added an answer on May 14, 2026 at 5:58 am

    If you are programming Python using Emacs, then you should probably be using python-mode. With python-mode, after marking the block of code,

    C-c > or C-c C-l shifts the region 4 spaces to the right

    C-c < or C-c C-r shifts the region 4 spaces to the left

    If you need to shift code by two levels of indention, or some arbitary amount you can prefix the command with an argument:

    C-u 8 C-c > shifts the region 8 spaces to the right

    C-u 8 C-c < shifts the region 8 spaces to the left

    Another alternative is to use M-x indent-rigidly which is bound to C-x TAB:

    C-u 8 C-x TAB shifts the region 8 spaces to the right

    C-u -8 C-x TAB shifts the region 8 spaces to the left

    Also useful are the rectangle commands that operate on rectangles of text instead of lines of text.

    For example, after marking a rectangular region,

    C-x r o inserts blank space to fill the rectangular region (effectively shifting code to the right)

    C-x r k kills the rectangular region (effectively shifting code to the left)

    C-x r t prompts for a string to replace the rectangle with. Entering C-u 8 <space> will then enter 8 spaces.

    PS. With Ubuntu, to make python-mode the default mode for all .py files, simply install the python-mode package.

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

Sidebar

Related Questions

I have a working Python based program that I want to run as a
I can't get python-mode working in Emacs on Mac OS X (I am a
I am currently working with Python and have been confused over the fact that
I just installed the python-mode in Emacs and it seems to be working well.
I have a working Python script that executes an external command and calls Popen.communicate()
I'm new to the whole Emacs thing, and one of the things that gets
I have a working python wrapper for C++ code (as suggested here Calling C/C++
I have emacs and python working on OSX, but I'd like to get a
I was working with python-twitter and realized that twitter provides streaming api to consume
I use Emacs and am currently working on projects that use different versions of

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.