bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: make ffap wildcard-friendly


From: Juri Linkov
Subject: Re: make ffap wildcard-friendly
Date: Wed, 01 Dec 2004 22:11:15 +0200
User-agent: Gnus/5.110002 (No Gnus v0.2) Emacs/21.3.50 (gnu/linux)

Kevin Rodgers <ihs_4664@yahoo.com> writes:
> Dan Jacobson wrote:
>> (setq ffap-dired-wildcards "[*?][^/]*\\'") should be the default.
>> Hmm, the docstring doesn't say what if then there really is a filename
>> with those...
>
> And the comment in the code confirms that is one of the reasons it is
> disabled by default:
>
>    ;; Suggestion from RHOGEE, 07 Jul 1994.  Disabled, dired is still
>    ;; available by "C-x C-d <pattern>", and valid filenames may
>    ;; sometimes contain wildcard characters.

`find-file' can expand wildcards, so it makes sense to call
`find-file' with WILDCARDS argument instead of `dired'.
So I think the following patch will do the right thing:
C-x C-f (find-file-at-point) works like `find-file' wrt wildcards,
and C-x d (dired-at-point) calls `dired' with wildcards.
It contains also fixes to copy correctly all wildcards to the minibuffer.

Index: lisp/ffap.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/ffap.el,v
retrieving revision 1.45
diff -c -r1.45 ffap.el
*** lisp/ffap.el        9 Jun 2004 18:32:06 -0000       1.45
--- lisp/ffap.el        1 Dec 2004 20:02:14 -0000
***************
*** 202,214 ****
  ;; through this section for features that you like, put an appropriate
  ;; enabler in your .emacs file.
  
! (defcustom ffap-dired-wildcards nil
!   ;; Suggestion from RHOGEE, 07 Jul 1994.  Disabled, dired is still
!   ;; available by "C-x C-d <pattern>", and valid filenames may
!   ;; sometimes contain wildcard characters.
    "*A regexp matching filename wildcard characters, or nil.
  If `find-file-at-point' gets a filename matching this pattern,
! it passes it on to `dired' instead of `find-file'."
    :type '(choice (const :tag "Disable" nil)
                 (const :tag "Enable" "[*?][^/]*\\'")
                 ;; regexp -- probably not useful
--- 202,218 ----
  ;; through this section for features that you like, put an appropriate
  ;; enabler in your .emacs file.
  
! (defcustom ffap-dired-wildcards "[*?][^/]*\\'"
    "*A regexp matching filename wildcard characters, or nil.
+ 
  If `find-file-at-point' gets a filename matching this pattern,
! it passes it on to `find-file' with non-nil WILDCARDS argument,
! which expands wildcards and visits multiple files.  To visit
! a file whose name contains wildcard characters you can suppress
! wildcard expansion by setting `find-file-wildcards'.
! 
! If `dired-at-point' gets a filename matching this pattern,
! it passes it on to `dired'."
    :type '(choice (const :tag "Disable" nil)
                 (const :tag "Enable" "[*?][^/]*\\'")
                 ;; regexp -- probably not useful
***************
*** 939,945 ****
      ;; Slightly controversial decisions:
      ;; * strip trailing "@" and ":"
      ;; * no commas (good for latex)
!     (file "--:$+<>@-Z_a-z~" "<@" "@>;.,!?:")
      ;; An url, or maybe a email/news message-id:
      (url "--:=&?$+@-Z_a-z~#,%;" "^A-Za-z0-9" ":;.,!?")
      ;; Find a string that does *not* contain a colon:
--- 943,949 ----
      ;; Slightly controversial decisions:
      ;; * strip trailing "@" and ":"
      ;; * no commas (good for latex)
!     (file "--:$+<>@-Z_a-z~*?" "<@" "@>;.,!:")
      ;; An url, or maybe a email/news message-id:
      (url "--:=&?$+@-Z_a-z~#,%;" "^A-Za-z0-9" ":;.,!?")
      ;; Find a string that does *not* contain a colon:
***************
*** 1187,1192 ****
--- 1191,1199 ----
                         remote-dir (substring name (match-end 1)))))
                  (ffap-file-exists-string
                   (ffap-replace-file-component remote-dir name))))))
+        ((and ffap-dired-wildcards
+              (string-match ffap-dired-wildcards name)
+              name))
           ;; Try all parent directories by deleting the trailing directory
           ;; name until existing directory is found or name stops changing
           ((let ((dir name))
***************
*** 1357,1366 ****
       ((ffap-url-p filename)
        (let (current-prefix-arg)               ; w3 2.3.25 bug, reported by KPC
        (funcall ffap-url-fetcher filename)))
-      ;; This junk more properly belongs in a modified ffap-file-finder:
       ((and ffap-dired-wildcards
!          (string-match ffap-dired-wildcards filename))
!       (dired filename))
       ((or (not ffap-newfile-prompt)
          (file-exists-p filename)
          (y-or-n-p "File does not exist, create buffer? "))
--- 1364,1374 ----
       ((ffap-url-p filename)
        (let (current-prefix-arg)               ; w3 2.3.25 bug, reported by KPC
        (funcall ffap-url-fetcher filename)))
       ((and ffap-dired-wildcards
!          (string-match ffap-dired-wildcards filename)
!          (eq ffap-file-finder 'find-file)
!          find-file-wildcards)
!       (funcall ffap-file-finder (expand-file-name filename) t))
       ((or (not ffap-newfile-prompt)
          (file-exists-p filename)
          (y-or-n-p "File does not exist, create buffer? "))

-- 
Juri Linkov
http://www.jurta.org/emacs/





reply via email to

[Prev in Thread] Current Thread [Next in Thread]