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

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

Re: [patch] Emacs cygwin path completion support


From: Jari Aalto+mail.emacs
Subject: Re: [patch] Emacs cygwin path completion support
Date: 02 Jan 2001 02:06:56 +0200
User-agent: Gnus/5.090001 (Oort Gnus v0.01) Emacs/20.6 (i386-*-windows98.1998)

* Mon 2001-01-01 Eli Zaretskii <address@hidden> gnu.emacs.bug
* <http://search.dejanews.com/address@hidden&format=threaded>
| [+]
| > From: address@hidden (Jari Aalto+mail.emacs)
| > Newsgroups: gnu.emacs.bug
| > Date: 01 Jan 2001 18:49:24 +0200
| >
| > + (defun w32-cygwin-path-to-dos (path)
| > +    ((or (string-match "^//\\([a-z]\\)\\(.*\\)" path)
| > +   (string-match "^/cygdrive/\\([a-z]\\)\\(.*\\)" path))
| 
| The last two regexps are still too general, I think.  For example,
| "^/cygdrive/\\([a-z]\\)\\(.*\\)" will let "/cygdrive/foobar" be
| converted to "f:oobar".  That's not what you want, I think.
| 
| I see the note you put in the comment above, but I think it only
| pertains to the case like "/cygdrive/c" which you test in the first
| part of `cond'.  Wouldn't using "^/cygdrive/\\([a-z]\\)\\(/.*\\)", and
| similar for the "//c/foo" syntax, be better in the second part?

Yes. Fixed in this latest patch. I also noticed flaws in the
`comint-dynamic-complete-as-filename-1' which now 
handles cygwin paths.

I should note that the "/cygdrive/c" is the correct traslation
in w32-dos-path-to-cygwin, the "//c" is an old and depricated B19 and B20 
feature, but still supported in latest V1.1+ release.

Jari


cvs diff: Diffing .
Index: ChangeLog
===================================================================
RCS file: 
/cygdrive/K/data/version-control/cvsroot/emacs/gnu-emacs/lisp/ChangeLog,v
retrieving revision 1.1.1.1
retrieving revision 1.1.1.1.2.5
diff -u -IId: -b -w -c -r1.1.1.1 -r1.1.1.1.2.5
cvs diff: conflicting specifications of output style
*** ChangeLog   2000/12/10 19:53:54     1.1.1.1
--- ChangeLog   2001/01/01 23:56:16     1.1.1.1.2.5
***************
*** 1,3 ****
--- 1,75 ----
+ 2001-01-02 Tue  Jari Aalto  <address@hidden>
+ 
+       * comint.el (comint-dynamic-complete-as-filename):
+       Rearranged the code to take into account dirtrack.el
+       which must be called before comint-dynamic-complete-as-filename-1
+       or that function will die on error trying to complete
+       cygwin //c/temp name:
+       (file-error (Opening directory invalid argument //c/))
+       (comint-dynamic-complete-as-filename-1): handle special
+       case: cygwin-p
+ 
+ 
+       * w32-fns.el (w32-cygwin-path-to-dos):
+       Made regexps more strict Based on Eli's comment.
+       Now a slash is required after drive letter in cygwin
+       path. path like /cygdrive/some or //some are illegal
+       (w32-dos-path-to-cygwin): New.
+       (w32-cygwin-path-p): New.
+ 
+ 2000-12-19 Tue  Jari Aalto  <address@hidden>
+ 
+       * comint.el (comint-dynamic-complete-as-filename-1): was
+       `comint-dynamic-complete-as-filename'
+       (comint-dynamic-complete-as-filename): New. The completion
+       fails to see the changed directory if user calls an shell alias to
+       change the directory. The path however will show the changed
+       location. This function calls dirtrack (if available) to make
+       a second guess before giving up.
+ 
+ 2000-12-17 Sun  Jari Aalto  <address@hidden>
+ 
+       * w32-fns.el (w32-cygwin-path-to-dos): New.
+       Corrected handling of special cases //c and //c/ in addition
+       to /cygdrive/c and  /cygdrive/c/
+ 
+       * dirtrack.el (dirtrack): Remove `dirtrack-path-to-standard'
+       and moved to w32-fns.el under name `w32-cygwin-path-to-dos'
+       Added test for w32 based Emacs where the function is only
+       used.
+ 
+ 2000-12-15 Fri  Jari Aalto  <address@hidden>
+ 
+       * w32-fns.el (w32-cygwin-path-to-dos): New.
+ 
+       * dirtrack.el (dirtrack-path-to-standard): Fixed the
+       regexps to be more accurate. Require [a-z] drive letter
+       after cygwin paths. Anchored to the beginning.
+       (dirtrack-path-to-standard): Moved to w32-fns.el
+       (dirtrack): Call `w32-cygwin-path-to-dos'.
+ 
+       * comint.el (comint-directory-sep-char): Changed to use
+       `w32-system-shell-p' to check if running under DOS type
+       command shell.
+ 
+ 2000-12-14 Thu  Jari Aalto  <address@hidden>
+ 
+       * dirtrack.el (dirtrack): Call `dirtrack-path-to-standard'
+       (dirtrack-path-to-standard): New. When running Cygwin inside
+       NTEmacs, the ptah name can be  //c/temp  or /cygdrive/d/temp. This
+       function converts them to understandable c:/temp which can
+       be tested with `file-accessible-directory-p' in function
+       `dirtrack'
+ 
+       * comint.el (comint-directory-sep-char): New.
+       Added w32 support for completing directorynames with \
+       in the comint shell buffer when `comint-completion-addsuffix'
+       was set to true.
+       (comint-dynamic-complete-as-filename): Call ┬┤comint-directory-sep-char'
+       to find out the
+       (comint-dos-shell-file-name-regexp): New. Regexp to match
+       sos based shell named like cmd.*\\.exe
+ 
  2000-02-26  Gerd Moellmann  <address@hidden>
  
        * Version 20.6 released.
Index: comint.el
===================================================================
RCS file: 
/cygdrive/K/data/version-control/cvsroot/emacs/gnu-emacs/lisp/comint.el,v
retrieving revision 1.1.1.1
retrieving revision 1.1.1.1.2.5
diff -u -IId: -b -w -c -r1.1.1.1 -r1.1.1.1.2.5
cvs diff: conflicting specifications of output style
*** comint.el   2000/12/10 19:53:54     1.1.1.1
--- comint.el   2001/01/01 23:59:45     1.1.1.1.2.5
***************
*** 147,152 ****
--- 147,157 ----
  ;;  comint-completion-autolist                boolean         completion 
behavior
  ;;  comint-completion-recexact                boolean         ...
  
+ (eval-and-compile
+   (autoload 'w32-system-shell-p     "w32-fns")
+   (autoload 'w32-cygwin-path-p      "w32-fns")
+   (autoload 'w32-cygwin-path-to-dos "w32-fns"))
+ 
  (defgroup comint nil
    "General command interpreter in a window stuff."
    :group 'processes)
***************
*** 2131,2139 ****
        (message "Completing file name..."))
      (comint-dynamic-complete-as-filename)))
  
  (defun comint-dynamic-complete-as-filename ()
    "Dynamically complete at point as a filename.
! See `comint-dynamic-complete-filename'.  Returns t if successful."
    (let* ((completion-ignore-case (memq system-type '(ms-dos windows-nt)))
         (completion-ignored-extensions comint-completion-fignore)
         ;; If we bind this, it breaks remote directory tracking in rlogin.el.
--- 2136,2193 ----
        (message "Completing file name..."))
      (comint-dynamic-complete-as-filename)))
  
+ (defun comint-directory-sep-char ()
+   "Return appropriate `directory-sep-char' which see.
+ The value depends on the current value of `shell-file-name'.
+ If this is cmd.*exe, then suppose w32 type dos shell."
+   ;;  The shel may also be Cygwin based bash.exe, but for
+   ;;  cmd.exe, cmdproxy.exe and the like, the separatr must be \
+   (if (w32-system-shell-p (file-name-nondirectory shell-file-name))
+       ?\\
+     ?/))
+ 
+ 
  (defun comint-dynamic-complete-as-filename ()
+   "Call `comint-dynamic-complete-as-filename-1'. Return t on success."
+   (if (not (fboundp 'dirtrack))
+       (comint-dynamic-complete-as-filename-1)
+     (let* ((point (point))
+          (path (buffer-substring
+                 (save-excursion
+                   (skip-chars-backward "^ \t\r\n")
+                  (point))
+                 point))
+          )
+       ;;  It is possible that user uses an shell alias that changes the
+       ;;  the current directory and the dirtrack.el didn't have a chance
+       ;;  to see the "cd ..." prompt to set correct directory.
+       ;;
+       ;;  bashrc: alias goemacs='cd $EMACS_HOME'
+       ;;
+       ;;  But after this command, the path hopefully shows the current 
location
+       ;;  and we can make a second guess abount completion.
+       ;;
+       (cond
+        ((not (string-match "^/" path))
+       ;;  this is relative completion, calculate ROOT
+       (dirtrack (buffer-substring
+                  (line-beginning-position)
+                  (line-end-position)))))
+ 
+       ;;  Now the default-directory is ready, but user may be now requesting
+       ;;  and absolute CD. The PATH-HERE was fixed by dirtrack for relative
+       ;;  completions.
+       ;;
+       ;;  promt PATH-HERE > cd //c/temp[TAB]
+       ;;
+       (comint-dynamic-complete-as-filename-1))))
+ 
+ 
+ 
+ 
+ (defun comint-dynamic-complete-as-filename-1 ()
    "Dynamically complete at point as a filename.
! See `comint-dynamic-complete-filename'.  Return message string id succesful."
    (let* ((completion-ignore-case (memq system-type '(ms-dos windows-nt)))
         (completion-ignored-extensions comint-completion-fignore)
         ;; If we bind this, it breaks remote directory tracking in rlogin.el.
***************
*** 2145,2151 ****
         (dirsuffix (cond ((not comint-completion-addsuffix)
                           "")
                          ((not (consp comint-completion-addsuffix))
!                          (char-to-string directory-sep-char))
                          (t
                           (car comint-completion-addsuffix))))
         (filesuffix (cond ((not comint-completion-addsuffix)
--- 2199,2205 ----
         (dirsuffix (cond ((not comint-completion-addsuffix)
                           "")
                          ((not (consp comint-completion-addsuffix))
!                          (char-to-string (comint-directory-sep-char)))
                          (t
                           (car comint-completion-addsuffix))))
         (filesuffix (cond ((not comint-completion-addsuffix)
***************
*** 2155,2162 ****
                           (t
                            (cdr comint-completion-addsuffix))))
         (filename (or (comint-match-partial-filename) ""))
!        (pathdir (file-name-directory filename))
!        (pathnondir (file-name-nondirectory filename))
         (directory (if pathdir (comint-directory pathdir) default-directory))
         (completion (file-name-completion pathnondir directory)))
      (cond ((null completion)
--- 2209,2224 ----
                           (t
                            (cdr comint-completion-addsuffix))))
         (filename (or (comint-match-partial-filename) ""))
!        (cygwin-p (and (memq system-type '(windows-nt ms-dos))
!                       (w32-cygwin-path-p filename)))
!        (pathdir (file-name-directory
!                  (if cygwin-p
!                      (w32-cygwin-path-to-dos filename)
!                    filename)))
!        (pathnondir (file-name-nondirectory
!                     (if cygwin-p
!                         (w32-cygwin-path-to-dos filename)
!                       filename)))
         (directory (if pathdir (comint-directory pathdir) default-directory))
         (completion (file-name-completion pathnondir directory)))
      (cond ((null completion)
Index: dirtrack.el
===================================================================
RCS file: 
/cygdrive/K/data/version-control/cvsroot/emacs/gnu-emacs/lisp/dirtrack.el,v
retrieving revision 1.1.1.1
retrieving revision 1.1.1.1.2.2
diff -u -IId: -b -w -c -r1.1.1.1 -r1.1.1.1.2.2
cvs diff: conflicting specifications of output style
*** dirtrack.el 2000/12/10 19:53:54     1.1.1.1
--- dirtrack.el 2001/01/01 16:35:09     1.1.1.1.2.2
***************
*** 119,124 ****
--- 119,125 ----
  ;;; Code:
  
  (eval-when-compile
+   (autoload 'w32-cygwin-path-to-dos "w32-fns")
    (require 'comint)
    (require 'shell))
  
***************
*** 271,277 ****
  "
    (if (null dirtrackp)
        nil
!     (let (prompt-path
          matched
          (current-dir default-directory)
          (dirtrack-regexp    (nth 0 dirtrack-list))
--- 272,279 ----
  "
    (if (null dirtrackp)
        nil
!     (let (prompt-path1
!         prompt-path
          matched
          (current-dir default-directory)
          (dirtrack-regexp    (nth 0 dirtrack-list))
***************
*** 298,312 ****
                (and dirtrack-debug
                     (dirtrack-debug-message "Match is empty string")) 
              ;; Transform prompts into canonical forms
!             (setq prompt-path (funcall dirtrack-directory-function
                                         prompt-path))
              (setq current-dir (funcall dirtrack-canonicalize-function
                                         current-dir))
              (and dirtrack-debug
                   (dirtrack-debug-message 
                    (format
!                    "Prompt is %s\nCurrent directory is %s"
!                    prompt-path current-dir))) 
              ;; Compare them
              (if (or (string= current-dir prompt-path)
                      (string= current-dir 
--- 300,317 ----
                (and dirtrack-debug
                     (dirtrack-debug-message "Match is empty string"))
              ;; Transform prompts into canonical forms
!             (setq prompt-path1 (funcall dirtrack-directory-function
                                         prompt-path))
+             (if (memq system-type '(windows-nt ms-dos))
+                 (setq prompt-path (w32-cygwin-path-to-dos prompt-path1))
+               (setq prompt-path prompt-path1))
              (setq current-dir (funcall dirtrack-canonicalize-function
                                         current-dir))
              (and dirtrack-debug
                   (dirtrack-debug-message
                    (format
!                    "Prompt is %s -> %s\nCurrent directory is %s"
!                    prompt-path1 prompt-path current-dir)))
              ;; Compare them
              (if (or (string= current-dir prompt-path)
                      (string= current-dir
Index: w32-fns.el
===================================================================
RCS file: 
/cygdrive/K/data/version-control/cvsroot/emacs/gnu-emacs/lisp/w32-fns.el,v
retrieving revision 1.1.1.1
retrieving revision 1.1.1.1.2.3
diff -u -IId: -b -w -c -r1.1.1.1 -r1.1.1.1.2.3
cvs diff: conflicting specifications of output style
*** w32-fns.el  2000/12/10 19:54:01     1.1.1.1
--- w32-fns.el  2001/01/01 23:47:58     1.1.1.1.2.3
***************
*** 63,68 ****
--- 63,108 ----
        (and (w32-using-nt) "cmd.exe")
        "command.com"))
  
+ 
+ (defun w32-cygwin-path-p (path)
+   "Check if PATH is like cygwin //c /cygdrive/c."
+   (and path
+        (string-match "^//[a-z]\\|^/cygdrive/" path)))
+ 
+ (defun w32-dos-path-to-cygwin (path)
+   "Convert dos PATH c:/temp to cygwin v1.1+ like /cygdrive/c/temp."
+   (and path
+        (if (not (string-match "^\\([a-z]\\):\\(.*\\)" path))
+          path
+        (setq path (format "/cygdrive/%s%s"
+                           (match-string 1 path)
+                           (match-string 2 path)))
+        (subst-char-in-string ?\\ ?/ path))))
+ 
+ (defun w32-cygwin-path-to-dos (path)
+   "Convert cygwin like //c/temp  or /cygdrive/c/temp path to
+ dos notation c:/temp."
+   ;;  NOTE for cygwin and bash shell prompt
+   ;;  We can't require a slash after the drive letter, because
+   ;;  //c   and  /cygdrive/c   are all top level roots.
+   ;;
+   ;; The bash shell's PS1 setting \w (The current working directory)
+   ;; Does not add trailing slash.
+   (cond
+    ((or (string-match "^//\\([a-z]\\)/?$" path)
+       (string-match "^/cygdrive/\\([a-z]\\)/?$" path))
+     (concat (match-string 1 path) ":/"))
+    ((or (string-match "^//\\([a-z]\\)\\(/.*\\)" path)
+       (string-match "^/cygdrive/\\([a-z]\\)\\(/.*\\)" path))
+     (concat (match-string 1 path) ":" (match-string 2 path)))
+    ((string-match "^(/cygdrive/./\\|//" path)
+     ;;  if previous regexps couldn't handle it, this is severe error.
+     (error "Invalid path format for cygwin %s" path))
+    (t
+     path)))
+ 
+ 
+ 
  (defun w32-system-shell-p (shell-name)
    (and shell-name
         (member (downcase (file-name-nondirectory shell-name))





reply via email to

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