aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/python.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/progmodes/python.el')
-rw-r--r--lisp/progmodes/python.el32
1 files changed, 8 insertions, 24 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 4388cbdc060..a72a55d2d9a 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -287,10 +287,6 @@
287;;; 24.x Compat 287;;; 24.x Compat
288 288
289 289
290(unless (fboundp 'prog-widen)
291 (defun prog-widen ()
292 (widen)))
293
294(unless (fboundp 'prog-first-column) 290(unless (fboundp 'prog-first-column)
295 (defun prog-first-column () 291 (defun prog-first-column ()
296 0)) 292 0))
@@ -785,7 +781,7 @@ work on `python-indent-calculate-indentation' instead."
785 (interactive) 781 (interactive)
786 (save-excursion 782 (save-excursion
787 (save-restriction 783 (save-restriction
788 (prog-widen) 784 (widen)
789 (goto-char (point-min)) 785 (goto-char (point-min))
790 (let ((block-end)) 786 (let ((block-end))
791 (while (and (not block-end) 787 (while (and (not block-end)
@@ -883,8 +879,6 @@ keyword
883:at-dedenter-block-start 879:at-dedenter-block-start
884 - Point is on a line starting a dedenter block. 880 - Point is on a line starting a dedenter block.
885 - START is the position where the dedenter block starts." 881 - START is the position where the dedenter block starts."
886 (save-restriction
887 (prog-widen)
888 (let ((ppss (save-excursion 882 (let ((ppss (save-excursion
889 (beginning-of-line) 883 (beginning-of-line)
890 (syntax-ppss)))) 884 (syntax-ppss))))
@@ -1022,7 +1016,7 @@ keyword
1022 (looking-at (python-rx block-ender))) 1016 (looking-at (python-rx block-ender)))
1023 :after-block-end) 1017 :after-block-end)
1024 (t :after-line)) 1018 (t :after-line))
1025 (point))))))))) 1019 (point))))))))
1026 1020
1027(defun python-indent--calculate-indentation () 1021(defun python-indent--calculate-indentation ()
1028 "Internal implementation of `python-indent-calculate-indentation'. 1022 "Internal implementation of `python-indent-calculate-indentation'.
@@ -1030,8 +1024,6 @@ May return an integer for the maximum possible indentation at
1030current context or a list of integers. The latter case is only 1024current context or a list of integers. The latter case is only
1031happening for :at-dedenter-block-start context since the 1025happening for :at-dedenter-block-start context since the
1032possibilities can be narrowed to specific indentation points." 1026possibilities can be narrowed to specific indentation points."
1033 (save-restriction
1034 (prog-widen)
1035 (save-excursion 1027 (save-excursion
1036 (pcase (python-indent-context) 1028 (pcase (python-indent-context)
1037 (`(:no-indent . ,_) (prog-first-column)) ; usually 0 1029 (`(:no-indent . ,_) (prog-first-column)) ; usually 0
@@ -1081,7 +1073,7 @@ possibilities can be narrowed to specific indentation points."
1081 (`(,(or :inside-paren-newline-start-from-block) . ,start) 1073 (`(,(or :inside-paren-newline-start-from-block) . ,start)
1082 ;; Add two indentation levels to make the suite stand out. 1074 ;; Add two indentation levels to make the suite stand out.
1083 (goto-char start) 1075 (goto-char start)
1084 (+ (current-indentation) (* python-indent-offset 2))))))) 1076 (+ (current-indentation) (* python-indent-offset 2))))))
1085 1077
1086(defun python-indent--calculate-levels (indentation) 1078(defun python-indent--calculate-levels (indentation)
1087 "Calculate levels list given INDENTATION. 1079 "Calculate levels list given INDENTATION.
@@ -4593,7 +4585,7 @@ Optional argument INCLUDE-TYPE indicates to include the type of the defun.
4593This function can be used as the value of `add-log-current-defun-function' 4585This function can be used as the value of `add-log-current-defun-function'
4594since it returns nil if point is not inside a defun." 4586since it returns nil if point is not inside a defun."
4595 (save-restriction 4587 (save-restriction
4596 (prog-widen) 4588 (widen)
4597 (save-excursion 4589 (save-excursion
4598 (end-of-line 1) 4590 (end-of-line 1)
4599 (let ((names) 4591 (let ((names)
@@ -4791,12 +4783,10 @@ likely an invalid python file."
4791 "Message the first line of the block the current statement closes." 4783 "Message the first line of the block the current statement closes."
4792 (let ((point (python-info-dedenter-opening-block-position))) 4784 (let ((point (python-info-dedenter-opening-block-position)))
4793 (when point 4785 (when point
4794 (save-restriction
4795 (prog-widen)
4796 (message "Closes %s" (save-excursion 4786 (message "Closes %s" (save-excursion
4797 (goto-char point) 4787 (goto-char point)
4798 (buffer-substring 4788 (buffer-substring
4799 (point) (line-end-position)))))))) 4789 (point) (line-end-position)))))))
4800 4790
4801(defun python-info-dedenter-statement-p () 4791(defun python-info-dedenter-statement-p ()
4802 "Return point if current statement is a dedenter. 4792 "Return point if current statement is a dedenter.
@@ -4812,8 +4802,6 @@ statement."
4812 "Return non-nil if current line ends with backslash. 4802 "Return non-nil if current line ends with backslash.
4813With optional argument LINE-NUMBER, check that line instead." 4803With optional argument LINE-NUMBER, check that line instead."
4814 (save-excursion 4804 (save-excursion
4815 (save-restriction
4816 (prog-widen)
4817 (when line-number 4805 (when line-number
4818 (python-util-goto-line line-number)) 4806 (python-util-goto-line line-number))
4819 (while (and (not (eobp)) 4807 (while (and (not (eobp))
@@ -4822,14 +4810,12 @@ With optional argument LINE-NUMBER, check that line instead."
4822 (not (equal (char-before (point)) ?\\))) 4810 (not (equal (char-before (point)) ?\\)))
4823 (forward-line 1)) 4811 (forward-line 1))
4824 (when (equal (char-before) ?\\) 4812 (when (equal (char-before) ?\\)
4825 (point-marker))))) 4813 (point-marker))))
4826 4814
4827(defun python-info-beginning-of-backslash (&optional line-number) 4815(defun python-info-beginning-of-backslash (&optional line-number)
4828 "Return the point where the backslashed line starts. 4816 "Return the point where the backslashed line starts.
4829Optional argument LINE-NUMBER forces the line number to check against." 4817Optional argument LINE-NUMBER forces the line number to check against."
4830 (save-excursion 4818 (save-excursion
4831 (save-restriction
4832 (prog-widen)
4833 (when line-number 4819 (when line-number
4834 (python-util-goto-line line-number)) 4820 (python-util-goto-line line-number))
4835 (when (python-info-line-ends-backslash-p) 4821 (when (python-info-line-ends-backslash-p)
@@ -4838,15 +4824,13 @@ Optional argument LINE-NUMBER forces the line number to check against."
4838 (python-syntax-context 'paren)) 4824 (python-syntax-context 'paren))
4839 (forward-line -1)) 4825 (forward-line -1))
4840 (back-to-indentation) 4826 (back-to-indentation)
4841 (point-marker))))) 4827 (point-marker))))
4842 4828
4843(defun python-info-continuation-line-p () 4829(defun python-info-continuation-line-p ()
4844 "Check if current line is continuation of another. 4830 "Check if current line is continuation of another.
4845When current line is continuation of another return the point 4831When current line is continuation of another return the point
4846where the continued line ends." 4832where the continued line ends."
4847 (save-excursion 4833 (save-excursion
4848 (save-restriction
4849 (prog-widen)
4850 (let* ((context-type (progn 4834 (let* ((context-type (progn
4851 (back-to-indentation) 4835 (back-to-indentation)
4852 (python-syntax-context-type))) 4836 (python-syntax-context-type)))
@@ -4872,7 +4856,7 @@ where the continued line ends."
4872 (python-util-forward-comment -1) 4856 (python-util-forward-comment -1)
4873 (when (and (equal (1- line-start) (line-number-at-pos)) 4857 (when (and (equal (1- line-start) (line-number-at-pos))
4874 (python-info-line-ends-backslash-p)) 4858 (python-info-line-ends-backslash-p))
4875 (point-marker)))))))) 4859 (point-marker)))))))
4876 4860
4877(defun python-info-block-continuation-line-p () 4861(defun python-info-block-continuation-line-p ()
4878 "Return non-nil if current line is a continuation of a block." 4862 "Return non-nil if current line is a continuation of a block."