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

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

[patch] Emacs cygwin path completion support


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

According to Eli's last comments here is improved patch to
complete paths in w32 Cygwin shell. I moved the cygwin related
conversion function to w32-fns.el.

Jari

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.2
diff -u -IId: -b -w -c -r1.1.1.1 -r1.1.1.1.2.2
cvs diff: conflicting specifications of output style
*** ChangeLog   2000/12/10 19:53:54     1.1.1.1
--- ChangeLog   2001/01/01 16:35:07     1.1.1.1.2.2
***************
*** 1,3 ****
--- 1,56 ----
+ 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.2
diff -u -IId: -b -w -c -r1.1.1.1 -r1.1.1.1.2.2
cvs diff: conflicting specifications of output style
*** comint.el   2000/12/10 19:53:54     1.1.1.1
--- comint.el   2001/01/01 16:35:09     1.1.1.1.2.2
***************
*** 147,152 ****
--- 147,155 ----
  ;;  comint-completion-autolist                boolean         completion 
behavior
  ;;  comint-completion-recexact                boolean         ...
  
+ (eval-and-compile
+   (autoload 'w32-system-shell-p "w32-fns"))
+ 
  (defgroup comint nil
    "General command interpreter in a window stuff."
    :group 'processes)
***************
*** 361,366 ****
--- 364,373 ----
  
  (defvar comint-mode-map nil)
  
+ (defvar comint-dos-shell-file-name-regexp "cmd.*\\.exe$"
+   "*Regexp to match a dos based shell filename in `shell-file-name'.
+ This affects the choice between \ and / in the directory completions.")
+ 
  (defvar comint-ptyp t
    "Non-nil if communications via pty; false if by pipe.  Buffer local.
  This is to work around a bug in Emacs process signaling.")
***************
*** 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.
--- 2138,2179 ----
        (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 Vygwin 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."
+   (when (and (not (comint-dynamic-complete-as-filename-1))
+            (fboundp 'dirtrack))
+     ;;  It is possible that user used an shell alist that changed 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.
+     ;;
+     (dirtrack (buffer-substring 
+              (line-beginning-position)
+              (line-end-position)))
+     ;; Now, perhaps the directory was set and we can make a second guess
+     (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)
--- 2185,2191 ----
         (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)
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.1
diff -u -IId: -b -w -c -r1.1.1.1 -r1.1.1.1.2.1
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 16:35:09     1.1.1.1.2.1
***************
*** 63,68 ****
--- 63,91 ----
        (and (w32-using-nt) "cmd.exe")
        "command.com"))
  
+ 
+ 
+ (defun w32-cygwin-path-to-dos (path)
+   "Convert cygwin like //c/temp  or /cygdrive/d/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)))
+    (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]