今天和emacs的ido-mode较劲了

来源:互联网 发布:微信淘宝优惠券安全吗 编辑:程序博客网 时间:2024/04/28 14:55

 

emacs无疑是最强大的编辑器,最近她又升级到23.2了,内置了强大的cedet。没有不升级一下的道理。

 

升级后主要是把.emacs中关于cedet加载的配置关掉即可。但是我日常使用的ido-mode居然出现了问题。

 

因为在做symbian手机应用开发,所以随大流把所有工程放到了C:/Symbian/Source目录当中,并且用emacs修改,用abld编译。fine,一步步编写越来越多的工程,用helloworldbasic到helloworldplus到multiviews。可以在安装23.2之后,每次在用c-x c-f打开C:/Symbian/Source时,都只能看到一个helloworldbasic目录的补全。没理由啊,我用cmd看过,用explorer看过,source目录下子目录不下20个。

 

我重装回23.1,问题依旧。试过其它目录,补全都正常。

难道是.emacs出问题了(用-q启动正常)。我用二分法试完了.emacs,发现问题依旧。

 

最后怀疑到~/.ido.last文件上,因为在里面看到了C:/Symbian/Source的cache。删之。。

重启emacs。still malfunction...

 

又乱折腾了一会儿,想起,ido-mode可能会在退出时把cache写回.ido.last,所以退出emacs,删.ido.last。终于好了。

 

这个cache功能应该是为了加快ido-mode的提示速度,以前怎么没注意到呢。用customize-group看到ido里面的确有cache,既然有cache,就应该有refresh咯。在补全时键入c-l,立马更新,连删.ido.last都不必,更简单。如果不喜欢cache,把它定制为0也可以。

 

在前面“乱折腾”那会儿,还去查看了ido-find-file,心想它是不是有bug。在看ido-find-file,我震惊了。原来这函数这么强大呀,还支持历史管理、find查找、正则表达式。其中的find查找(在补全时m-f)非常吸引我,这样可以瞬间定位多级子目录中的同名文件。在windows中试了一下,发现不行。ssh到ubuntu中,可用。。。这回铁是bug没错了。。

 

 

我花了些时间修改了 ido-wide-find-dirs-or-files函数,还把cygwin的windows目录名兼容支持打开了。哈哈。以后find-file就可以跨越多级目录补全了。。

P.S:在windows下,find.exe和系统内置的有冲突,所以建议把cygwin版的find复制成cygfind,再把

find-program定制成"cygfind"就好了。

 

;remember to set CYGWIN=nodosfilewarning
(defun ido-wide-find-dirs-or-files (dir file &optional prefix finddir)
  ;; As ido-run-find-command, but returns a list of cons pairs ("file" . "dir")
  (let ((filenames
     (split-string
      (shell-command-to-string
         (concat find-program " " ;"cygfind "
           (shell-quote-argument dir)
           " -name "
           (shell-quote-argument
            (concat (if prefix "" "*") file "*"))
           " -type " (if finddir "d" "f") " -print"))))
    filename d f
    res)
    (while filenames
      (message find-program)
      (setq filename (car filenames)
        filenames (cdr filenames))
      (if (and (or (string-match "^/" filename) (string-match "^.:" filename))
           (file-exists-p filename))
      (setq d (file-name-directory filename)
        f (file-name-nondirectory filename)
        res (cons (cons (if finddir (ido-final-slash f t) f) d) res))))
    res))