]> code.delx.au - gnu-emacs/commitdiff
Merge from origin/emacs-25
authorPaul Eggert <eggert@cs.ucla.edu>
Mon, 2 May 2016 17:46:53 +0000 (10:46 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Mon, 2 May 2016 17:46:53 +0000 (10:46 -0700)
bf21c84 Fix quoting problem in cc-engine debug message
8f36614 Add electric-quote-string unit test
6280531 Don’t electrically quote ‘'’ in Python
fd7b430 `nreverse' Grep hits before passing them to xref--convert-hits

1  2 
lisp/progmodes/cc-engine.el
test/lisp/electric-tests.el

index 76a0b201816743235973542e30ec6eb25b5e2aab,eb015acf3200bbf3cd18c7faa4ea7f5e7a51a8f7..d19d2dacda12ab9d1c1a7e573763a9a16277a059
@@@ -1543,7 -1543,7 +1543,7 @@@ comment at the start of cc-engine.el fo
  ;;    two newlines with horizontal whitespace between them.
  ;;
  ;;    The reason to include the first following char is to cope with
 -;;    "rung positions" that doesn't have any ordinary whitespace.  If
 +;;    "rung positions" that don't have any ordinary whitespace.  If
  ;;    `c-is-sws' is put on a token character it does not have
  ;;    `c-in-sws' set simultaneously.  That's the only case when that
  ;;    can occur, and the reason for not extending the `c-in-sws'
      ;; if it's anything that can't start syntactic ws, so we can bail out
      ;; early in the majority of cases when there just are a few ws chars.
      (skip-chars-forward " \t\n\r\f\v")
 -    (when (looking-at c-syntactic-ws-start)
 +    (when (or (looking-at c-syntactic-ws-start)
 +            (and c-opt-cpp-prefix
 +                 (looking-at c-noise-macro-name-re)))
  
        (setq rung-end-pos (min (1+ (point)) (point-max)))
        (if (setq rung-is-marked (text-property-any rung-pos rung-end-pos
        (with-silent-modifications
        (while
          (progn
 +          ;; In the following while form, we move over a "ladder" and
 +          ;; following simple WS each time round the loop, appending the WS
 +          ;; onto the ladder, joining adjacent ladders, and terminating when
 +          ;; there is no more WS or we reach EOB.
            (while
                (when (and rung-is-marked
                           (get-text-property (point) 'c-in-sws))
                            (setq rung-pos (point)
                                  last-put-in-sws-pos rung-pos)))
  
 +          ;; Now move over any comments (x)or a CPP construct.
            (setq simple-ws-end (point))
            (c-forward-comments)
  
              (forward-line 1)
              (setq safe-start t)
              ;; Don't cache at eob in case the buffer is narrowed.
 +            (not (eobp)))
 +
 +           ((and c-opt-cpp-prefix
 +                 (looking-at c-noise-macro-name-re))
 +            ;; Skip over a noise macro.
 +            (goto-char (match-end 1))
 +            (setq safe-start t)
              (not (eobp)))))
  
        ;; We've searched over a piece of non-white syntactic ws.  See if this
      (when (and (not (bobp))
               (save-excursion
                 (backward-char)
 -               (looking-at c-syntactic-ws-end)))
 -
 +               (or (looking-at c-syntactic-ws-end)
 +                   (and c-opt-cpp-prefix
 +                        (looking-at c-symbol-char-key)
 +                        (progn (c-beginning-of-current-token)
 +                               (looking-at c-noise-macro-name-re))))))
        ;; Try to find a rung position in the simple ws preceding point, so that
        ;; we can get a cache hit even if the last bit of the simple ws has
        ;; changed recently.
        (with-silent-modifications
        (while
          (progn
 +          ;; Each time round the next while form, we move back over a ladder
 +          ;; and append any simple WS preceding it, if possible joining with
 +          ;; the previous ladder.
            (while
                (when (and rung-is-marked
                           (not (bobp))
              ;; narrowed out, and we can't risk marking the simple ws
              ;; at the end of it.
              (goto-char next-rung-pos)
 +            t)
 +
 +           ((and c-opt-cpp-prefix
 +                 (save-excursion
 +                   (and (< (skip-syntax-backward "w_") 0)
 +                        (progn (setq next-rung-pos (point))
 +                               (looking-at c-noise-macro-name-re)))))
 +            ;; Skipped over a noise macro
 +            (goto-char next-rung-pos)
              t)))
  
        ;; We've searched over a piece of non-white syntactic ws.  See if this
           c-state-old-cpp-end
           c-parse-state-point))))
  (defun c-replay-parse-state-state ()
-   (message
+   (message "%s"
     (concat "(setq "
      (mapconcat
       (lambda (arg)
@@@ -5840,16 -5811,13 +5840,16 @@@ comment at the start of cc-engine.el fo
                               `(c-forward-type)
                             `(c-forward-name)))
                nil
 -            (and (looking-at c-keywords-regexp)
 -                 (c-forward-keyword-clause 1))))
 +            (cond ((looking-at c-keywords-regexp)
 +                   (c-forward-keyword-clause 1))
 +                  ((and c-opt-cpp-prefix
 +                        (looking-at c-noise-macro-with-parens-name-re))
 +                   (c-forward-noise-clause)))))
       (when (memq res '(t known found prefix maybe))
         (when c-record-type-identifiers
 -       ,(if (eq type 'type)
 -            `(c-record-type-id c-last-identifier-range)
 -          `(c-record-ref-id c-last-identifier-range)))
 +        ,(if (eq type 'type)
 +             `(c-record-type-id c-last-identifier-range)
 +           `(c-record-ref-id c-last-identifier-range)))
         t)))
  
  (defmacro c-forward-id-comma-list (type update-safe-pos)
                 (c-forward-syntactic-ws)
                 (c-forward-keyword-prefixed-id ,type)))))
  
 +(defun c-forward-noise-clause ()
 +  ;; Point is at a c-noise-macro-with-parens-names macro identifier.  Go
 +  ;; forward over this name, any parenthesis expression which follows it, and
 +  ;; any syntactic WS, ending up at the next token.  If there is an unbalanced
 +  ;; paren expression, leave point at it.  Always Return t.
 +  (c-forward-token-2)
 +  (if (and (eq (char-after) ?\()
 +         (c-go-list-forward))
 +      (c-forward-syntactic-ws))
 +  t)
 +
  (defun c-forward-keyword-clause (match)
    ;; Submatch MATCH in the current match data is assumed to surround a
    ;; token.  If it's a keyword, move over it and any immediately
                  ;; `nconc' doesn't mind that the tail of
                  ;; `c-record-found-types' is t.
                  (nconc c-record-found-types c-record-type-identifiers)))
 -          (if (c-major-mode-is 'java-mode) (c-fontify-recorded-types-and-refs))
          t)
  
        (goto-char start)
                (progn
                  (c-forward-syntactic-ws)
                  (when (or (and c-record-type-identifiers all-types)
 -                          (c-major-mode-is 'java-mode))
 -                  ;; All encountered identifiers are types, so set the
 -                  ;; promote flag and parse the type.
 -                  (progn
 -                    (c-forward-syntactic-ws)
 -                    (if (looking-at "\\?")
 -                        (forward-char)
 -                      (when (looking-at c-identifier-start)
 +                          (not (equal c-inside-<>-type-key "\\(\\<\\>\\)")))
 +                  (c-forward-syntactic-ws)
 +                  (cond
 +                   ((eq (char-after) ??)
 +                    (forward-char))
 +                   ((and (looking-at c-identifier-start)
 +                         (not (looking-at c-keywords-regexp)))
 +                    (if (or (and all-types c-record-type-identifiers)
 +                            (c-major-mode-is 'java-mode))
 +                        ;; All encountered identifiers are types, so set the
 +                        ;; promote flag and parse the type.
                          (let ((c-promote-possible-types t)
                                (c-record-found-types t))
 -                          (c-forward-type))))
 +                          (c-forward-type))
 +                      (c-forward-token-2))))
  
 -                    (c-forward-syntactic-ws)
 +                  (c-forward-syntactic-ws)
  
 -                    (when (or (looking-at "extends")
 -                              (looking-at "super"))
 -                      (forward-word-strictly)
 -                      (c-forward-syntactic-ws)
 -                      (let ((c-promote-possible-types t)
 -                            (c-record-found-types t))
 -                        (c-forward-type)
 -                        (c-forward-syntactic-ws)))))
 +                  (when (looking-at c-inside-<>-type-key)
 +                    (goto-char (match-end 1))
 +                    (c-forward-syntactic-ws)
 +                    (let ((c-promote-possible-types t)
 +                          (c-record-found-types t))
 +                      (c-forward-type))
 +                    (c-forward-syntactic-ws)))
  
                  (setq pos (point))    ; e.g. first token inside the '<'
  
              ((and c-recognize-<>-arglists
                    (eq (char-after) ?<))
               ;; Maybe an angle bracket arglist.
 -             (when (let ((c-record-type-identifiers t)
 -                         (c-record-found-types t)
 -                         (c-last-identifier-range))
 +             (when (let (c-last-identifier-range)
                       (c-forward-<>-arglist nil))
  
                 (c-forward-syntactic-ws)
                                     ; "typedef".
        (goto-char (match-end 1))
        (c-forward-syntactic-ws)
 +
 +      (while (cond
 +            ((looking-at c-decl-hangon-key)
 +             (c-forward-keyword-clause 1))
 +            ((and c-opt-cpp-prefix
 +                  (looking-at c-noise-macro-with-parens-name-re))
 +             (c-forward-noise-clause))))
 +
        (setq pos (point))
  
        (setq name-res (c-forward-name))
           ;; of the while.  These are, e.g. "*" in "int *foo" or "(" and
           ;; "*" in "int (*foo) (void)" (Note similar code in
           ;; `c-forward-decl-or-cast-1'.)
 -         (while (and (looking-at c-type-decl-prefix-key)
 -                     (if (and (c-major-mode-is 'c++-mode)
 -                              (match-beginning 3))
 -                         ;; If the third submatch matches in C++ then
 -                         ;; we're looking at an identifier that's a
 -                         ;; prefix only if it specifies a member pointer.
 -                         (progn
 -                           (setq id-start (point))
 -                           (c-forward-name)
 -                           (if (looking-at "\\(::\\)")
 -                               ;; We only check for a trailing "::" and
 -                               ;; let the "*" that should follow be
 -                               ;; matched in the next round.
 -                               t
 -                             ;; It turned out to be the real identifier,
 -                             ;; so flag that and stop.
 -                             (setq got-identifier t)
 -                             nil))
 -                       t))
 -           (if (eq (char-after) ?\()
 -               (progn
 -                 (setq paren-depth (1+ paren-depth))
 -                 (forward-char))
 -             (goto-char (match-end 1)))
 -           (c-forward-syntactic-ws))
 +            (while
 +                (cond
 +                 ((looking-at c-decl-hangon-key)
 +                  (c-forward-keyword-clause 1))
 +                 ((and c-opt-cpp-prefix
 +                       (looking-at c-noise-macro-with-parens-name-re))
 +                  (c-forward-noise-clause))
 +                 ((and (looking-at c-type-decl-prefix-key)
 +                       (if (and (c-major-mode-is 'c++-mode)
 +                                (match-beginning 3))
 +                           ;; If the third submatch matches in C++ then
 +                           ;; we're looking at an identifier that's a
 +                           ;; prefix only if it specifies a member pointer.
 +                           (progn
 +                             (setq id-start (point))
 +                             (c-forward-name)
 +                             (if (looking-at "\\(::\\)")
 +                                 ;; We only check for a trailing "::" and
 +                                 ;; let the "*" that should follow be
 +                                 ;; matched in the next round.
 +                                 t
 +                               ;; It turned out to be the real identifier,
 +                               ;; so flag that and stop.
 +                               (setq got-identifier t)
 +                               nil))
 +                         t))
 +                  (if (eq (char-after) ?\()
 +                      (progn
 +                        (setq paren-depth (1+ paren-depth))
 +                        (forward-char))
 +                    (goto-char (match-end 1)))
 +                  (c-forward-syntactic-ws)
 +                  t)))
  
           ;; If we haven't passed the identifier already, do it now.
           (unless got-identifier
  
         ;; Skip over any trailing bit, such as "__attribute__".
         (progn
 -         (when (looking-at c-decl-hangon-key)
 -           (c-forward-keyword-clause 1))
 -         (<= (point) limit))
 +            (while (cond
 +                    ((looking-at c-decl-hangon-key)
 +                     (c-forward-keyword-clause 1))
 +                    ((and c-opt-cpp-prefix
 +                          (looking-at c-noise-macro-with-parens-name-re))
 +                     (c-forward-noise-clause))))
 +            (<= (point) limit))
  
         ;; Search syntactically to the end of the declarator (";",
         ;; ",", a closing paren, eob etc) or to the beginning of an
        cast-end
        ;; Have we got a new-style C++11 "auto"?
        new-style-auto
 +      ;; Set when the symbol before `preceding-token-end' is known to
 +      ;; terminate the previous construct, or when we're at point-min.
 +      at-decl-start
        ;; Save `c-record-type-identifiers' and
        ;; `c-record-ref-identifiers' since ranges are recorded
        ;; speculatively and should be thrown away if it turns out
        (save-rec-type-ids c-record-type-identifiers)
        (save-rec-ref-ids c-record-ref-identifiers))
  
 +    (save-excursion
 +      (goto-char preceding-token-end)
 +      (setq at-decl-start
 +          (or (bobp)
 +              (let ((tok-end (point)))
 +                (c-backward-token-2)
 +                (member (buffer-substring-no-properties (point) tok-end)
 +                        c-pre-start-tokens)))))
 +
      (while (c-forward-annotation)
        (c-forward-syntactic-ws))
  
      ;; macros like __INLINE__, so we recognize both types and known
      ;; specifiers after them too.
      (while
 -      (let* ((start (point)) kwd-sym kwd-clause-end found-type)
 +      (let* ((start (point)) kwd-sym kwd-clause-end found-type noise-start)
  
 +        (cond
          ;; Look for a specifier keyword clause.
 -        (when (or (looking-at c-prefix-spec-kwds-re) ;FIXME!!! includes auto
 -                  (and (c-major-mode-is 'java-mode)
 -                       (looking-at "@[A-Za-z0-9]+")))
 -          (if (save-match-data (looking-at c-typedef-key))
 -              (setq at-typedef t))
 +         ((or (looking-at c-prefix-spec-kwds-re)
 +              (and (c-major-mode-is 'java-mode)
 +               (looking-at "@[A-Za-z0-9]+")))
 +          (save-match-data
 +            (if (looking-at c-typedef-key)
 +                (setq at-typedef t)))
            (setq kwd-sym (c-keyword-sym (match-string 1)))
            (save-excursion
              (c-forward-keyword-clause 1)
              (setq kwd-clause-end (point))))
 +         ((and c-opt-cpp-prefix
 +               (looking-at c-noise-macro-with-parens-name-re))
 +          (setq noise-start (point))
 +          (c-forward-noise-clause)
 +          (setq kwd-clause-end (point))))
  
          (when (setq found-type (c-forward-type t)) ; brace-block-too
            ;; Found a known or possible type or a prefix of a known type.
                  backup-at-type-decl nil
                  backup-maybe-typeless nil))
  
 -        (if kwd-sym
 +        (if (or kwd-sym noise-start)
              (progn
                ;; Handle known specifier keywords and
                ;; `c-decl-hangon-kwds' which can occur after known
                ;; types.
  
 -              (if (c-keyword-member kwd-sym 'c-decl-hangon-kwds)
 -                  ;; It's a hang-on keyword that can occur anywhere.
 +              (if (or (c-keyword-member kwd-sym 'c-decl-hangon-kwds)
 +                      noise-start)
 +                  ;; It's a hang-on keyword or noise clause that can occur
 +                  ;; anywhere.
                    (progn
 -                    (setq at-decl-or-cast t)
                      (if at-type
                          ;; Move the identifier start position if
                          ;; we've passed a type.
        ;; If a known type was found, we still need to skip over any
        ;; hangon keyword clauses after it.  Otherwise it has already
        ;; been done in the loop above.
 -      (while (looking-at c-decl-hangon-key)
 -      (c-forward-keyword-clause 1))
 +      (while
 +        (cond ((looking-at c-decl-hangon-key)
 +               (c-forward-keyword-clause 1))
 +              ((and c-opt-cpp-prefix
 +                    (looking-at c-noise-macro-with-parens-name-re))
 +               (c-forward-noise-clause))))
        (setq id-start (point)))
  
       ((eq at-type 'prefix)
               (setq got-identifier (c-forward-name))
               (setq name-start pos)))
  
 -      ;; Skip over type decl suffix operators.
 -      (while (if (looking-at c-type-decl-suffix-key)
 +      ;; Skip over type decl suffix operators and trailing noise macros.
 +      (while
 +        (cond
 +         ((and c-opt-cpp-prefix
 +               (looking-at c-noise-macro-with-parens-name-re))
 +          (c-forward-noise-clause))
 +
 +         ((looking-at c-type-decl-suffix-key)
 +          (if (eq (char-after) ?\))
 +              (when (> paren-depth 0)
 +                (setq paren-depth (1- paren-depth))
 +                (forward-char)
 +                t)
 +            (when (if (save-match-data (looking-at "\\s("))
 +                      (c-safe (c-forward-sexp 1) t)
 +                    (goto-char (match-end 1))
 +                    t)
 +              (when (and (not got-suffix-after-parens)
 +                         (= paren-depth 0))
 +                (setq got-suffix-after-parens (match-beginning 0)))
 +              (setq got-suffix t))))
  
 -               (if (eq (char-after) ?\))
 -                   (when (> paren-depth 0)
 -                     (setq paren-depth (1- paren-depth))
 -                     (forward-char)
 -                     t)
 -                 (when (if (save-match-data (looking-at "\\s("))
 -                           (c-safe (c-forward-sexp 1) t)
 -                         (goto-char (match-end 1))
 -                         t)
 -                   (when (and (not got-suffix-after-parens)
 -                              (= paren-depth 0))
 -                     (setq got-suffix-after-parens (match-beginning 0)))
 -                   (setq got-suffix t)))
 -
 -             ;; No suffix matched.  We might have matched the
 -             ;; identifier as a type and the open paren of a
 -             ;; function arglist as a type decl prefix.  In that
 -             ;; case we should "backtrack": Reinterpret the last
 -             ;; type as the identifier, move out of the arglist and
 -             ;; continue searching for suffix operators.
 -             ;;
 -             ;; Do this even if there's no preceding type, to cope
 -             ;; with old style function declarations in K&R C,
 -             ;; (con|de)structors in C++ and `c-typeless-decl-kwds'
 -             ;; style declarations.  That isn't applicable in an
 -             ;; arglist context, though.
 -             (when (and (= paren-depth 1)
 +         (t
 +          ;; No suffix matched.  We might have matched the
 +          ;; identifier as a type and the open paren of a
 +          ;; function arglist as a type decl prefix.  In that
 +          ;; case we should "backtrack": Reinterpret the last
 +          ;; type as the identifier, move out of the arglist and
 +          ;; continue searching for suffix operators.
 +          ;;
 +          ;; Do this even if there's no preceding type, to cope
 +          ;; with old style function declarations in K&R C,
 +          ;; (con|de)structors in C++ and `c-typeless-decl-kwds'
 +          ;; style declarations.  That isn't applicable in an
 +          ;; arglist context, though.
 +          (when (and (= paren-depth 1)
                          (not got-prefix-before-parens)
                          (not (eq at-type t))
                          (or backup-at-type
                          (eq (char-before pos) ?\)))
                 (c-fdoc-shift-type-backward)
                 (goto-char pos)
 -               t))
 +               t)))
  
        (c-forward-syntactic-ws))
  
                          at-type
                          (or at-decl-end (looking-at "=[^=]"))
                          (not context)
 -                        (not got-suffix))
 -               ;; Got something like "foo * bar;".  Since we're not inside an
 -               ;; arglist it would be a meaningless expression because the
 -               ;; result isn't used.  We therefore choose to recognize it as
 -               ;; a declaration.  Do not allow a suffix since it could then
 -               ;; be a function call.
 +                        (or (not got-suffix)
 +                            at-decl-start))
 +               ;; Got something like "foo * bar;".  Since we're not inside
 +               ;; an arglist it would be a meaningless expression because
 +               ;; the result isn't used.  We therefore choose to recognize
 +               ;; it as a declaration.  We only allow a suffix (which makes
 +               ;; the construct look like a function call) when
 +               ;; `at-decl-start' provides additional evidence that we do
 +               ;; have a declaration.
                 (throw 'at-decl-or-cast t))
  
               ;; CASE 17
@@@ -9082,12 -8986,6 +9082,12 @@@ comment at the start of cc-engine.el fo
           t)
          ((looking-at c-after-brace-list-key) t)
          ((looking-at c-brace-list-key) nil)
 +        ((eq (char-after) ?\()
 +         (and (eq (c-backward-token-2) 0)
 +              (or (looking-at c-decl-hangon-key)
 +                  (and c-opt-cpp-prefix
 +                       (looking-at c-noise-macro-with-parens-name-re)))))
 +
          ((and c-recognize-<>-arglists
                (eq (char-after) ?<)
                (looking-at "\\s("))
           ;; CASE 5A.3: brace list open
           ((save-excursion
              (c-beginning-of-decl-1 lim)
 -            (while (looking-at c-specifier-key)
 -              (goto-char (match-end 1))
 -              (c-forward-syntactic-ws indent-point))
 +            (while (cond
 +                    ((looking-at c-specifier-key)
 +                     (c-forward-keyword-clause 1))
 +                    ((and c-opt-cpp-prefix
 +                          (looking-at c-noise-macro-with-parens-name-re))
 +                     (c-forward-noise-clause))))
              (setq placeholder (c-point 'boi))
              (or (consp special-brace-list)
                  (and (or (save-excursion
           (t
            (save-excursion
              (c-beginning-of-decl-1 lim)
 -            (while (looking-at c-specifier-key)
 -              (goto-char (match-end 1))
 -              (c-forward-syntactic-ws indent-point))
 +            (while (cond
 +                    ((looking-at c-specifier-key)
 +                     (c-forward-keyword-clause 1))
 +                    ((and c-opt-cpp-prefix
 +                          (looking-at c-noise-macro-with-parens-name-re))
 +                     (c-forward-noise-clause))))
              (c-add-syntax 'defun-open (c-point 'boi))
              ;; Bogus to use bol here, but it's the legacy.  (Resolved,
              ;; 2007-11-09)
            (c-beginning-of-statement-1
             (c-safe-position (1- containing-sexp) paren-state))
            (c-forward-token-2 0)
 -          (while (looking-at c-specifier-key)
 -            (goto-char (match-end 1))
 -            (c-forward-syntactic-ws))
 +          (while (cond
 +                  ((looking-at c-specifier-key)
 +                   (c-forward-keyword-clause 1))
 +                  ((and c-opt-cpp-prefix
 +                        (looking-at c-noise-macro-with-parens-name-re))
 +                   (c-forward-noise-clause))))
            (c-add-syntax 'brace-list-open (c-point 'boi))))
  
         ;; CASE 9B: brace-list-close brace
index 107b2e79fb61ed707b72d230c65f80191205c4d6,afd707667b8586352841f4f5206c3f5174dea4c4..afd707667b8586352841f4f5206c3f5174dea4c4
@@@ -584,5 -584,13 +584,13 @@@ baz\"\"
                    (skip-chars-backward "\"")
                    (mark-sexp -1)))
  
\f
+ ;;; Electric quotes
+ (define-electric-pair-test electric-quote-string
+   "" "'" :expected-string "'" :expected-point 2
+   :fixture-fn #'electric-quote-local-mode
+   :bindings '((electric-quote-string . t))
+   :test-in-comments nil :test-in-strings nil)
  (provide 'electric-tests)
  ;;; electric-tests.el ends here