mirror of https://github.com/python/cpython.git
(py-electric-colon): turn off electric behavior inside strings and
comments.
This commit is contained in:
parent
57697af9b0
commit
0c6563f7c7
|
@ -471,31 +471,39 @@ py-beep-if-tab-change\tring the bell if tab-width is changed"
|
||||||
(defun py-electric-colon (arg)
|
(defun py-electric-colon (arg)
|
||||||
"Insert a colon.
|
"Insert a colon.
|
||||||
In certain cases the line is outdented appropriately. If a numeric
|
In certain cases the line is outdented appropriately. If a numeric
|
||||||
argument is provided, that many colons are inserted non-electrically."
|
argument is provided, that many colons are inserted non-electrically.
|
||||||
|
Electric behavior is inhibited inside a string or comment."
|
||||||
(interactive "P")
|
(interactive "P")
|
||||||
(self-insert-command (prefix-numeric-value arg))
|
(self-insert-command (prefix-numeric-value arg))
|
||||||
(save-excursion
|
;; are we in a string or comment?
|
||||||
(let ((here (point))
|
(if (save-excursion
|
||||||
(outdent 0)
|
(let ((pps (parse-partial-sexp (save-excursion
|
||||||
(indent (py-compute-indentation)))
|
(beginning-of-python-def-or-class)
|
||||||
(if (and (not arg)
|
(point))
|
||||||
(py-outdent-p)
|
(point))))
|
||||||
(= indent (save-excursion
|
(not (or (nth 3 pps) (nth 4 pps)))))
|
||||||
(forward-line -1)
|
(save-excursion
|
||||||
(py-compute-indentation)))
|
(let ((here (point))
|
||||||
)
|
(outdent 0)
|
||||||
(setq outdent py-indent-offset))
|
(indent (py-compute-indentation)))
|
||||||
;; Don't indent, only outdent. This assumes that any lines that
|
(if (and (not arg)
|
||||||
;; are already outdented relative to py-compute-indentation were
|
(py-outdent-p)
|
||||||
;; put there on purpose. Its highly annoying to have `:' indent
|
(= indent (save-excursion
|
||||||
;; for you. Use TAB, C-c C-l or C-c C-r to adjust. TBD: Is
|
(forward-line -1)
|
||||||
;; there a better way to determine this???
|
(py-compute-indentation)))
|
||||||
(if (< (current-indentation) indent) nil
|
)
|
||||||
(goto-char here)
|
(setq outdent py-indent-offset))
|
||||||
(beginning-of-line)
|
;; Don't indent, only outdent. This assumes that any lines that
|
||||||
(delete-horizontal-space)
|
;; are already outdented relative to py-compute-indentation were
|
||||||
(indent-to (- indent outdent))
|
;; put there on purpose. Its highly annoying to have `:' indent
|
||||||
))))
|
;; for you. Use TAB, C-c C-l or C-c C-r to adjust. TBD: Is
|
||||||
|
;; there a better way to determine this???
|
||||||
|
(if (< (current-indentation) indent) nil
|
||||||
|
(goto-char here)
|
||||||
|
(beginning-of-line)
|
||||||
|
(delete-horizontal-space)
|
||||||
|
(indent-to (- indent outdent))
|
||||||
|
)))))
|
||||||
|
|
||||||
(defun py-indent-right (arg)
|
(defun py-indent-right (arg)
|
||||||
"Indent the line by one `py-indent-offset' level.
|
"Indent the line by one `py-indent-offset' level.
|
||||||
|
|
Loading…
Reference in New Issue