X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/34dc21db6e57ebbad81a196002fcd3cc557f096e..ab849b7fac5f7a4bb301eb830fa0acc3ad18c18f:/lisp/indent.el diff --git a/lisp/indent.el b/lisp/indent.el index ab38d50296..0bbb5209e8 100644 --- a/lisp/indent.el +++ b/lisp/indent.el @@ -1,6 +1,6 @@ ;;; indent.el --- indentation commands for Emacs -*- lexical-binding:t -*- -;; Copyright (C) 1985, 1995, 2001-2014 Free Software Foundation, Inc. +;; Copyright (C) 1985, 1995, 2001-2016 Free Software Foundation, Inc. ;; Maintainer: emacs-devel@gnu.org ;; Package: emacs @@ -86,6 +86,22 @@ that case, indent by aligning to the previous non-blank line." ;; The normal case. (funcall indent-line-function))) +(defun indent--default-inside-comment () + (unless (or (> (current-column) (current-indentation)) + (eq this-command last-command)) + (let ((ppss (syntax-ppss))) + (when (nth 4 ppss) + (indent-line-to + (save-excursion + (forward-line -1) + (skip-chars-forward " \t") + (when (< (1- (point)) (nth 8 ppss) (line-end-position)) + (goto-char (nth 8 ppss)) + (when (looking-at comment-start-skip) + (goto-char (match-end 0)))) + (current-column))) + t)))) + (defun indent-for-tab-command (&optional arg) "Indent the current line or region, or insert a tab, as appropriate. This function either inserts a tab, or indents the current line, @@ -124,7 +140,11 @@ prefix argument is ignored." (old-indent (current-indentation))) ;; Indent the line. - (funcall indent-line-function) + (or (not (eq (funcall indent-line-function) 'noindent)) + (indent--default-inside-comment) + (when (or (<= (current-column) (current-indentation)) + (not (eq tab-always-indent 'complete))) + (funcall (default-value 'indent-line-function)))) (cond ;; If the text was already indented right, try completion. @@ -249,7 +269,7 @@ indentation by specifying a large negative ARG." (indent-rigidly--pop-undo) (let* ((current (indent-rigidly--current-indentation beg end)) (rtl (eq (current-bidi-paragraph-direction) 'right-to-left)) - (next (indent--next-tab-stop current (if rtl nil 'prev)))) + (next (indent-next-tab-stop current (if rtl nil 'prev)))) (indent-rigidly beg end (- next current)))) (defun indent-rigidly-right-to-tab-stop (beg end) @@ -258,7 +278,7 @@ indentation by specifying a large negative ARG." (indent-rigidly--pop-undo) (let* ((current (indent-rigidly--current-indentation beg end)) (rtl (eq (current-bidi-paragraph-direction) 'right-to-left)) - (next (indent--next-tab-stop current (if rtl 'prev)))) + (next (indent-next-tab-stop current (if rtl 'prev)))) (indent-rigidly beg end (- next current)))) (defun indent-line-to (column) @@ -537,7 +557,7 @@ column to indent to; if it is nil, use one of the three methods above." ;; In most cases, reindenting modifies the buffer, but it may also ;; leave it unmodified, in which case we have to deactivate the mark ;; by hand. - (deactivate-mark)) + (setq deactivate-mark t)) (defun indent-relative-maybe () "Indent a new line like previous nonblank line. @@ -590,7 +610,7 @@ See also `indent-relative-maybe'." "List of tab stop positions used by `tab-to-tab-stop'. This should be nil, or a list of integers, ordered from smallest to largest. It implicitly extends to infinity through repetition of the last step. -For example, '(1 2 5) is equivalent to '(1 2 5 8 11 ...). If the list has +For example, (1 2 5) is equivalent to (1 2 5 8 11 ...). If the list has fewer than 2 elements, `tab-width' is used as the \"last step\". A value of nil means a tab stop every `tab-width' columns." :group 'indent @@ -654,7 +674,7 @@ You can add or remove colons and then do \\\\[edit-tab-stops (setq tab-stop-list tabs)) (message "Tab stops installed")) -(defun indent--next-tab-stop (column &optional prev) +(defun indent-next-tab-stop (column &optional prev) "Return the next tab stop after COLUMN. If PREV is non-nil, return the previous one instead." (let ((tabs tab-stop-list)) @@ -677,6 +697,13 @@ If PREV is non-nil, return the previous one instead." (if (<= column last) -1 (/ (- column last 1) step)) (1+ (/ (- column last) step))))))))) +(defun indent-accumulate-tab-stops (limit) + "Get a list of tab stops before LIMIT (inclusive)." + (let ((tab 0) (tab-stops)) + (while (<= (setq tab (indent-next-tab-stop tab)) limit) + (push tab tab-stops)) + (nreverse tab-stops))) + (defun tab-to-tab-stop () "Insert spaces or tabs to next defined tab-stop column. The variable `tab-stop-list' is a list of columns at which there are tab stops. @@ -684,7 +711,7 @@ Use \\[edit-tab-stops] to edit them interactively." (interactive) (and abbrev-mode (= (char-syntax (preceding-char)) ?w) (expand-abbrev)) - (let ((nexttab (indent--next-tab-stop (current-column)))) + (let ((nexttab (indent-next-tab-stop (current-column)))) (delete-horizontal-space t) (indent-to nexttab))) @@ -693,7 +720,7 @@ Use \\[edit-tab-stops] to edit them interactively." The variable `tab-stop-list' is a list of columns at which there are tab stops. Use \\[edit-tab-stops] to edit them interactively." (interactive) - (let ((nexttab (indent--next-tab-stop (current-column)))) + (let ((nexttab (indent-next-tab-stop (current-column)))) (let ((before (point))) (move-to-column nexttab t) (save-excursion