简体   繁体   中英

Cycling through possible indentations in python.el in Emacs

The latest version of Emacs (eg 24.3.93.1 ) come with python.el . How can I cycle through different levels of indentation for a given block?

For instance in the code:

for ix in range(10);
   line1
   line2 # <- two possible values of indentation for this line

The EmacsWiki doesn't seem to provide info on this and I couldn't find anything on Ch m . Is this functionality supported?

Both python-modes use TAB for cycling. Should TAB not cycle, check your init resp. consider filing a bug-report.

BTW the way it's done differs slightly: from outmost position python.el will dedent immediatly, while first hit at python-mode.el from correct outmost position does nothing. Second TAB at python-mode.el will jump to column 0, then stepping up indent by indent. Python.el does the inverse, steps down indent by indent, but jumps to outmost from column zero.

Use Ch m in order to know that. It invokes the describe-mode function.

You can also look at the python.el file and look for define-key :

;; Indent specific                                                                                                                         
(define-key map "\177" 'python-indent-dedent-line-backspace)                                                                               
(define-key map (kbd "<backtab>") 'python-indent-dedent-line)                                                                              
(define-key map "\C-c<" 'python-indent-shift-left)                                                                                         
(define-key map "\C-c>" 'python-indent-shift-right)                                                                                        
(define-key map ":" 'python-indent-electric-colon)      

Or indent

;; Indentation: Automatic indentation with indentation cycling is                                                                              
;; provided, it allows you to navigate different available levels of                                                                           
;; indentation by hitting <tab> several times.  Also when inserting a                                                                          
;; colon the `python-indent-electric-colon' command is invoked and                                                                             
;; causes the current line to be dedented automatically if needed. 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM