Function: web-mode-python-indentation

web-mode-python-indentation is a natively compiled function defined in web-mode.el.

Signature

(web-mode-python-indentation POS LINE INITIAL-COLUMN LANGUAGE-OFFSET LIMIT)

Source Code

;; Defined in /nix/store/2qgnz1rp30nzfz6w0apx4kdm14if1bbs-emacs-packages-deps/share/emacs/site-lisp/elpa/web-mode-20260831.219/web-mode.el
(defun web-mode-python-indentation (pos line initial-column language-offset limit)
  (unless limit (setq limit nil))
  (let (h offset prev-line prev-indentation ctx)
    (setq ctx (web-mode-bracket-up pos "python" limit))
    ;;(message "point-ctx=%S" ctx)
    (if (plist-get ctx :pos)
        (cond
          ((web-mode-looking-at-p ".[ \t\n]+" (plist-get ctx :pos))
           (setq offset (+ (plist-get ctx :indentation) language-offset)))
          (t
           (setq offset (1+ (plist-get ctx :column))))
          )
        ;; else
        (setq h (web-mode-previous-line pos limit))
        (setq offset initial-column)
        (when h
          (setq prev-line (car h))
          (setq prev-indentation (cdr h))
          (cond
            ((string-match-p "^\\(pass\\|else\\|elif\\|when\\|except\\)" line)
             (setq offset (- prev-indentation language-offset))
             )
            ((string-match-p "\\(if\\|else\\|elif\\|for\\|while\\|try\\|except\\)" prev-line)
             (setq offset (+ prev-indentation language-offset))
             )
            (t
             (setq offset prev-indentation)
             )
            ) ;cond
          ) ;when
        ) ;if
    ;;offset
    (if (< offset initial-column) initial-column offset)
    ))