From: Kaushal Modi <kaushal.modi@gmail.com>
To: 24057@debbugs.gnu.org
Cc: cyd@gnu.org
Subject: bug#24057: 25.1.50; ffap interprets comments beginning with "//" as file path
Date: Fri, 22 Jul 2016 23:11:47 +0000 [thread overview]
Message-ID: <CAFyQvY3hxxAPaA_XF6PYOc7H_w-kmFbemP3sSPnu5GZJpZ3=2Q@mail.gmail.com> (raw)
In-Reply-To: <CAFyQvY1f5jVrZCGHZu9hVkQHDLuSSv0Ve0FA=nHrMJoQtijqLA@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 4041 bytes --]
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 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
[-- Attachment #2: Type: text/html, Size: 6885 bytes --]
next prev parent reply other threads:[~2016-07-22 23:11 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 [this message]
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
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='CAFyQvY3hxxAPaA_XF6PYOc7H_w-kmFbemP3sSPnu5GZJpZ3=2Q@mail.gmail.com' \
--to=kaushal.modi@gmail.com \
--cc=24057@debbugs.gnu.org \
--cc=cyd@gnu.org \
/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).