4

In Windows, both find-file and helm-find-file don't work if there's space in the file name. For example:

I move cursor to the anywhere in the string "c:/a/b.yaml", and then call find-file (C-x C-f), press RET, then Emacs will open the file.

but this doesn't work for "c:/a/b c/d.yaml", note the space in path, find-file will only manage to find the directory c:/a ....

If there a configurable variable or work round for this issue?

3
  • 1
    Please elaborate on what "doesn't work" means, i.e. describe exactly what you type, what you expect to see, and what actually happens. Have you tried reproducing this problem after starting Emacs with the -Q option?
    – Basil
    Commented May 17, 2018 at 10:29
  • No, there is no user option to control this because Emacs handles file names containing spaces by default. This is why I asked whether you can reproduce this after starting Emacs with the -Q flag. If you can't, it means there is something in your configuration causing the problem.
    – Basil
    Commented May 17, 2018 at 10:48
  • I tried Emacs with -Q and it doesn't work for both cases. i guess something is wrong with my Emacs installation problem rather Emacs in windows. Commented May 17, 2018 at 12:31

2 Answers 2

1

It is not implemented in Emacs yet as far as I know.

Check https://debbugs.gnu.org/cgi/bugreport.cgi?bug=28870

1

The following lisp code advices ffap-string-at-point such that it returns the string text at point if point is inside a string.

That modification lets find-file-at-point propose the full string text as initial input for the file name.

MS-Windows file names with drive letters are wrongly detected as url's if the value of the variable ffap-lax-url is non-nil. In that case find-file-at-point gives c:/Program as initial input if point is within Program of the string "c:/Program Files". So it may be that you need to set ffap-lax-url to nil.

The advice relies on the syntax parser (syntax-ppss) of emacs. That works on all major modes with syntactic fontification.

(require 'subr-x) ;; for `when-let'

;; You can also use `thingatpt+.el' instead.
(defun bounds-of-string-at-point ()
  "String at point including the string delimiters."
  (when-let ((ppss (syntax-ppss))
             (in-string (nth 3 ppss))
             (b (nth 8 ppss))
             (e-ppss (save-excursion (parse-partial-sexp (1+ b) (point-max) nil nil nil 'syntax-table)))
             (e (1+ (nth 8 e-ppss))))
    (cons b e)))

(put 'string 'bounds-of-thing-at-point #'bounds-of-string-at-point)

(defun around-ad-ffap-string-at-point (oldfun &optional mode)
  "Use the string at point for `ffap-string-at-point'
or the original function if we are not within a string."
  (let ((str-bounds (bounds-of-thing-at-point 'string)))
    (if str-bounds
        (setq ffap-string-at-point
              (buffer-substring-no-properties
               (setcar ffap-string-at-point-region (1+ (car str-bounds)))
               (setcar (cdr ffap-string-at-point-region) (1- (cdr str-bounds)))))
      (funcall oldfun mode))))

(advice-add 'ffap-string-at-point :around #'around-ad-ffap-string-at-point)
1
  • I tried to set ``ffap-lax-url` to nil, but it did not work.
    – nephewtom
    Commented Jan 20, 2019 at 23:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.