mirror of
https://git.savannah.gnu.org/git/emacs.git
synced 2024-12-01 08:17:38 +00:00
(c-indent-new-comment-line): Added a kludge
similar to the one in c-fill-paragraph to check the fill prefix from the adaptive fill function for sanity. (c-electric-brace): Fixed some bugs in the state handling that caused class open lines to be recognized as statement-conts in some cases. (c-indent-new-comment-line): Keep the fill prefix guessed by the adaptive fill function unless point is on the first line of a block comment. (c-indent-command): Obey c-syntactic-indentation. (c-electric-brace, c-electric-slash, c-electric-star, c-electric-semi&comma, c-electric-colon, c-electric-lt-gt, c-electric-paren): Don't reindent old lines when c-syntactic-indentation is nil. (c-fill-paragraph): Keep one or two spaces between the text and the block comment ender when it hangs, depending on how many there are before the fill. (c-indent-new-comment-line): Always break multiline comments in multiline mode, regardless of comment-multi-line.
This commit is contained in:
parent
6862d61353
commit
b8ded7944c
@ -1,8 +1,9 @@
|
||||
;;; cc-cmds.el --- user level commands for CC Mode
|
||||
|
||||
;; Copyright (C) 1985,1987,1992-1999 Free Software Foundation, Inc.
|
||||
;; Copyright (C) 1985,1987,1992-2000 Free Software Foundation, Inc.
|
||||
|
||||
;; Authors: 1998-1999 Barry A. Warsaw and Martin Stjernholm
|
||||
;; Authors: 2000- Martin Stjernholm
|
||||
;; 1998-1999 Barry A. Warsaw and Martin Stjernholm
|
||||
;; 1992-1997 Barry A. Warsaw
|
||||
;; 1987 Dave Detlefs and Stewart Clamen
|
||||
;; 1985 Richard M. Stallman
|
||||
@ -184,8 +185,9 @@ or \"/ah\" string on the mode line, newlines are inserted before and
|
||||
after braces based on the value of `c-hanging-braces-alist'.
|
||||
|
||||
Also, the line is re-indented unless a numeric ARG is supplied, there
|
||||
are non-whitespace characters present on the line after the brace, or
|
||||
the brace is inserted inside a literal.
|
||||
are non-whitespace characters present on the line after the brace, the
|
||||
brace is inserted inside a literal, or `c-syntactic-indentation' is
|
||||
nil.
|
||||
|
||||
This function does various newline cleanups based on the value of
|
||||
`c-cleanup-list'."
|
||||
@ -232,6 +234,8 @@ This function does various newline cleanups based on the value of
|
||||
(not (bolp)))
|
||||
(progn (newline)
|
||||
(setq delete-temp-newline t)))
|
||||
(if (eq last-command-char ?{)
|
||||
(setq c-state-cache (cons (point) c-state-cache)))
|
||||
(self-insert-command (prefix-numeric-value arg))
|
||||
;; state cache doesn't change
|
||||
(c-guess-basic-syntax)))
|
||||
@ -291,7 +295,8 @@ This function does various newline cleanups based on the value of
|
||||
t))))
|
||||
(setq c-state-cache
|
||||
(c-hack-state (point) 'open c-state-cache)))))
|
||||
(c-indent-line))
|
||||
(if c-syntactic-indentation
|
||||
(c-indent-line)))
|
||||
(setq c-state-cache (c-adjust-state (c-point 'bol) here
|
||||
(- (point) (c-point 'bol))
|
||||
c-state-cache))
|
||||
@ -308,6 +313,7 @@ This function does various newline cleanups based on the value of
|
||||
;; at least one space.
|
||||
(delete-indentation)
|
||||
(just-one-space)
|
||||
(setq c-state-cache (c-whack-state (point) c-state-cache))
|
||||
(if (not preserve-p)
|
||||
(delete-char -1))))
|
||||
;; since we're hanging the brace, we need to recalculate
|
||||
@ -318,8 +324,7 @@ This function does various newline cleanups based on the value of
|
||||
(save-excursion
|
||||
(let ((bol (c-point 'bol)))
|
||||
(if (zerop (car (parse-partial-sexp bol (1- (point)))))
|
||||
(setq c-state-cache (c-whack-state bol c-state-cache)
|
||||
syntax (c-guess-basic-syntax))
|
||||
(setq syntax (c-guess-basic-syntax))
|
||||
;; gotta punt. this requires some horrible kludgery
|
||||
(beginning-of-line)
|
||||
(makunbound 'c-state-cache)
|
||||
@ -411,11 +416,12 @@ Indent the line as a comment, if:
|
||||
2. The slash is part of a `*/' token that closes a block oriented
|
||||
comment.
|
||||
|
||||
If numeric ARG is supplied or point is inside a literal, indentation
|
||||
is inhibited."
|
||||
If a numeric ARG is supplied, point is inside a literal, or
|
||||
`c-syntactic-indentation' is nil, indentation is inhibited."
|
||||
(interactive "*P")
|
||||
(let* ((ch (char-before))
|
||||
(indentp (and (not arg)
|
||||
(indentp (and c-syntactic-indentation
|
||||
(not arg)
|
||||
(eq last-command-char ?/)
|
||||
(or (and (eq ch ?/)
|
||||
(not (c-in-literal)))
|
||||
@ -432,13 +438,14 @@ is inhibited."
|
||||
"Insert a star character.
|
||||
If the star is the second character of a C style comment introducing
|
||||
construct, and we are on a comment-only-line, indent line as comment.
|
||||
If numeric ARG is supplied or point is inside a literal, indentation
|
||||
is inhibited."
|
||||
If a numeric ARG is supplied, point is inside a literal, or
|
||||
`c-syntactic-indentation' is nil, indentation is inhibited."
|
||||
(interactive "*P")
|
||||
(self-insert-command (prefix-numeric-value arg))
|
||||
;; if we are in a literal, or if arg is given do not re-indent the
|
||||
;; current line, unless this star introduces a comment-only line.
|
||||
(if (and (not arg)
|
||||
(if (and c-syntactic-indentation
|
||||
(not arg)
|
||||
(memq (c-in-literal) '(c))
|
||||
(eq (char-before) ?*)
|
||||
(save-excursion
|
||||
@ -462,7 +469,8 @@ is determined.
|
||||
|
||||
When semicolon is inserted, the line is re-indented unless a numeric
|
||||
arg is supplied, point is inside a literal, or there are
|
||||
non-whitespace characters on the line following the semicolon.
|
||||
non-whitespace characters on the line following the semicolon, or
|
||||
`c-syntactic-indentation' is nil.
|
||||
|
||||
Based on the value of `c-cleanup-list', this function cleans up commas
|
||||
following brace lists and semicolons following defuns."
|
||||
@ -481,7 +489,8 @@ following brace lists and semicolons following defuns."
|
||||
;; do all cleanups and newline insertions if c-auto-newline is
|
||||
;; turned on
|
||||
(if (not c-auto-newline)
|
||||
(c-indent-line)
|
||||
(if c-syntactic-indentation
|
||||
(c-indent-line))
|
||||
;; clean ups
|
||||
(let ((pos (- (point-max) (point))))
|
||||
(if (and (or (and
|
||||
@ -499,7 +508,8 @@ following brace lists and semicolons following defuns."
|
||||
(delete-region (point) here))
|
||||
(goto-char (- (point-max) pos)))
|
||||
;; re-indent line
|
||||
(c-indent-line)
|
||||
(if c-syntactic-indentation
|
||||
(c-indent-line))
|
||||
;; check to see if a newline should be added
|
||||
(let ((criteria c-hanging-semi&comma-criteria)
|
||||
answer add-newline-p)
|
||||
@ -525,8 +535,9 @@ or \"/ah\" string on the mode line, newlines are inserted before and
|
||||
after colons based on the value of `c-hanging-colons-alist'.
|
||||
|
||||
Also, the line is re-indented unless a numeric ARG is supplied, there
|
||||
are non-whitespace characters present on the line after the colon, or
|
||||
the colon is inserted inside a literal.
|
||||
are non-whitespace characters present on the line after the colon, the
|
||||
colon is inserted inside a literal, or `c-syntactic-indentation' is
|
||||
nil.
|
||||
|
||||
This function cleans up double colon scope operators based on the
|
||||
value of `c-cleanup-list'."
|
||||
@ -574,8 +585,9 @@ value of `c-cleanup-list'."
|
||||
(c-guess-basic-syntax)
|
||||
(delete-char -1)))
|
||||
c-hanging-colons-alist))))
|
||||
;; indent the current line
|
||||
(c-indent-line syntax)
|
||||
;; indent the current line if it's done syntactically.
|
||||
(if c-syntactic-indentation
|
||||
(c-indent-line syntax))
|
||||
;; does a newline go before the colon? Watch out for already
|
||||
;; non-hung colons. However, we don't unhang them because that
|
||||
;; would be a cleanup (and anti-social).
|
||||
@ -601,10 +613,12 @@ value of `c-cleanup-list'."
|
||||
"Insert a less-than, or greater-than character.
|
||||
The line will be re-indented if the character inserted is the second
|
||||
of a C++ style stream operator and the buffer is in C++ mode.
|
||||
Exceptions are when a numeric argument is supplied, or point is inside
|
||||
a literal, in which case the line will not be re-indented."
|
||||
Exceptions are when a numeric argument is supplied, point is inside a
|
||||
literal, or `c-syntactic-indentation' is nil, in which case the line
|
||||
will not be re-indented."
|
||||
(interactive "*P")
|
||||
(let ((indentp (and (not arg)
|
||||
(let ((indentp (and c-syntactic-indentation
|
||||
(not arg)
|
||||
(eq (char-before) last-command-char)
|
||||
(not (c-in-literal))))
|
||||
;; shut this up
|
||||
@ -622,7 +636,8 @@ appropriate; see the variable `c-cleanup-list'.
|
||||
|
||||
Also, the line is re-indented unless a numeric ARG is supplied, there
|
||||
are non-whitespace characters present on the line after the
|
||||
parenthesis, or the parenthesis is inserted inside a literal."
|
||||
parenthesis, the parenthesis is inserted inside a literal, or
|
||||
`c-syntactic-indentation' is nil."
|
||||
(interactive "*P")
|
||||
(let (;; shut this up
|
||||
(c-echo-syntactic-information-p nil))
|
||||
@ -637,7 +652,8 @@ parenthesis, or the parenthesis is inserted inside a literal."
|
||||
(old-blink-paren blink-paren-function)
|
||||
blink-paren-function)
|
||||
(self-insert-command (prefix-numeric-value arg))
|
||||
(c-indent-line)
|
||||
(if c-syntactic-indentation
|
||||
(c-indent-line))
|
||||
(when c-auto-newline
|
||||
;; Do all appropriate clean ups
|
||||
(let ((here (point))
|
||||
@ -1299,7 +1315,7 @@ treated as conditional clause limits. Normally they are ignored."
|
||||
|
||||
|
||||
;; commands to indent lines, regions, defuns, and expressions
|
||||
(defun c-indent-command (&optional whole-exp)
|
||||
(defun c-indent-command (&optional arg)
|
||||
"Indent current line as C code, and/or insert some whitespace.
|
||||
|
||||
If `c-tab-always-indent' is t, always just indent the current line.
|
||||
@ -1309,10 +1325,16 @@ other than nil or t, then some whitespace[*] is inserted only within
|
||||
literals (comments and strings) and inside preprocessor directives,
|
||||
but the line is always reindented.
|
||||
|
||||
A numeric argument, regardless of its value, means indent rigidly all
|
||||
the lines of the expression starting after point so that this line
|
||||
becomes properly indented. The relative indentation among the lines
|
||||
of the expression is preserved.
|
||||
If `c-syntactic-indentation' is t, indentation is done according to
|
||||
the syntactic context. If it's nil, the line is just indented one
|
||||
step according to `c-basic-offset'. In this mode, a numeric argument
|
||||
indents a number of such steps, positive or negative, and an empty
|
||||
prefix argument is equivalent to -1.
|
||||
|
||||
If `c-syntactic-indentation' is t, then a numeric argument, regardless
|
||||
of its value, means indent rigidly all the lines of the expression
|
||||
starting after point so that this line becomes properly indented. The
|
||||
relative indentation among the lines of the expression is preserved.
|
||||
|
||||
[*] The amount and kind of whitespace inserted is controlled by the
|
||||
variable `c-insert-tab-function', which is called to do the actual
|
||||
@ -1320,11 +1342,21 @@ of the expression is preserved.
|
||||
just inserts a tab character, or the equivalent number of spaces,
|
||||
depending on the variable `indent-tabs-mode'."
|
||||
|
||||
(interactive "P")
|
||||
(let ((bod (c-point 'bod)))
|
||||
(if whole-exp
|
||||
;; If arg, always indent this line as C
|
||||
;; and shift remaining lines of expression the same amount.
|
||||
(interactive "p")
|
||||
(let ((bod (c-point 'bod))
|
||||
(indent-function
|
||||
(if c-syntactic-indentation
|
||||
(symbol-function 'c-indent-line)
|
||||
(lambda ()
|
||||
(let ((steps (cond ((not current-prefix-arg) 1)
|
||||
((equal current-prefix-arg '(4)) -1)
|
||||
(t arg))))
|
||||
(c-shift-line-indentation (* steps c-basic-offset)))
|
||||
))))
|
||||
(if (and c-syntactic-indentation current-prefix-arg)
|
||||
;; If c-syntactic-indentation and got arg, always indent this
|
||||
;; line as C and shift remaining lines of expression the same
|
||||
;; amount.
|
||||
(let ((shift-amt (c-indent-line))
|
||||
beg end)
|
||||
(save-excursion
|
||||
@ -1338,8 +1370,7 @@ of the expression is preserved.
|
||||
(setq beg (point)))
|
||||
(if (> end beg)
|
||||
(indent-code-rigidly beg end (- shift-amt) "#")))
|
||||
;; No arg supplied, use c-tab-always-indent to determine
|
||||
;; behavior
|
||||
;; Else use c-tab-always-indent to determine behavior.
|
||||
(cond
|
||||
;; CASE 1: indent when at column zero or in lines indentation,
|
||||
;; otherwise insert a tab
|
||||
@ -1348,20 +1379,20 @@ of the expression is preserved.
|
||||
(skip-chars-backward " \t")
|
||||
(not (bolp)))
|
||||
(funcall c-insert-tab-function)
|
||||
(c-indent-line)))
|
||||
(funcall indent-function)))
|
||||
;; CASE 2: just indent the line
|
||||
((eq c-tab-always-indent t)
|
||||
(c-indent-line))
|
||||
(funcall indent-function))
|
||||
;; CASE 3: if in a literal, insert a tab, but always indent the
|
||||
;; line
|
||||
(t
|
||||
(if (c-in-literal bod)
|
||||
(funcall c-insert-tab-function))
|
||||
(c-indent-line)
|
||||
(funcall indent-function)
|
||||
)))))
|
||||
|
||||
(defun c-indent-exp (&optional shutup-p)
|
||||
"Indent each line in balanced expression following point.
|
||||
"Indent each line in balanced expression following point syntactically.
|
||||
Optional SHUTUP-P if non-nil, inhibits message printing and error checking."
|
||||
(interactive "*P")
|
||||
(let ((here (point-marker))
|
||||
@ -1411,7 +1442,8 @@ Optional SHUTUP-P if non-nil, inhibits message printing and error checking."
|
||||
(set-marker here nil))))
|
||||
|
||||
(defun c-indent-defun ()
|
||||
"Re-indents the current top-level function def, struct or class declaration."
|
||||
"Re-indents the current top-level function def, struct or class declaration
|
||||
syntactically."
|
||||
(interactive "*")
|
||||
(let ((here (point-marker))
|
||||
(c-echo-syntactic-information-p nil)
|
||||
@ -2221,9 +2253,9 @@ Warning: `c-comment-prefix-regexp' doesn't match the comment prefix %S"
|
||||
If inside a comment and `comment-multi-line' is non-nil, the
|
||||
indentation and line prefix are preserved (see the
|
||||
`c-comment-prefix-regexp' and `c-block-comment-prefix' variables for
|
||||
details). If inside a comment and `comment-multi-line' is nil, a new
|
||||
comment of the same type is started on the next line and indented as
|
||||
appropriate for comments.
|
||||
details). If inside a single line comment and `comment-multi-line' is
|
||||
nil, a new comment of the same type is started on the next line and
|
||||
indented as appropriate for comments.
|
||||
|
||||
If a fill prefix is specified, it overrides all the above."
|
||||
(interactive)
|
||||
@ -2252,8 +2284,20 @@ If a fill prefix is specified, it overrides all the above."
|
||||
(t c-lit-type))
|
||||
c-ignore-auto-fill)
|
||||
(setq fill-prefix t) ; Used as flag in the cond.
|
||||
(if (null c-auto-fill-prefix)
|
||||
(setq fill-prefix nil))))
|
||||
(if (and (null c-auto-fill-prefix)
|
||||
(eq c-lit-type 'c)
|
||||
(<= (c-point 'bol) (car c-lit-limits)))
|
||||
;; The adaptive fill function has generated a prefix, but
|
||||
;; we're on the first line in a block comment so it'll be
|
||||
;; wrong. Ignore it to guess a better one below.
|
||||
(setq fill-prefix nil)
|
||||
(when (and (eq c-lit-type 'c++)
|
||||
(not (string-match "\\`[ \t]*//" (or fill-prefix ""))))
|
||||
;; Kludge: If the function that adapted the fill prefix
|
||||
;; doesn't produce the required comment starter for line
|
||||
;; comments, then we ignore it.
|
||||
(setq fill-prefix nil)))
|
||||
))
|
||||
(cond ((eq fill-prefix t)
|
||||
;; A call from do-auto-fill which should be ignored.
|
||||
)
|
||||
@ -2267,7 +2311,11 @@ If a fill prefix is specified, it overrides all the above."
|
||||
(unless c-lit-type
|
||||
(setq c-lit-type (c-literal-type c-lit-limits)))
|
||||
(memq c-lit-type '(c c++)))
|
||||
(if comment-multi-line
|
||||
(if (or comment-multi-line
|
||||
(save-excursion
|
||||
(goto-char (car c-lit-limits))
|
||||
(end-of-line)
|
||||
(< (point) (cdr c-lit-limits))))
|
||||
;; Inside a comment that should be continued.
|
||||
(let ((fill (c-guess-fill-prefix
|
||||
(setq c-lit-limits
|
||||
|
Loading…
Reference in New Issue
Block a user