1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-01-08 04:30:45 -08:00

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.
This commit is contained in:
Dmitry Gutov 2017-12-14 11:18:51 +02:00
parent 6067f0c702
commit 7e9eef0ffd
7 changed files with 35 additions and 125 deletions

View file

@ -287,10 +287,6 @@
;;; 24.x Compat
(unless (fboundp 'prog-widen)
(defun prog-widen ()
(widen)))
(unless (fboundp 'prog-first-column)
(defun prog-first-column ()
0))
@ -785,7 +781,7 @@ work on `python-indent-calculate-indentation' instead."
(interactive)
(save-excursion
(save-restriction
(prog-widen)
(widen)
(goto-char (point-min))
(let ((block-end))
(while (and (not block-end)
@ -883,8 +879,6 @@ keyword
:at-dedenter-block-start
- Point is on a line starting a dedenter block.
- START is the position where the dedenter block starts."
(save-restriction
(prog-widen)
(let ((ppss (save-excursion
(beginning-of-line)
(syntax-ppss))))
@ -1022,7 +1016,7 @@ keyword
(looking-at (python-rx block-ender)))
:after-block-end)
(t :after-line))
(point)))))))))
(point))))))))
(defun python-indent--calculate-indentation ()
"Internal implementation of `python-indent-calculate-indentation'.
@ -1030,8 +1024,6 @@ May return an integer for the maximum possible indentation at
current context or a list of integers. The latter case is only
happening for :at-dedenter-block-start context since the
possibilities can be narrowed to specific indentation points."
(save-restriction
(prog-widen)
(save-excursion
(pcase (python-indent-context)
(`(:no-indent . ,_) (prog-first-column)) ; usually 0
@ -1081,7 +1073,7 @@ possibilities can be narrowed to specific indentation points."
(`(,(or :inside-paren-newline-start-from-block) . ,start)
;; Add two indentation levels to make the suite stand out.
(goto-char start)
(+ (current-indentation) (* python-indent-offset 2)))))))
(+ (current-indentation) (* python-indent-offset 2))))))
(defun python-indent--calculate-levels (indentation)
"Calculate levels list given INDENTATION.
@ -4590,7 +4582,7 @@ Optional argument INCLUDE-TYPE indicates to include the type of the defun.
This function can be used as the value of `add-log-current-defun-function'
since it returns nil if point is not inside a defun."
(save-restriction
(prog-widen)
(widen)
(save-excursion
(end-of-line 1)
(let ((names)
@ -4788,12 +4780,10 @@ likely an invalid python file."
"Message the first line of the block the current statement closes."
(let ((point (python-info-dedenter-opening-block-position)))
(when point
(save-restriction
(prog-widen)
(message "Closes %s" (save-excursion
(goto-char point)
(buffer-substring
(point) (line-end-position))))))))
(point) (line-end-position)))))))
(defun python-info-dedenter-statement-p ()
"Return point if current statement is a dedenter.
@ -4809,8 +4799,6 @@ statement."
"Return non-nil if current line ends with backslash.
With optional argument LINE-NUMBER, check that line instead."
(save-excursion
(save-restriction
(prog-widen)
(when line-number
(python-util-goto-line line-number))
(while (and (not (eobp))
@ -4819,14 +4807,12 @@ With optional argument LINE-NUMBER, check that line instead."
(not (equal (char-before (point)) ?\\)))
(forward-line 1))
(when (equal (char-before) ?\\)
(point-marker)))))
(point-marker))))
(defun python-info-beginning-of-backslash (&optional line-number)
"Return the point where the backslashed line start.
Optional argument LINE-NUMBER forces the line number to check against."
(save-excursion
(save-restriction
(prog-widen)
(when line-number
(python-util-goto-line line-number))
(when (python-info-line-ends-backslash-p)
@ -4835,15 +4821,13 @@ Optional argument LINE-NUMBER forces the line number to check against."
(python-syntax-context 'paren))
(forward-line -1))
(back-to-indentation)
(point-marker)))))
(point-marker))))
(defun python-info-continuation-line-p ()
"Check if current line is continuation of another.
When current line is continuation of another return the point
where the continued line ends."
(save-excursion
(save-restriction
(prog-widen)
(let* ((context-type (progn
(back-to-indentation)
(python-syntax-context-type)))
@ -4869,7 +4853,7 @@ where the continued line ends."
(python-util-forward-comment -1)
(when (and (equal (1- line-start) (line-number-at-pos))
(python-info-line-ends-backslash-p))
(point-marker))))))))
(point-marker)))))))
(defun python-info-block-continuation-line-p ()
"Return non-nil if current line is a continuation of a block."