unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Kaushal Modi <kaushal.modi@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 24057@debbugs.gnu.org, npostavs@users.sourceforge.net
Subject: bug#24057: 25.1.50; ffap interprets comments beginning with "//" as file path
Date: Mon, 25 Jul 2016 18:13:56 +0000	[thread overview]
Message-ID: <CAFyQvY05wezaFk004KQCgcrZ4A1GeLnXqQ_WQwQ1Kce=241uCA@mail.gmail.com> (raw)
In-Reply-To: <83invttyv7.fsf@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 4328 bytes --]

On Mon, Jul 25, 2016 at 1:24 PM Eli Zaretskii <eliz@gnu.org> wrote:

> Not sure which behavior you call "buggy".  I'm okay with
> unconditionally skipping the comment leader string, such as "//" in
> C/C++ case.  If you want to skip more than that, I think skipping the
> rest should be optional, defaulting to off.  How's that "buggy"?
>

Thanks for the clarification. I thought that you were suggesting to have a
defcustom that would either use or not use comment-search-forward in
ffap-string-at-point with the default set such that the old (current)
behavior of not skipping the comment starter at all is retained. I refer to
this "not skipping the comment starter at all" behavior as buggy.


> > How about we add the defcustom and set the default value so that this
> bug is fixed. And we wait for people
> > using the master branch to report any issues caused by this. Also we let
> emacs-devel know that this
> > defcustom is going in.
>
> I don't want us to introduce backward-incompatible behavior, except
> when strictly necessary.  In this case, skipping the initial "//" is
> necessary, but skipping more slashes is not.
>

Understood. In that case, the code will have to be made more complex...

Here's a quick attempt .. Can you please have a look at it?

 (defun modi/ffap-string-at-point (&optional mode)
      "Return a string of characters from around point.

MODE (defaults to value of `major-mode') is a symbol used to look up
string syntax parameters in `ffap-string-at-point-mode-alist'.

If MODE is not found, we use `file' instead of MODE.

If the region is active,return a string from the region.

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).

Sets variables `ffap-string-at-point' and `ffap-string-at-point-region'. "
      (let* ((args
              (cdr
               (or (assq (or mode major-mode)
ffap-string-at-point-mode-alist)
                   (assq 'file ffap-string-at-point-mode-alist))))
             (region-selected (use-region-p))
             (pt (point))
             (beg (if region-selected
                      (region-beginning)
                    (save-excursion
                      (skip-chars-backward (car args))
                      (skip-chars-forward (nth 1 args) pt)
                      (point))))
             (end (if region-selected
                      (region-end)
                    (save-excursion
                      (skip-chars-forward (car args))
                      (skip-chars-backward (nth 2 args) pt)
                      (point))))
             beg-temp)
        ;; Ensure that if "//" is a valid comment starter in the current
major
        ;; mode, then that is removed from the returned string.
        (when (and (null region-selected)
                   ;; Check if the first character is '/' and not part of
the
                   ;; comment
                   (save-excursion
                     (goto-char beg)
                     (and (looking-at "/")
                          (null (nth 4 (syntax-ppss)))))
                   ;; Check if the second character is '/' and also not
part of
                   ;; the comment
                   (setq beg-temp (+ 1 beg))
                   (if (> end beg-temp)
                       (save-excursion
                         (goto-char beg-temp)
                         (and (looking-at "/")
                              (null (nth 4 (syntax-ppss)))))
                     nil))
          ;; Check if the third character *is* part of the comment
          (setq beg-temp (+ 2 beg))
          (if (> end beg-temp)
              (save-excursion
                (goto-char beg-temp)
                (when (nth 4 (syntax-ppss))
                  (setq beg beg-temp)))))
        (message "beg = %d beg-temp = %S end = %d "
                 beg beg-temp end)
        (prog1
            (setq ffap-string-at-point
                  (buffer-substring-no-properties
                   (setcar ffap-string-at-point-region beg)
                   (setcar (cdr ffap-string-at-point-region) end)))
          (message "dbg: %S" ffap-string-at-point)
          )))
    (advice-add 'ffap-string-at-point :override #'modi/ffap-string-at-point)
-- 

Kaushal Modi

[-- Attachment #2: Type: text/html, Size: 6530 bytes --]

  reply	other threads:[~2016-07-25 18:13 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-22 23:00 bug#24057: 25.1.50; ffap interprets comments beginning with "//" as file path Kaushal Modi
2016-07-22 23:11 ` Kaushal Modi
2016-07-23  1:26 ` npostavs
2016-07-23  7:38   ` Eli Zaretskii
2016-07-23  7:34 ` Eli Zaretskii
2016-07-23 11:56   ` Kaushal Modi
2016-07-23 13:05     ` Eli Zaretskii
2016-07-23 13:23       ` Kaushal Modi
2016-07-23 13:59         ` Eli Zaretskii
2016-07-23 18:02           ` Noam Postavsky
2016-07-23 18:20             ` Eli Zaretskii
2016-07-23 18:22             ` Eli Zaretskii
2016-07-23 21:51           ` Kaushal Modi
2016-07-24 14:16             ` Eli Zaretskii
2016-07-25  2:19               ` Kaushal Modi
2016-07-25 17:02                 ` Eli Zaretskii
2016-07-25 17:13                   ` Kaushal Modi
2016-07-25 17:24                     ` Eli Zaretskii
2016-07-25 18:13                       ` Kaushal Modi [this message]
2016-07-25 20:18                         ` Kaushal Modi
2016-07-26 14:41                           ` Eli Zaretskii
2016-07-26 15:11                             ` Kaushal Modi
2017-03-17  2:10                           ` npostavs
2017-03-17  2:13                             ` npostavs
2017-03-17 22:16                             ` Kaushal Modi
2017-03-17 23:30                               ` npostavs
2017-03-18  1:28                                 ` Kaushal Modi
2017-03-18 15:41                                   ` npostavs
2017-03-23 13:01                                     ` npostavs
2017-03-23 13:30                                       ` Kaushal Modi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAFyQvY05wezaFk004KQCgcrZ4A1GeLnXqQ_WQwQ1Kce=241uCA@mail.gmail.com' \
    --to=kaushal.modi@gmail.com \
    --cc=24057@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=npostavs@users.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).