From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Kaushal Modi Newsgroups: gmane.emacs.bugs Subject: bug#24057: 25.1.50; ffap interprets comments beginning with "//" as file path Date: Fri, 22 Jul 2016 23:11:47 +0000 Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=94eb2c031310ab4eab0538418fed X-Trace: ger.gmane.org 1469229206 18677 80.91.229.3 (22 Jul 2016 23:13:26 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 22 Jul 2016 23:13:26 +0000 (UTC) Cc: cyd@gnu.org To: 24057@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Jul 23 01:13:18 2016 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1bQjd8-0001nU-1K for geb-bug-gnu-emacs@m.gmane.org; Sat, 23 Jul 2016 01:13:18 +0200 Original-Received: from localhost ([::1]:49683 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bQjd3-0007gg-Sp for geb-bug-gnu-emacs@m.gmane.org; Fri, 22 Jul 2016 19:13:13 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:45775) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bQjcw-0007ga-Lj for bug-gnu-emacs@gnu.org; Fri, 22 Jul 2016 19:13:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bQjcs-0000b9-CA for bug-gnu-emacs@gnu.org; Fri, 22 Jul 2016 19:13:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:49992) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bQjcs-0000b4-81 for bug-gnu-emacs@gnu.org; Fri, 22 Jul 2016 19:13:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1bQjcs-00013S-0x for bug-gnu-emacs@gnu.org; Fri, 22 Jul 2016 19:13:02 -0400 X-Loop: help-debbugs@gnu.org In-Reply-To: Resent-From: Kaushal Modi Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 22 Jul 2016 23:13:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 24057 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 24057-submit@debbugs.gnu.org id=B24057.14692291253975 (code B ref 24057); Fri, 22 Jul 2016 23:13:01 +0000 Original-Received: (at 24057) by debbugs.gnu.org; 22 Jul 2016 23:12:05 +0000 Original-Received: from localhost ([127.0.0.1]:34096 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bQjbx-000123-5z for submit@debbugs.gnu.org; Fri, 22 Jul 2016 19:12:05 -0400 Original-Received: from mail-oi0-f68.google.com ([209.85.218.68]:36831) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bQjbv-00011a-Qo for 24057@debbugs.gnu.org; Fri, 22 Jul 2016 19:12:04 -0400 Original-Received: by mail-oi0-f68.google.com with SMTP id d204so11621598oig.3 for <24057@debbugs.gnu.org>; Fri, 22 Jul 2016 16:12:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to:cc; bh=YYY4v8XS/HAJwf93xY1LiUWtBh14okzUmTmigGaPUQI=; b=T/TEW+taoCOhWAYgl8qVlUtsPSOEd3NscOQzGatiicqfmSjSrHebYOm75aS55PhPvA P2Wf4RcAdLyxFP7UQIkbmpURwIFdA0cZ6dJx/BrfRHrYSBYyYkRwK5ThrjUf/I3kRx7t 8+IPNq+iyee37smy3sbxHoaxNvbAiIHcqJJQvYXX8jHCG4MmcncMj+Vajyt9DxHsQD4S d0D6MM9RMaxcoFm/dbyT0bSS2tdQYrcgefkhrmZI5K8Z/PNmK6zAS71b/UmygoiHq50C i7INi9i7X7oYpoCJAiGJZG+TpZRCNc4yqhWlWAylpjTcHeMKSGKiBslsnyazwURJh+4G s3Og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:from:date:message-id:subject:to:cc; bh=YYY4v8XS/HAJwf93xY1LiUWtBh14okzUmTmigGaPUQI=; b=SOFhAGxjHjiTpNrXrvpZp3DBj194XOcoLOmNBuuhKdVwhIhajqnoMC/CT+1nIxbz7q nUea2yFb3aSt9VG0rOE1N/a7ZC3vlCuFBjCx0OC1nOwbWhE0JbK5+cI55/KMRKty83tS 03sbkeEwku3ZYTag2V0UBj5VTGa+VSAlyHJo7WfGxjybTrU/0YTqIDFrLpOK9T/dE8sx /9cz19ux+SJZwAI/x9BT/MsnspXytSMIppRUSdugOjAciE+dCt6O++zTERm4MQHtHbq5 tz1nohrmDSIdA/nZIkt2zqgsqEOO//Aq524pUrHnBqMNDWX6cNR7WOVHFMbMBQ6ywmTb DFxw== X-Gm-Message-State: AEkoousOSL7i3Peg4tPSVggyFQBVEgXXJykmYAM8quZRj1gdjaLShfrQUwgKmKpI4SAEvnC39dOyASl2M7Qxmw== X-Received: by 10.157.7.202 with SMTP id 68mr3590206oto.133.1469229117949; Fri, 22 Jul 2016 16:11:57 -0700 (PDT) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:121431 Archived-At: --94eb2c031310ab4eab0538418fed Content-Type: text/plain; charset=UTF-8 I am copying the last 3 committers on this section of the code to review this patch. Patch follows: >From a9e94ba5789d2b1d524120efecd3f9ab9af641cc Mon Sep 17 00:00:00 2001 From: Kaushal Modi Date: Fri, 22 Jul 2016 18:58:29 -0400 Subject: [PATCH] Do not include comment start chars in ffap string * 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). 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). --- lisp/ffap.el | 63 ++++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 42 insertions(+), 21 deletions(-) diff --git a/lisp/ffap.el b/lisp/ffap.el index 7013e6e..ba62012 100644 --- a/lisp/ffap.el +++ b/lisp/ffap.el @@ -1097,33 +1097,54 @@ ffap-string-at-point (defun 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. -Sets the variable `ffap-string-at-point' and the variable -`ffap-string-at-point-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)))) - (pt (point)) - (beg (if (use-region-p) - (region-beginning) - (save-excursion - (skip-chars-backward (car args)) - (skip-chars-forward (nth 1 args) pt) - (point)))) - (end (if (use-region-p) - (region-end) - (save-excursion - (skip-chars-forward (car args)) - (skip-chars-backward (nth 2 args) pt) - (point))))) + (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)))) + ;; If point is in a comment like "//abc" (in `c-mode'), and a + ;; region is not selected, return the position of 'a'. + (comment-start-pos (unless region-selected + (save-excursion + (goto-char beg) + (comment-search-forward + (line-end-position) :noerror) + (point)))) + (end (if region-selected + (region-end) + (save-excursion + (skip-chars-forward (car args)) + (skip-chars-backward (nth 2 args) pt) + (point))))) + (when (and comment-start-pos + (> end comment-start-pos)) + (setq beg comment-start-pos)) + ;; (message "comment-start-pos = %d end = %d beg = %d" + ;; comment-start-pos end beg) (setq ffap-string-at-point - (buffer-substring-no-properties - (setcar ffap-string-at-point-region beg) - (setcar (cdr ffap-string-at-point-region) end))))) + (buffer-substring-no-properties + (setcar ffap-string-at-point-region beg) + (setcar (cdr ffap-string-at-point-region) end))))) (defun ffap-string-around () ;; Sometimes useful to decide how to treat a string. -- 2.9.2 -- Kaushal Modi --94eb2c031310ab4eab0538418fed Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
I am copying the last 3 committers on this section of= the code to review this patch.

Patch follows:

=
From a9e94ba5789d2b1d524120efecd3f9ab9af641cc Mon Sep 17 00= :00:00 2001
From: Kaushal Modi <kaushal.modi@gmail.com>
Date: Fri, 22 Jul 2016= 18:58:29 -0400
Subject: [PATCH] Do not include comment start cha= rs in ffap string

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

Otherwise, in a major mode like c-mode, with `ido= -mode' enabled and
`ido-use-filename-at-point' set to `gu= ess', doing "C-x C-f" on a "//foo"
commen= t will initiate an attempt to access a path "//foo" (Bug#24057).<= /div>
---
=C2=A0lisp/ffap.el | 63 +++++++++++++++++++++++++++= +++++++++++++--------------------
=C2=A01 file changed, 42 insert= ions(+), 21 deletions(-)

diff --git a/lisp/ffap.el= b/lisp/ffap.el
index 7013e6e..ba62012 100644
--- a/lis= p/ffap.el
+++ b/lisp/ffap.el
@@ -1097,33 +1097,54 @@ ff= ap-string-at-point
=C2=A0
=C2=A0(defun ffap-string-at-p= oint (&optional mode)
=C2=A0 =C2=A0"Return a string of c= haracters from around point.
+
=C2=A0MODE (defaults to = value of `major-mode') is a symbol used to look up
=C2=A0stri= ng syntax parameters in `ffap-string-at-point-mode-alist'.
+<= /div>
=C2=A0If MODE is not found, we use `file' instead of MODE.
+
=C2=A0If the region is active, return a string from the= region.
-Sets the variable `ffap-string-at-point' and the va= riable
-`ffap-string-at-point-region'."
+
+If the point is in a comment, ensure that the returned string does n= ot contain
+the comment start characters (especially for major mo= des that have '//' as
+comment start characters).
+
+Sets variables `ffap-string-at-point' and `ffap-string-= at-point-region'. "
=C2=A0 =C2=A0(let* ((args
= - =C2=A0(c= dr
- =C2=A0 (or (assq (or mode major-mode) ffap-string-at-point-mode-alist)=
- =C2=A0 =C2=A0 =C2=A0 (assq 'file ffap-string-at-point-mode-alist))))=
- (pt (point))
- (beg (if (use-region-p)
- =C2=A0(region-beginning)
=
- (sa= ve-excursion
- =C2=A0(skip-chars-backward (car args))
- =C2=A0(skip-chars= -forward (nth 1 args) pt)
- =C2=A0(point))))
- (end (if (use-region-p)
- =C2=A0(region-end)
- (save-excursion
- =C2=A0(skip-chars-forward (car ar= gs))
- = =C2=A0(skip-chars-backward (nth 2 args) pt)
- =C2=A0(point)))))
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(cdr
+ =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 (or (assq (or mode major-mode) ffap-string-at-point-m= ode-alist)
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (as= sq 'file ffap-string-at-point-mode-alist))))
+ =C2=A0 =C2=A0 = =C2=A0 =C2=A0 (region-selected (use-region-p))
+ =C2=A0 =C2=A0 = =C2=A0 =C2=A0 (pt (point))
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 (beg (if= region-selected
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0(region-beginning)
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0(save-excursion
+ =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(skip-chars-backward (car args= ))
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0(skip-chars-forward (nth 1 args) pt)
+ =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(point))))
+ =C2=A0 =C2= =A0 =C2=A0 =C2=A0 ;; If point is in a comment like "//abc" (in `c= -mode'), and a
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 ;; region is not= selected, return the position of 'a'.
+ =C2=A0 =C2=A0 = =C2=A0 =C2=A0 (comment-start-pos (unless region-selected
+ =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0(save-excursion
+ =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0(goto-char beg)
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0(comment-search-forward
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 (line-end-position) :noerror)
+ =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0(point))))
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 (end (i= f region-selected
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0(region-end)
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0(save-excursion
+ =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(skip-chars-forward (car args))
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(sk= ip-chars-backward (nth 2 args) pt)
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(point)))))
+ =C2=A0 =C2=A0(whe= n (and comment-start-pos
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 (> end comment-start-pos))
+ =C2=A0 =C2=A0 =C2=A0(s= etq beg comment-start-pos))
+ =C2=A0 =C2=A0;; (message "comm= ent-start-pos =3D %d end =3D %d beg =3D %d"
+ =C2=A0 =C2=A0;= ; =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0comment-start-pos end beg)
= =C2=A0 =C2=A0 =C2=A0(setq ffap-string-at-point
- =C2=A0(buffer-substring-no= -properties
- =C2=A0 (setcar ffap-string-at-point-region beg)
- =C2=A0 (set= car (cdr ffap-string-at-point-region) end)))))
+ =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0(buffer-substring-no-properties
+ =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 (setcar ffap-string-at-point-region beg)
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (setcar (cdr ffap-string-at-point-reg= ion) end)))))
=C2=A0
=C2=A0(defun ffap-string-around ()=
=C2=A0 =C2=A0;; Sometimes useful to decide how to treat a string= .
--=C2=A0
2.9.2

--

Kaushal Modi

--94eb2c031310ab4eab0538418fed--