Hi, Paul!
On Thu, 13 Oct 2005, Paul Horton wrote:
>To whom it may concern,
Well, there's me and there's Martin Stjernholm. Martin's Swedish, I'm
Scottish.
>My potential bug involves c-indent-command when evoked from this function:
Oh, it's a real bug, no doubt about that. :-)
>(defun test-bug (test-bug-arg)
> (interactive "P")
> (insert-string "}")
> (c-indent-command)
>)
>When interactively invoked with a prefix argument in a C++ mode buffer
>test-bug gives an error like:
>c-indent-command: Scan error: "Containing expression ends prematurely", 3, 4
>where 3 is the character position of the inserted "}" in the buffer.
>No error occurs if a prefix argument is not given.
What is happening is that the prefix argument is being picked up
(wrongly) by `c-indent-command' (which is what <tab> is bound to). A
prefix command to <tab> means (roughly) "indent rigidly the entire
expression that point is at". Trying to find that expression generates
the error.
>Explicitly giving c-indent-command an argument such as with
>(c-indent-command -1) or (c-indent-command 1) does not change
>the behavior.
>Perhaps this indicates a bug?
>I have only tried it on the following four versions:
Only? Wow! That's four times as many versions as most people test bugs
on. ;-)
[ .... ]
Here is a patch for CC Mode 5.30.10 which should fix the bug. I'm
presuming here you know how to install patches, but if you need any help
with this, email me on <acm@...>.
Thank you very much indeed for taking the trouble to report it, and thank
you even more for creating such a concise test case. Do please let us
know if the patch fixes the problem.
Thanks again.
c-indent-command: expunge use of `current-prefix-arg', since this might
be the prefix arg to a command which calls c-indent-command as a function.
Change the interactive spec from "p" to "P".
Index: cc-cmds.el
===================================================================
RCS file: /cvsroot/cc-mode/cc-mode/cc-cmds.el,v
retrieving revision 5.268.2.10
retrieving revision 5.268.2.11
diff -C2 -d -r5.268.2.10 -r5.268.2.11
*** cc-cmds.el 13 Jun 2005 17:26:35 -0000 5.268.2.10
--- cc-cmds.el 31 Oct 2005 19:37:35 -0000 5.268.2.11
***************
*** 1995,1999 ****
depending on the variable `indent-tabs-mode'."
! (interactive "p")
(let ((indent-function
(if c-syntactic-indentation
--- 1995,1999 ----
depending on the variable `indent-tabs-mode'."
! (interactive "P")
(let ((indent-function
(if c-syntactic-indentation
***************
*** 2001,2007 ****
(lambda ()
(let ((c-macro-start c-macro-start)
! (steps (cond ((not current-prefix-arg) 1)
! ((equal current-prefix-arg '(4)) -1)
! (t arg))))
(c-shift-line-indentation (* steps c-basic-offset))
(when (and c-auto-align-backslashes
--- 2001,2007 ----
(lambda ()
(let ((c-macro-start c-macro-start)
! (steps (if (equal arg '(4))
! -1
! (prefix-numeric-value arg))))
(c-shift-line-indentation (* steps c-basic-offset))
(when (and c-auto-align-backslashes
***************
*** 2013,2017 ****
(c-backslash-region (point) (point) nil t)))
))))
! (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
--- 2013,2017 ----
(c-backslash-region (point) (point) nil t)))
))))
! (if (and c-syntactic-indentation arg)
;; If c-syntactic-indentation and got arg, always indent this
;; line as C and shift remaining lines of expression the same
***************
*** 2039,2043 ****
;; 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
((not c-tab-always-indent)
--- 2039,2043 ----
;; Else use c-tab-always-indent to determine behavior.
(cond
! ;; CASE 1: indent when at column zero or in line's indentation,
;; otherwise insert a tab
((not c-tab-always-indent)
--
Alan Mackenzie (Munich, Germany)
|