From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Jari Aalto Newsgroups: gmane.emacs.bugs Subject: bug#8439: [PATCH] ffap.el -- detect paths with spaces (v2) Date: Fri, 19 Oct 2012 11:35:17 +0300 Organization: Private Message-ID: <87zk3i7tbu.fsf@picasso.cante.net> References: <87pqoyaxu0.fsf@blue.sea.net> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1350635746 1523 80.91.229.3 (19 Oct 2012 08:35:46 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 19 Oct 2012 08:35:46 +0000 (UTC) To: 8439@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Oct 19 10:35:53 2012 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 1TP83a-0007L0-2E for geb-bug-gnu-emacs@m.gmane.org; Fri, 19 Oct 2012 10:35:50 +0200 Original-Received: from localhost ([::1]:57743 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TP83S-0004k4-V0 for geb-bug-gnu-emacs@m.gmane.org; Fri, 19 Oct 2012 04:35:42 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:37158) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TP83P-0004g6-1q for bug-gnu-emacs@gnu.org; Fri, 19 Oct 2012 04:35:40 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TP83K-0002d1-1I for bug-gnu-emacs@gnu.org; Fri, 19 Oct 2012 04:35:38 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:40812) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TP83J-0002ch-TK for bug-gnu-emacs@gnu.org; Fri, 19 Oct 2012 04:35:33 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1TP84k-00063N-0N for bug-gnu-emacs@gnu.org; Fri, 19 Oct 2012 04:37:02 -0400 X-Loop: help-debbugs@gnu.org In-Reply-To: <87pqoyaxu0.fsf@blue.sea.net> Resent-From: Jari Aalto Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 19 Oct 2012 08:37:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 8439 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 8439-submit@debbugs.gnu.org id=B8439.135063581223253 (code B ref 8439); Fri, 19 Oct 2012 08:37:01 +0000 Original-Received: (at 8439) by debbugs.gnu.org; 19 Oct 2012 08:36:52 +0000 Original-Received: from localhost ([127.0.0.1]:51063 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1TP84Z-000630-Vb for submit@debbugs.gnu.org; Fri, 19 Oct 2012 04:36:52 -0400 Original-Received: from emh04.mail.saunalahti.fi ([62.142.5.110]:34026) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1TP84W-00062r-Dn for 8439@debbugs.gnu.org; Fri, 19 Oct 2012 04:36:50 -0400 Original-Received: from saunalahti-vams (vs3-11.mail.saunalahti.fi [62.142.5.95]) by emh04.mail.saunalahti.fi (Postfix) with SMTP id 803FA1A2684; Fri, 19 Oct 2012 11:35:18 +0300 (EEST) Original-Received: from emh07.mail.saunalahti.fi ([62.142.5.117]) by vs3-11.mail.saunalahti.fi ([62.142.5.95]) with SMTP (gateway) id A05BE978000; Fri, 19 Oct 2012 11:35:18 +0300 Original-Received: from picasso.cante.net (a91-155-178-192.elisa-laajakaista.fi [91.155.178.192]) by emh07.mail.saunalahti.fi (Postfix) with ESMTP id AE1753FE4; Fri, 19 Oct 2012 11:35:17 +0300 (EEST) Mail-Copies-To: poster User-Agent: Gnus/5.130006 (Ma Gnus v0.6) Emacs/24.1 (gnu/linux) X-Antivirus: VAMS X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 140.186.70.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-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:65726 Archived-At: --=-=-= Content-Type: text/plain Patch for http://debbugs.gnu.org/cgi/bugreport.cgi?bug=8439#13 --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-lisp-ffap.el-ffap-string-at-point-v2-support-spaces.patch >From 9d912ef5fe082c81917cf65bbacbf4d23e1cd9f3 Mon Sep 17 00:00:00 2001 From: Jari Aalto Date: Fri, 19 Oct 2012 10:15:50 +0300 Subject: [PATCH] lisp/ffap.el: (ffap-string-at-point): v2 support spaces Organization: Private Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Signed-off-by: Jari Aalto --- lisp/ffap.el | 87 +++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 68 insertions(+), 19 deletions(-) diff --git a/lisp/ffap.el b/lisp/ffap.el index 4c75609..a74f85b 100644 --- a/lisp/ffap.el +++ b/lisp/ffap.el @@ -1036,6 +1036,17 @@ possibly a major-mode name, or one of the symbol ;; Added at suggestion of RHOGEE (for ff-paths), 7/24/95. "Last string returned by `ffap-string-at-point'.") +;; Test cases: +;; +;; c:/Program Files/Open Text Evaluation Media/Open Text Exceed 14 x86/Program here.txt +;; c:/Program Files/Open Text Evaluation Media/Open Text Exceed 14 x86/Program Files/Hummingbird/ +;; +(defvar ffap-paths-with-spaces + (or (memq system-type '(ms-dos windows-nt)) + (string-match "cygwin" (emacs-version))) + "If non-nil, look for paths with spaces in `ffap-string-at-point'. +Enabled in W32 and Cygwin by default.") + (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 @@ -1043,25 +1054,63 @@ 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 `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))))))) + (let* ((cygwin-p (string-match "cygwin" (emacs-version))) + (args + (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 + (if (and ffap-paths-with-spaces + (memq mode '(nil file))) + (if (string-match "^[ \t]*$" + (buffer-substring (line-beginning-position) + (point))) + ;; Nothing interesting before point. Move to the first character + (skip-chars-forward " \t" (line-end-position)) + ;; If at colon, move a little forward so that next + ;; `re-search-backward' can position at drive letter. + (if (looking-at ":/") + (forward-char 1)) + ;; Skip until drive path start or patch start letter + (while (re-search-backward "[a-zA-Z]:[\\\\/]\\|[/\\\\]" + (line-beginning-position) t) + (goto-char (match-beginning 0))))) + (skip-chars-backward (car args)) + (skip-chars-forward (nth 1 args) pt) + (when (and ffap-paths-with-spaces + (memq mode '(nil file))) + ;; Paths may contains spaces, allow those + (if (looking-at + "[^\t\r\n]*[/\\\\][^][<>()\"';:|\t\r\n]*[^][<>()\"';:|\r\n[: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)))))) + ;; Under Cygwin, convert drive letters in paths. + (when (and cygwin-p + (memq mode '(nil file)) + (string-match "^\\([a-zA-Z]\\):[/\\\\]\\(.*\\)" str)) + (let ((drive (downcase (match-string 1 str))) + (path (match-string 2 str))) + (setq str (format "/cygdrive/%s/%s" + drive + (replace-regexp-in-string "[\\\\]" "/" path))))) (set-text-properties 0 (length str) nil str) (setq ffap-string-at-point str))) -- 1.7.10.4 --=-=-=--