unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#24057: 25.1.50; ffap interprets comments beginning with "//" as file path
@ 2016-07-22 23:00 Kaushal Modi
  2016-07-22 23:11 ` Kaushal Modi
                   ` (2 more replies)
  0 siblings, 3 replies; 30+ messages in thread
From: Kaushal Modi @ 2016-07-22 23:00 UTC (permalink / raw)
  To: 24057

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

Hi all,

I lived with this bug for a long time and then I lived with a patched
ffap-string-at-point for a long time :)

The bug is that if

(1) a major mode uses "//" as comment start chars, and
(2) ido-mode is enabled, and
(3) ffap feature is enabled, and
(4) user does C-x C-f on a comment like "//foo"

attempt is made to access "//foo" path.

It's a very corner case bug, but I hit is very often as I work most of the
time in a major mode that uses "//" to comment lines (verilog-mode).

Here is the recipe to reproduce this in emacs -Q:

(1) emacs -Q
(2) Evaluate:

(progn
  (c-mode)
  (insert "//This is a comment")
  (ido-mode)
  (setq ido-use-filename-at-point 'guess)
  (re-search-backward "//" (line-beginning-position)))

(3) Hit "C-x C-f"

You will see that emacs is trying to look for a path "//This"!

This must not happen.

The proposed fix adds a little intelligence to skip the comment start chars
in the string stored to ffap-string-at-point var.

Here is the proposed patch generated ignoring white space. I will post a
proper git formatted patch in a follow up email.

=====

diff --git a/lisp/ffap.el b/lisp/ffap.el
index 7013e6e..ba62012 100644
--- a/lisp/ffap.el
+++ b/lisp/ffap.el
@@ -1097,29 +1097,50 @@ 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))))
+         (region-selected (use-region-p))
          (pt (point))
- (beg (if (use-region-p)
+         (beg (if region-selected
                   (region-beginning)
                 (save-excursion
                   (skip-chars-backward (car args))
                   (skip-chars-forward (nth 1 args) pt)
                   (point))))
- (end (if (use-region-p)
+         ;; 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)

=====


In GNU Emacs 25.1.50.10 (x86_64-unknown-linux-gnu, GTK+ Version 2.24.23)
 of 2016-07-22 built on ...
Repository revision: 03f32876210f3dd68c71baa210e523c3b7581758
Windowing system distributor 'The X.Org Foundation', version 11.0.60900000
System Description: Red Hat Enterprise Linux Workstation release 6.6
(Santiago)

Configured using:
 'configure --with-modules
 --prefix=/home/kmodi/usr_local/apps/6/emacs/master
 'CPPFLAGS=-fgnu89-inline -I/home/kmodi/usr_local/6/include
 -I/usr/include/freetype2 -I/usr/include' 'CFLAGS=-ggdb3 -O0'
 'CXXFLAGS=-ggdb3 -O0' 'LDFLAGS=-L/home/kmodi/usr_local/6/lib
 -L/home/kmodi/usr_local/6/lib64 -ggdb3''

Configured features:
XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK SOUND GPM DBUS GCONF GSETTINGS
NOTIFY ACL LIBSELINUX GNUTLS LIBXML2 FREETYPE LIBOTF XFT ZLIB
TOOLKIT_SCROLL_BARS GTK2 X11 MODULES

Important settings:
  value of $LANG: en_US.UTF-8
  value of $XMODIFIERS: @im=none
  locale-coding-system: utf-8-unix

-- 

Kaushal Modi

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

^ permalink raw reply related	[flat|nested] 30+ messages in thread

end of thread, other threads:[~2017-03-23 13:30 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

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