aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/python.el
diff options
context:
space:
mode:
authorDmitry Gutov2017-12-14 11:18:51 +0200
committerDmitry Gutov2017-12-14 11:18:51 +0200
commit7e9eef0ffd90cd7e39f15b003e4a9770be27b0ce (patch)
tree65c46eac3785849457ba9d989ed4acf19b3e8fac /lisp/progmodes/python.el
parent6067f0c702e3652a9d489852752f038320cb91ae (diff)
downloademacs-7e9eef0ffd90cd7e39f15b003e4a9770be27b0ce.tar.gz
emacs-7e9eef0ffd90cd7e39f15b003e4a9770be27b0ce.zip
Consolidate 'widen' calls
* lisp/progmodes/prog-mode.el (prog-indentation-context): Un-document all elements but the first. (prog-widen): Remove. (http://lists.gnu.org/archive/html/emacs-devel/2017-12/msg00321.html) * doc/lispref/text.texi (Mode-Specific Indent): Update. * lisp/progmodes/ruby-mode.el (ruby-calculate-indent): Don't call widen. * lisp/progmodes/python.el (python-indent-guess-indent-offset) (python-info-current-defun): Replace prog-widen with widen; these functions are not called during indentation. (python-indent-context) (python-indent--calculate-indentation) (python-info-dedenter-opening-block-message) (python-info-line-ends-backslash-p) (python-info-beginning-of-backslash) (python-info-continuation-line-p) (python-info-current-defun): Remove 'widen' calls. * lisp/indent.el (indent-according-to-mode) (indent-for-tab-command, indent-region): Move them here. * lisp/textmodes/mhtml-mode.el (mhtml-indent-line): Bind prog-indentation-context to one-element list.
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 d4226e5ce7b..b8926529d1e 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.
@@ -4590,7 +4582,7 @@ Optional argument INCLUDE-TYPE indicates to include the type of the defun.
4590This function can be used as the value of `add-log-current-defun-function' 4582This function can be used as the value of `add-log-current-defun-function'
4591since it returns nil if point is not inside a defun." 4583since it returns nil if point is not inside a defun."
4592 (save-restriction 4584 (save-restriction
4593 (prog-widen) 4585 (widen)
4594 (save-excursion 4586 (save-excursion
4595 (end-of-line 1) 4587 (end-of-line 1)
4596 (let ((names) 4588 (let ((names)
@@ -4788,12 +4780,10 @@ likely an invalid python file."
4788 "Message the first line of the block the current statement closes." 4780 "Message the first line of the block the current statement closes."
4789 (let ((point (python-info-dedenter-opening-block-position))) 4781 (let ((point (python-info-dedenter-opening-block-position)))
4790 (when point 4782 (when point
4791 (save-restriction
4792 (prog-widen)
4793 (message "Closes %s" (save-excursion 4783 (message "Closes %s" (save-excursion
4794 (goto-char point) 4784 (goto-char point)
4795 (buffer-substring 4785 (buffer-substring
4796 (point) (line-end-position)))))))) 4786 (point) (line-end-position)))))))
4797 4787
4798(defun python-info-dedenter-statement-p () 4788(defun python-info-dedenter-statement-p ()
4799 "Return point if current statement is a dedenter. 4789 "Return point if current statement is a dedenter.
@@ -4809,8 +4799,6 @@ statement."
4809 "Return non-nil if current line ends with backslash. 4799 "Return non-nil if current line ends with backslash.
4810With optional argument LINE-NUMBER, check that line instead." 4800With optional argument LINE-NUMBER, check that line instead."
4811 (save-excursion 4801 (save-excursion
4812 (save-restriction
4813 (prog-widen)
4814 (when line-number 4802 (when line-number
4815 (python-util-goto-line line-number)) 4803 (python-util-goto-line line-number))
4816 (while (and (not (eobp)) 4804 (while (and (not (eobp))
@@ -4819,14 +4807,12 @@ With optional argument LINE-NUMBER, check that line instead."
4819 (not (equal (char-before (point)) ?\\))) 4807 (not (equal (char-before (point)) ?\\)))
4820 (forward-line 1)) 4808 (forward-line 1))
4821 (when (equal (char-before) ?\\) 4809 (when (equal (char-before) ?\\)
4822 (point-marker))))) 4810 (point-marker))))
4823 4811
4824(defun python-info-beginning-of-backslash (&optional line-number) 4812(defun python-info-beginning-of-backslash (&optional line-number)
4825 "Return the point where the backslashed line start. 4813 "Return the point where the backslashed line start.
4826Optional argument LINE-NUMBER forces the line number to check against." 4814Optional argument LINE-NUMBER forces the line number to check against."
4827 (save-excursion 4815 (save-excursion
4828 (save-restriction
4829 (prog-widen)
4830 (when line-number 4816 (when line-number
4831 (python-util-goto-line line-number)) 4817 (python-util-goto-line line-number))
4832 (when (python-info-line-ends-backslash-p) 4818 (when (python-info-line-ends-backslash-p)
@@ -4835,15 +4821,13 @@ Optional argument LINE-NUMBER forces the line number to check against."
4835 (python-syntax-context 'paren)) 4821 (python-syntax-context 'paren))
4836 (forward-line -1)) 4822 (forward-line -1))
4837 (back-to-indentation) 4823 (back-to-indentation)
4838 (point-marker))))) 4824 (point-marker))))
4839 4825
4840(defun python-info-continuation-line-p () 4826(defun python-info-continuation-line-p ()
4841 "Check if current line is continuation of another. 4827 "Check if current line is continuation of another.
4842When current line is continuation of another return the point 4828When current line is continuation of another return the point
4843where the continued line ends." 4829where the continued line ends."
4844 (save-excursion 4830 (save-excursion
4845 (save-restriction
4846 (prog-widen)
4847 (let* ((context-type (progn 4831 (let* ((context-type (progn
4848 (back-to-indentation) 4832 (back-to-indentation)
4849 (python-syntax-context-type))) 4833 (python-syntax-context-type)))
@@ -4869,7 +4853,7 @@ where the continued line ends."
4869 (python-util-forward-comment -1) 4853 (python-util-forward-comment -1)
4870 (when (and (equal (1- line-start) (line-number-at-pos)) 4854 (when (and (equal (1- line-start) (line-number-at-pos))
4871 (python-info-line-ends-backslash-p)) 4855 (python-info-line-ends-backslash-p))
4872 (point-marker)))))))) 4856 (point-marker)))))))
4873 4857
4874(defun python-info-block-continuation-line-p () 4858(defun python-info-block-continuation-line-p ()
4875 "Return non-nil if current line is a continuation of a block." 4859 "Return non-nil if current line is a continuation of a block."