Subject: Re: bug#24057: 25.1.50; ffap interprets comments beginning with "//" as file path

From: [email-masked]
Date: Thu, 16 Mar 2017 22:10:37 -0400

Kaushal Modi <[email-masked]> writes:

> * lisp/ffap.el (ffap-string-at-point): If the point is in a comment,
> ensure that the returned string does not contain the comment start
> characters (especially for major modes that have '//' as comment start
> characters).
>

Why is there a blank line here?

> Otherwise, in a major mode like c-mode, with `ido-mode' enabled and
> `ido-use-filename-at-point' set to `guess', doing "C-x C-f" on a "//foo"
> comment will initiate an attempt to access a path "//foo" (Bug#24057).
> ---

> +    ;; (message "ffap-string-at-point dbg: beg = %d end = %d" beg end)

This can be removed.

> +           ;; Check if END character is part of a comment.
> +           (save-excursion
> +             (goto-char end)
> +             (nth 4 (syntax-ppss))))

This could be just (nth 4 (syntax-ppss end)).

> +      (save-excursion
> +        ;; Increment BEG till point at BEG is in a comment too.
> +        ;; (nth 4 (syntax-ppss)) will be null for comment start
> +        ;; characters (for example, for the "//" characters in
> +        ;; `c-mode' line comments).
> +        (setq beg (catch 'break
> +                    (while (< beg-new end)
> +                      (goto-char beg-new)
> +                      (if (nth 4 (syntax-ppss)) ; in a comment
> +                          (throw 'break beg-new)
> +                        (setq beg-new (1+ beg-new))))
> +                    end)))) ; Set BEG to END if no throw happens

This could be just

    ;; Move BEG to beginning of comment (after the comment start
    ;; characters), or END, whichever comes first.
    (let ((state (syntax-ppss beg)))
      (unless (nth 4 state)
        (parse-partial-sexp beg end nil nil state t)
        (setq beg (point))))

> +    ;; (message "ffap-string-at-point dbg: beg = %d beg-new = %d"
> +    ;;          beg beg-new)

> +    ;; (message "ffap-string-at-point dbg: ffap-string-at-point = %S"
> +    ;;          ffap-string-at-point)

These can be removed.