emacs 23 python.el auto-indent style — can this be configured?

前端 未结 3 1157
后悔当初
后悔当初 2021-02-04 09:18

I have been using emacs 23 (python.el) for just over a month now and I\'m unhappy with the default auto-indentation settings.

Currently, my Python files are auto-indente

相关标签:
3条回答
  • 2021-02-04 09:59

    M-x customize-group RET python RET

    0 讨论(0)
  • 2021-02-04 10:09

    Try with the last fgallina's python.el version. It contains many other improvements.

    I use this version and TAB has the behavior that you want, but I made several modifications to python.el, so I can't be sure that you'll get the same behavior. If so, Let me know.

    0 讨论(0)
  • 2021-02-04 10:17

    You can try this peace of code :

    (require 'python)
    
    ; indentation
    (defadvice python-calculate-indentation (around outdent-closing-brackets)
      "Handle lines beginning with a closing bracket and indent them so that
      they line up with the line containing the corresponding opening bracket."
    (save-excursion
      (beginning-of-line)
      (let ((syntax (syntax-ppss)))
        (if (and (not (eq 'string (syntax-ppss-context syntax)))
                 (python-continuation-line-p)
                 (cadr syntax)
                 (skip-syntax-forward "-")
                 (looking-at "\\s)"))
            (progn
              (forward-char 1)
              (ignore-errors (backward-sexp))
              (setq ad-return-value (current-indentation)))
          ad-do-it))))
    
    (ad-activate 'python-calculate-indentation)
    

    Now, a simple python dict like this :

    a = {'foo': 'bar',
         'foobar': 'barfoo'
        }
    

    becomes...

    a = {'foo': 'bar',
         'foobar': 'barfoo'
    }
    
    0 讨论(0)
提交回复
热议问题