all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: michael@cadilhac.name (Michaël Cadilhac)
Cc: emacs-devel@gnu.org
Subject: Re: Ido and hosts named with a single letter.
Date: Mon, 27 Nov 2006 18:04:53 +0100	[thread overview]
Message-ID: <877ixgvn0q.fsf@lrde.org> (raw)
In-Reply-To: <m38xhxb4xh.fsf@kfs-l.imdomain.dk> (Kim F. Storm's message of "Mon\, 27 Nov 2006 10\:43\:38 +0100")


[-- Attachment #1.1.1: Type: text/plain, Size: 677 bytes --]

storm@cua.dk (Kim F. Storm) writes:

> michael@cadilhac.name (Michaël Cadilhac) writes:
>
>> Try this :
>> emacs -Q
>> M-x ido-mode
>> C-x C-f /tmp
>>
>> Everything's okey.
>> Now, do the same but before, add a line with a `w' in your known hosts:
>> echo w >> ~/.ssh/known_hosts
>>
>> It will result in the error « Login failed ». Disgracious.

> IIRC, the .. is deliberate.
>
> I would fear that this change will break ido on Windoze as it may then
> confuse single letter hostnames and drive letters, e.g. c: vs. c: ...

You're completely right. The simpler solution is to not allow one
letter hostnames on MS Windows. 

Maybe with the following :


[-- Attachment #1.1.2: ido.patch --]
[-- Type: text/x-patch, Size: 3986 bytes --]

*** lisp/ido.el.~1.110.~	2006-10-16 14:42:24.000000000 +0200
--- lisp/ido.el	2006-11-27 16:58:30.000000000 +0100
***************
*** 1111,1116 ****
--- 1111,1122 ----
  ;; Set to 'ignore to inhibit switching between find-file/switch-buffer.
  (defvar ido-context-switch-command)
  
+ ;; Regexp that matches a hostname.
+ (defconst ido-hostname-regexp
+   (if (memq system-type '(ms-dos windows-nt))
+       ".."
+     "."))
+ 
  ;;; FUNCTIONS
  
  (defun ido-active (&optional merge)
***************
*** 2068,2074 ****
  	      (ido-set-current-directory (file-name-directory (substring ido-current-directory 0 -1))))
  	  (setq ido-set-default-item t))
  
! 	 ((and (string-match (if ido-enable-tramp-completion "..[:@]\\'" "..:\\'") ido-selected)
  	       (ido-is-root-directory)) ;; Ange-ftp or Tramp
  	  (ido-set-current-directory ido-current-directory ido-selected)
  	  (ido-trace "tramp prefix" ido-selected)
--- 2074,2082 ----
  	      (ido-set-current-directory (file-name-directory (substring ido-current-directory 0 -1))))
  	  (setq ido-set-default-item t))
  
! 	 ((and (string-match (concat ido-hostname-regexp
! 				     (if ido-enable-tramp-completion  "[:@]\\'" ":\\'"))
! 			     ido-selected)
  	       (ido-is-root-directory)) ;; Ange-ftp or Tramp
  	  (ido-set-current-directory ido-current-directory ido-selected)
  	  (ido-trace "tramp prefix" ido-selected)
***************
*** 2426,2432 ****
       ((and (= 1 (length ido-matches))
  	   (not (and ido-enable-tramp-completion
  		     (string-equal ido-current-directory "/")
! 		     (string-match "..[@:]\\'" (ido-name (car ido-matches))))))
        ;; only one choice, so select it.
        (if (not ido-confirm-unique-completion)
  	  (exit-minibuffer)
--- 2434,2441 ----
       ((and (= 1 (length ido-matches))
  	   (not (and ido-enable-tramp-completion
  		     (string-equal ido-current-directory "/")
! 		     (string-match (concat ido-hostname-regexp "[@:]\\'")
! 				   (ido-name (car ido-matches))))))
        ;; only one choice, so select it.
        (if (not ido-confirm-unique-completion)
  	  (exit-minibuffer)
***************
*** 3433,3439 ****
        (let ((default-directory ido-current-directory))
  	(ido-to-end ;; move ftp hosts and visited files to end
  	 (delq nil (mapcar
! 		    (lambda (x) (if (or (string-match "..:\\'" x)
  					(and (not (ido-final-slash x))
  					     (get-file-buffer x))) x))
  		    ido-temp-list)))))
--- 3442,3448 ----
        (let ((default-directory ido-current-directory))
  	(ido-to-end ;; move ftp hosts and visited files to end
  	 (delq nil (mapcar
! 		    (lambda (x) (if (or (string-match (concat ido-hostname-regexp ":\\'") x)
  					(and (not (ido-final-slash x))
  					     (get-file-buffer x))) x))
  		    ido-temp-list)))))
***************
*** 4149,4155 ****
  	    (setq refresh t))
  	  ))
  
! 	 ((and (string-match (if ido-enable-tramp-completion "..[:@]\\'" "..:\\'") contents)
  	       (ido-is-root-directory)) ;; Ange-ftp or tramp
  	  (ido-set-current-directory ido-current-directory contents)
  	  (when (ido-is-slow-ftp-host)
--- 4158,4166 ----
  	    (setq refresh t))
  	  ))
  
! 	 ((and (string-match (concat ido-hostname-regexp
! 				     (if ido-enable-tramp-completion "[:@]\\'" ":\\'"))
! 			     contents)
  	       (ido-is-root-directory)) ;; Ange-ftp or tramp
  	  (ido-set-current-directory ido-current-directory contents)
  	  (when (ido-is-slow-ftp-host)
*** lisp/ChangeLog.~1.10261.~	2006-11-06 15:42:02.000000000 +0100
--- lisp/ChangeLog	2006-11-27 17:00:03.000000000 +0100
***************
*** 0 ****
--- 1,7 ----
+ 2006-11-27  Michaël Cadilhac  <michael.cadilhac@lrde.org>
+ 
+ 	* ido.el (ido-hostname-regexp): New.  Regexp that matches a hostname.
+ 	(ido-read-internal): Use it, allowing single letter named hosts on non
+ 	MS Windows systems.
+ 	(ido-complete, ido-make-file-list, ido-exhibit): Ditto.
+ 

[-- Attachment #1.1.3: Type: text/plain, Size: 165 bytes --]



But it's probably better to do that : if the file actually exists (c:
should exist, I suppose), then use it. Otherwise, use tramp.

I can propose the following :


[-- Attachment #1.1.4: ido-2.patch --]
[-- Type: text/x-patch, Size: 4288 bytes --]

*** lisp/ido.el.~1.110.~	2006-10-16 14:42:24.000000000 +0200
--- lisp/ido.el	2006-11-27 17:54:36.000000000 +0100
***************
*** 1142,1147 ****
--- 1142,1152 ----
  	  (pop-to-buffer b t t)
  	  (setq truncate-lines t)))))
  
+ (defun ido-local-file-exists-p (file)
+   "Tell if FILE exists locally."
+   (let (file-name-handler-alist)
+     (file-exists-p file)))
+ 
  (defun ido-unc-hosts (&optional query)
    "Return list of UNC host names."
    (let ((hosts
***************
*** 2068,2074 ****
  	      (ido-set-current-directory (file-name-directory (substring ido-current-directory 0 -1))))
  	  (setq ido-set-default-item t))
  
! 	 ((and (string-match (if ido-enable-tramp-completion "..[:@]\\'" "..:\\'") ido-selected)
  	       (ido-is-root-directory)) ;; Ange-ftp or Tramp
  	  (ido-set-current-directory ido-current-directory ido-selected)
  	  (ido-trace "tramp prefix" ido-selected)
--- 2073,2080 ----
  	      (ido-set-current-directory (file-name-directory (substring ido-current-directory 0 -1))))
  	  (setq ido-set-default-item t))
  
! 	 ((and (not (ido-local-file-exists-p ido-selected))
! 	       (string-match (if ido-enable-tramp-completion ".[:@]\\'" ".:\\'") ido-selected)
  	       (ido-is-root-directory)) ;; Ange-ftp or Tramp
  	  (ido-set-current-directory ido-current-directory ido-selected)
  	  (ido-trace "tramp prefix" ido-selected)
***************
*** 2426,2432 ****
       ((and (= 1 (length ido-matches))
  	   (not (and ido-enable-tramp-completion
  		     (string-equal ido-current-directory "/")
! 		     (string-match "..[@:]\\'" (ido-name (car ido-matches))))))
        ;; only one choice, so select it.
        (if (not ido-confirm-unique-completion)
  	  (exit-minibuffer)
--- 2432,2439 ----
       ((and (= 1 (length ido-matches))
  	   (not (and ido-enable-tramp-completion
  		     (string-equal ido-current-directory "/")
! 		     (not (ido-local-file-exists-p (ido-name (car ido-matches))))
! 		     (string-match ".[@:]\\'" (ido-name (car ido-matches))))))
        ;; only one choice, so select it.
        (if (not ido-confirm-unique-completion)
  	  (exit-minibuffer)
***************
*** 3433,3441 ****
        (let ((default-directory ido-current-directory))
  	(ido-to-end ;; move ftp hosts and visited files to end
  	 (delq nil (mapcar
! 		    (lambda (x) (if (or (string-match "..:\\'" x)
  					(and (not (ido-final-slash x))
! 					     (get-file-buffer x))) x))
  		    ido-temp-list)))))
      (ido-to-end  ;; move . files to end
       (delq nil (mapcar
--- 3440,3450 ----
        (let ((default-directory ido-current-directory))
  	(ido-to-end ;; move ftp hosts and visited files to end
  	 (delq nil (mapcar
! 		    (lambda (x) (if (or (and (not (ido-local-file-exists-p x))
! 					     (string-match ".:\\'" x))
  					(and (not (ido-final-slash x))
! 					     (let (file-name-handler-alist)
! 					       (get-file-buffer x)))) x))
  		    ido-temp-list)))))
      (ido-to-end  ;; move . files to end
       (delq nil (mapcar
***************
*** 4149,4155 ****
  	    (setq refresh t))
  	  ))
  
! 	 ((and (string-match (if ido-enable-tramp-completion "..[:@]\\'" "..:\\'") contents)
  	       (ido-is-root-directory)) ;; Ange-ftp or tramp
  	  (ido-set-current-directory ido-current-directory contents)
  	  (when (ido-is-slow-ftp-host)
--- 4158,4165 ----
  	    (setq refresh t))
  	  ))
  
! 	 ((and (not (ido-local-file-exists-p contents))
! 	       (string-match (if ido-enable-tramp-completion ".[:@]\\'" ".:\\'") contents)
  	       (ido-is-root-directory)) ;; Ange-ftp or tramp
  	  (ido-set-current-directory ido-current-directory contents)
  	  (when (ido-is-slow-ftp-host)
*** lisp/ChangeLog.~1.10261.~	2006-11-06 15:42:02.000000000 +0100
--- lisp/ChangeLog	2006-11-27 17:58:48.000000000 +0100
***************
*** 0 ****
--- 1,8 ----
+ 2006-11-27  Michaël Cadilhac  <michael.cadilhac@lrde.org>
+ 
+ 	* ido.el (ido-local-file-exists-p): New. Tell if a file exists
+ 	locally, i.e. without using file name handlers.
+ 	(ido-read-internal): Allow mono letter host names, avoiding the
+ 	`c:' problem by testing if the file exists locally.
+ 	(ido-complete, ido-make-file-list, ido-exhibit): Ditto.
+ 

[-- Attachment #1.1.5: Type: text/plain, Size: 648 bytes --]


but I really don't know if it works on Windows.

BTW, something tickles me about all that: why functions like
file-exists-p & co doesn't check if the file is not an actual
stat(2)-able file before getting any fanciness with file name
handlers ?

-- 
/!\ My mail address has changed, please update your files accordingly.
 |      Michaël `Micha' Cadilhac   |  «Tu aimeras ton prochain.»            |
 |         Epita/LRDE Promo 2007   |    D'abord, Dieu ou pas,               |
 |  http://michael.cadilhac.name   |       j'ai horreur qu'on me tutoie.    |
 `--  -   JID: micha@amessage.be --'           -- P. Desproges         -  --'

[-- Attachment #1.2: Type: application/pgp-signature, Size: 188 bytes --]

[-- Attachment #2: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel

  reply	other threads:[~2006-11-27 17:04 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-11-26 20:00 Ido and hosts named with a single letter Michaël Cadilhac
2006-11-27  9:43 ` Kim F. Storm
2006-11-27 17:04   ` Michaël Cadilhac [this message]
2006-11-28  8:58     ` Kim F. Storm
2006-11-28 13:13       ` File name handlers and local files Michaël Cadilhac
2006-11-28 14:50         ` Michael Albinus
2006-11-28 15:13           ` Michaël Cadilhac
2006-11-28 14:54         ` Andreas Schwab
2006-11-30 20:52     ` Ido and hosts named with a single letter Kim F. Storm

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=877ixgvn0q.fsf@lrde.org \
    --to=michael@cadilhac.name \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.