unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#15089: awk-mode indentation of line after /= statement with comment
@ 2013-08-13 19:08 ` Glenn Morris
  2013-08-15 16:39   ` bug#15089: awk-mode indentation of line after /= statement with?comment Alan Mackenzie
  2013-08-17 16:00   ` bug#15089: awk-mode indentation of line after /= statement with comment Alan Mackenzie
  0 siblings, 2 replies; 6+ messages in thread
From: Glenn Morris @ 2013-08-13 19:08 UTC (permalink / raw)
  To: 15089

Package: emacs,cc-mode
Version: 24.3
Severity: minor

emacs -Q foo.awk

Enter buffer contents:

#!/usr/bin/gawk -f
BEGIN {
   x = 4
   x /= 2    # comment
        y = 3
   print x, y
}

Use TAB to indent each line. The "y =" line is indented too much.
No such problem with +=, -=, etc; only with /=. And only if a comment
after if (actually, only if whitespace after "/= 2", it seems).





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#15089: awk-mode indentation of line after /= statement with?comment
  2013-08-13 19:08 ` bug#15089: awk-mode indentation of line after /= statement with comment Glenn Morris
@ 2013-08-15 16:39   ` Alan Mackenzie
  2013-08-17 16:00   ` bug#15089: awk-mode indentation of line after /= statement with comment Alan Mackenzie
  1 sibling, 0 replies; 6+ messages in thread
From: Alan Mackenzie @ 2013-08-15 16:39 UTC (permalink / raw)
  To: gnu-emacs-bug

Glenn Morris <rgm@gnu.org> wrote:
> Package: emacs,cc-mode
> Version: 24.3
> Severity: minor

> emacs -Q foo.awk

> Enter buffer contents:

> #!/usr/bin/gawk -f
> BEGIN {
>   x = 4
>   x /= 2    # comment
>        y = 3
>   print x, y
> }

> Use TAB to indent each line. The "y =" line is indented too much.
> No such problem with +=, -=, etc; only with /=. And only if a comment
> after if (actually, only if whitespace after "/= 2", it seems).

Yes.  The function `c-awk-at-vsemi-p' which detects being "at a virtual
semicolon" is too simplistically written, and it is mistaking the "/" for
an opening regexp delimiter.

I'll get it fixed.

-- 
Alan Mackenzie (Nuremberg, Germany).







^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#15089: awk-mode indentation of line after /= statement with comment
  2013-08-13 19:08 ` bug#15089: awk-mode indentation of line after /= statement with comment Glenn Morris
  2013-08-15 16:39   ` bug#15089: awk-mode indentation of line after /= statement with?comment Alan Mackenzie
@ 2013-08-17 16:00   ` Alan Mackenzie
  2013-08-20  6:57     ` Glenn Morris
  1 sibling, 1 reply; 6+ messages in thread
From: Alan Mackenzie @ 2013-08-17 16:00 UTC (permalink / raw)
  To: Glenn Morris; +Cc: 15089

Hi, Glenn.

On Tue, Aug 13, 2013 at 03:08:18PM -0400, Glenn Morris wrote:
> Package: emacs,cc-mode
> Version: 24.3
> Severity: minor

> emacs -Q foo.awk

> Enter buffer contents:

> #!/usr/bin/gawk -f
> BEGIN {
>    x = 4
>    x /= 2    # comment
>         y = 3
>    print x, y
> }

> Use TAB to indent each line. The "y =" line is indented too much.
> No such problem with +=, -=, etc; only with /=. And only if a comment
> after if (actually, only if whitespace after "/= 2", it seems).

The following patch should fix the bug.  A simple recompilation of
cc-{awk,engine}.el is OK.  Would you try it out, please.  Thanks!



=== modified file 'lisp/progmodes/cc-awk.el'
*** lisp/progmodes/cc-awk.el	2013-02-02 06:04:06 +0000
--- lisp/progmodes/cc-awk.el	2013-08-17 15:49:19 +0000
***************
*** 169,177 ****
    (concat "\\=_?\"" c-awk-string-innards-re))
  ;;   Matches an AWK string at point up to, but not including, any terminator.
  ;; A gawk 3.1+ string may look like _"localizable string".
! (defconst c-awk-one-line-possibly-open-string-re
!   (concat "\"\\(" c-awk-string-ch-re "\\|" c-awk-non-eol-esc-pair-re "\\)*"
! 	  "\\(\"\\|\\\\?$\\|\\'\\)"))
  
  ;; REGEXPS FOR AWK REGEXPS.
  (defconst c-awk-regexp-normal-re "[^[/\\\n\r]")
--- 169,177 ----
    (concat "\\=_?\"" c-awk-string-innards-re))
  ;;   Matches an AWK string at point up to, but not including, any terminator.
  ;; A gawk 3.1+ string may look like _"localizable string".
! (defconst c-awk-possibly-open-string-re
!   (concat "\"\\(" c-awk-string-ch-re "\\|" c-awk-esc-pair-re "\\)*"
! 	  "\\(\"\\|$\\|\\'\\)"))
  
  ;; REGEXPS FOR AWK REGEXPS.
  (defconst c-awk-regexp-normal-re "[^[/\\\n\r]")
***************
*** 192,216 ****
  	  "\\|" "[^]\n\r]" "\\)*" "\\(]\\|$\\)"))
  ;;   Matches a regexp char list, up to (but not including) EOL if the ] is
  ;;   missing.
- (defconst c-awk-regexp-one-line-possibly-open-char-list-re
-   (concat "\\[\\]?\\(" c-awk-non-eol-esc-pair-re "\\|" "[^]\n\r]" "\\)*"
- 	  "\\(]\\|\\\\?$\\|\\'\\)"))
- ;;   Matches the head (or all) of a regexp char class, up to (but not
- ;;   including) the first EOL.
  (defconst c-awk-regexp-innards-re
    (concat "\\(" c-awk-esc-pair-re "\\|" c-awk-regexp-char-list-re
!           "\\|" c-awk-regexp-normal-re "\\)*"))
  ;;   Matches the inside of an AWK regexp (i.e. without the enclosing /s)
  (defconst c-awk-regexp-without-end-re
    (concat "/" c-awk-regexp-innards-re))
  ;; Matches an AWK regexp up to, but not including, any terminating /.
- (defconst c-awk-one-line-possibly-open-regexp-re
-   (concat "/\\(" c-awk-non-eol-esc-pair-re
- 	  "\\|" c-awk-regexp-one-line-possibly-open-char-list-re
- 	  "\\|" c-awk-regexp-normal-re "\\)*"
- 	  "\\(/\\|\\\\?$\\|\\'\\)"))
- ;; Matches as much of the head of an AWK regexp which fits on one line,
- ;; possibly all of it.
  
  ;; REGEXPS used for scanning an AWK buffer in order to decide IF A '/' IS A
  ;; REGEXP OPENER OR A DIVISION SIGN.  By "state" in the following is meant
--- 192,204 ----
  	  "\\|" "[^]\n\r]" "\\)*" "\\(]\\|$\\)"))
  ;;   Matches a regexp char list, up to (but not including) EOL if the ] is
  ;;   missing.
  (defconst c-awk-regexp-innards-re
    (concat "\\(" c-awk-esc-pair-re "\\|" c-awk-regexp-char-list-re
! 	  "\\|" c-awk-regexp-normal-re "\\)*"))
  ;;   Matches the inside of an AWK regexp (i.e. without the enclosing /s)
  (defconst c-awk-regexp-without-end-re
    (concat "/" c-awk-regexp-innards-re))
  ;; Matches an AWK regexp up to, but not including, any terminating /.
  
  ;; REGEXPS used for scanning an AWK buffer in order to decide IF A '/' IS A
  ;; REGEXP OPENER OR A DIVISION SIGN.  By "state" in the following is meant
***************
*** 262,276 ****
  
  ;; REGEXPS USED FOR FINDING THE POSITION OF A "virtual semicolon"
  (defconst c-awk-_-harmless-nonws-char-re "[^#/\"\\\\\n\r \t]")
! ;; NEW VERSION!  (which will be restricted to the current line)
! (defconst c-awk-one-line-non-syn-ws*-re
!   (concat "\\([ \t]*"
!               "\\(" c-awk-_-harmless-nonws-char-re "\\|"
! 	            c-awk-non-eol-esc-pair-re "\\|"
! 		    c-awk-one-line-possibly-open-string-re "\\|"
! 		    c-awk-one-line-possibly-open-regexp-re
! 	      "\\)"
!           "\\)*"))
  
  \f
  ;; ACM, 2002/5/29:
--- 250,273 ----
  
  ;; REGEXPS USED FOR FINDING THE POSITION OF A "virtual semicolon"
  (defconst c-awk-_-harmless-nonws-char-re "[^#/\"\\\\\n\r \t]")
! (defconst c-awk-non-/-syn-ws*-re
!   (concat
!    "\\(" c-awk-escaped-nls*-with-space*
!          "\\(" c-awk-_-harmless-nonws-char-re "\\|"
!                c-awk-non-eol-esc-pair-re "\\|"
! 	       c-awk-possibly-open-string-re
!          "\\)"
!    "\\)*"))
! (defconst c-awk-space*-/-re (concat c-awk-escaped-nls*-with-space* "/"))
! ;; Matches optional whitespace followed by "/".
! (defconst c-awk-space*-regexp-/-re
!   (concat c-awk-escaped-nls*-with-space* "\\s\""))
! ;; Matches optional whitespace followed by a "/" with string syntax (a matched
! ;; regexp delimiter).
! (defconst c-awk-space*-unclosed-regexp-/-re
!   (concat c-awk-escaped-nls*-with-space* "\\s\|"))
! ;; Matches optional whitespace followed by a "/" with string fence syntax (an
! ;; unmatched regexp delimiter).
  
  \f
  ;; ACM, 2002/5/29:
***************
*** 549,558 ****
  (defun c-awk-at-vsemi-p (&optional pos)
    ;; Is there a virtual semicolon at POS (or POINT)?
    (save-excursion
!     (let (nl-prop
! 	  (pos-or-point (progn (if pos (goto-char pos)) (point))))
!       (forward-line 0)
!       (search-forward-regexp c-awk-one-line-non-syn-ws*-re)
        (and (eq (point) pos-or-point)
  	   (progn
  	     (while (and (eq (setq nl-prop (c-awk-get-NL-prop-cur-line)) ?\\)
--- 546,581 ----
  (defun c-awk-at-vsemi-p (&optional pos)
    ;; Is there a virtual semicolon at POS (or POINT)?
    (save-excursion
!     (let* (nl-prop
! 	   (pos-or-point (progn (if pos (goto-char pos)) (point)))
! 	   (bol (c-point 'bol)) (eol (c-point 'eol)))
!       (c-awk-beginning-of-logical-line)
!       ;; Next `while' goes round one logical line (ending in, e.g. "\\") per
!       ;; iteration.  Such a line is rare, and can only be an open string
!       ;; ending in an escaped \.
!       (while
! 	  (progn
! 	    ;; Next `while' goes over a division sign or /regexp/ per iteration.
! 	    (while
! 		(and
! 		 (< (point) eol)
! 		 (progn
! 		   (search-forward-regexp c-awk-non-/-syn-ws*-re eol)
! 		   (looking-at c-awk-space*-/-re)))
! 	      (cond
! 	       ((looking-at c-awk-space*-regexp-/-re) ; /regexp/
! 		(forward-sexp))
! 	       ((looking-at c-awk-space*-unclosed-regexp-/-re) ; Unclosed /regexp
! 		(condition-case nil
! 		    (progn
! 		      (forward-sexp)
! 		      (backward-char))	; Move to end of (logical) line.
! 		  (error (end-of-line)))) ; Happens at EOB.
! 	       (t 			; division sign
! 		(c-forward-syntactic-ws)
! 		(forward-char))))
! 	    (< (point) bol))
! 	(forward-line))
        (and (eq (point) pos-or-point)
  	   (progn
  	     (while (and (eq (setq nl-prop (c-awk-get-NL-prop-cur-line)) ?\\)

=== modified file 'lisp/progmodes/cc-engine.el'
*** lisp/progmodes/cc-engine.el	2013-07-27 12:07:43 +0000
--- lisp/progmodes/cc-engine.el	2013-08-17 15:46:12 +0000
***************
*** 1271,1276 ****
--- 1271,1279 ----
  	      (throw 'done (point)))))
  	  ;; In trailing space after an as yet undetected virtual semicolon?
  	  (c-backward-syntactic-ws from)
+ 	  (when (and (bolp) (not (bobp))) ; Can happen in AWK Mode with an
+ 					  ; unterminated string/regexp.
+ 	    (backward-char))
  	  (if (and (< (point) to)
  		   (c-at-vsemi-p))
  	      (point)



-- 
Alan Mackenzie (Nuremberg, Germany).





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#15089: awk-mode indentation of line after /= statement with comment
  2013-08-17 16:00   ` bug#15089: awk-mode indentation of line after /= statement with comment Alan Mackenzie
@ 2013-08-20  6:57     ` Glenn Morris
  2013-08-25 10:18       ` Alan Mackenzie
  0 siblings, 1 reply; 6+ messages in thread
From: Glenn Morris @ 2013-08-20  6:57 UTC (permalink / raw)
  To: Alan Mackenzie; +Cc: 15089


It works thank you. It introduces a new compiler warning, if you're
interested in such things:

  progmodes/cc-awk.el:1150:1:Warning: the function `c-forward-sws' is not
  known to be defined





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#15089: awk-mode indentation of line after /= statement with comment
  2013-08-20  6:57     ` Glenn Morris
@ 2013-08-25 10:18       ` Alan Mackenzie
  2013-08-25 19:08         ` Glenn Morris
  0 siblings, 1 reply; 6+ messages in thread
From: Alan Mackenzie @ 2013-08-25 10:18 UTC (permalink / raw)
  To: Glenn Morris; +Cc: 15089-done

Hi, Glenn.

Bug fixed.

On Tue, Aug 20, 2013 at 02:57:25AM -0400, Glenn Morris wrote:

> It works thank you. It introduces a new compiler warning, if you're
> interested in such things:

>   progmodes/cc-awk.el:1150:1:Warning: the function `c-forward-sws' is not
>   known to be defined

Wierd.  "sws" stands for "syntactic whitespace" and the function is used
all over the place, even though its use is generated from a macro.
Dealing with the compiler warnings is on my (long) TODO list.

-- 
Alan Mackenzie (Nuremberg, Germany).





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#15089: awk-mode indentation of line after /= statement with comment
  2013-08-25 10:18       ` Alan Mackenzie
@ 2013-08-25 19:08         ` Glenn Morris
  0 siblings, 0 replies; 6+ messages in thread
From: Glenn Morris @ 2013-08-25 19:08 UTC (permalink / raw)
  To: Alan Mackenzie; +Cc: 15089

Alan Mackenzie wrote:

>>   progmodes/cc-awk.el:1150:1:Warning: the function `c-forward-sws' is not
>>   known to be defined
>
> Wierd.  "sws" stands for "syntactic whitespace" and the function is used
> all over the place, even though its use is generated from a macro.

cc-awk already has this:

    ;; Some functions in cc-engine that are used below.  There's a cyclic
    ;; dependency so it can't be required here.  (Perhaps some functions
    ;; could be moved to cc-engine to avoid it.)
    (cc-bytecomp-defun c-backward-token-1)
    (cc-bytecomp-defun c-beginning-of-statement-1)
    (cc-bytecomp-defun c-backward-sws)

so I assume you can just add c-forward-sws there.





^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-08-25 19:08 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.3149.1376421825.12400.bug-gnu-emacs@gnu.org>
2013-08-13 19:08 ` bug#15089: awk-mode indentation of line after /= statement with comment Glenn Morris
2013-08-15 16:39   ` bug#15089: awk-mode indentation of line after /= statement with?comment Alan Mackenzie
2013-08-17 16:00   ` bug#15089: awk-mode indentation of line after /= statement with comment Alan Mackenzie
2013-08-20  6:57     ` Glenn Morris
2013-08-25 10:18       ` Alan Mackenzie
2013-08-25 19:08         ` Glenn Morris

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).