From 0706445da3f7e10aceef8b371d458deb4ec1c39d Mon Sep 17 00:00:00 2001 From: Jari Aalto Date: Thu, 7 Apr 2011 18:20:17 +0300 Subject: [PATCH] lisp/ffap.el: (ffap-string-at-point): Support spaces in paths Organization: Private Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Signed-off-by: Jari Aalto --- lisp/ffap.el | 47 +++++++++++++++++++++++++++++------------------ 1 files changed, 29 insertions(+), 18 deletions(-) diff --git a/lisp/ffap.el b/lisp/ffap.el index 97105ed..dcc16f2 100644 --- a/lisp/ffap.el +++ b/lisp/ffap.el @@ -1006,24 +1006,35 @@ If MODE is not found, we use `file' instead of MODE. If the region is active, return a string from the region. Sets `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)) - (str - (if (and transient-mark-mode mark-active) - (buffer-substring - (setcar ffap-string-at-point-region (region-beginning)) - (setcar (cdr ffap-string-at-point-region) (region-end))) - (buffer-substring - (save-excursion - (skip-chars-backward (car args)) - (skip-chars-forward (nth 1 args) pt) - (setcar ffap-string-at-point-region (point))) - (save-excursion - (skip-chars-forward (car args)) - (skip-chars-backward (nth 2 args) pt) - (setcar (cdr ffap-string-at-point-region) (point))))))) + (cdr + (or (assq (or mode major-mode) ffap-string-at-point-mode-alist) + (assq 'file ffap-string-at-point-mode-alist)))) + (pt (point)) + space-p + end + (str + (if (and transient-mark-mode mark-active) + (buffer-substring + (setcar ffap-string-at-point-region (region-beginning)) + (setcar (cdr ffap-string-at-point-region) (region-end))) + (buffer-substring + (save-excursion + (skip-chars-backward (car args)) + (skip-chars-forward (nth 1 args) pt) + ;; Paths may contains spaces, check those + ;; FIXME: may need better tuning. Currenly matches "/paths like/exam ple.txt" + (if (looking-at ".*/.* [^[:space:]]*/.*[^[:space:]]") + (setq space-p (match-end 0))) + (setcar ffap-string-at-point-region (point))) + (save-excursion + (skip-chars-forward (car args)) + (skip-chars-backward (nth 2 args) pt) + (setq end (point)) + (if (and space-p + (> space-p end) + (memq mode '(file nil))) + (setq end space-p)) + (setcar (cdr ffap-string-at-point-region) end)))))) (set-text-properties 0 (length str) nil str) (setq ffap-string-at-point str))) -- 1.7.4.1