在Linux下,eshell autojump将进行区分大小写的匹配,我只是觉得这很麻烦。我曾试图通过建议eshell/j使用总是返回t的eshell-under-windows-p来规避这一点,但令我懊恼的是,中调用的ushell/j不受cl letf的影响。我修改了我的eshell/j一点,以提供一些调试信息:
;; Modified eshell/j inside eshell-autojump.el to this
(defun eshell/j (&rest args) ; all but first ignored
"Jump to a directory you often cd to.
This compares the argument with the list of directories you usually jump to.
Without an argument, list the ten most common directories.
With a positive integer argument, list the n most common directories.
Otherwise, call `eshell/cd' with the result."
(setq args (eshell-flatten-list args))
(let ((path (car args))
(candidates (eshell-autojump-candidates))
(case-fold-search (eshell-under-windows-p))
result)
(when (not path)
(setq path 10))
(message "case-fold-search = %S" case-fold-search)
(message "eshell-under-windows-p returns %s from inside eshell/j" (eshell-under-windows-p))
(if (and (integerp path) (> path 0))
(progn
(let ((n (nthcdr (1- path) candidates)))
(when n
(setcdr n nil)))
(eshell-lisp-command (mapconcat 'identity candidates "n")))
(while (and candidates (not result))
(if (string-match path (car candidates))
(setq result (car candidates))
(setq candidates (cdr candidates))))
(eshell/cd result))))
我的init.el添加了一条建议,试图通过欺骗eshell/j使其认为我们在Windows:上而使其无案例
;; Added to init.el
(require 'eshell-autojump)
(advice-add 'eshell/j :around
(lambda (orig-fun &rest xs)
(cl-letf (((symbol-function 'eshell-under-windows-p) (lambda () t)))
(progn (message "eshell-under-windows-p returns %s from lambda" (eshell-under-windows-p)) (apply orig-fun xs)))))
但当我尝试跳转到eshell时,我在消息缓冲区中得到的只有:
;; I get in *Messages*
eshell-under-windows-p returns t from lambda
case-fold-search = nil
eshell-under-windows-p returns nil from inside eshell/j
我对elisp的新手知识不足以解决这里可能存在的范围界定问题。有人能解释为什么eshell-under-window-p在从eshell/j调用时不受影响吗?
我找到了答案cl-letf不适用于字节编译的函数。由于eshell autojump是一个包,它在安装时会编译字节,并且cl-letf不能用于修改它的内部行为。
最后,我成功地通过欺骗了eshell/j使其不区分大小写
(defun my/eshell-j-case-insensitive (orig-fun &rest args)
"Advice function to make `eshell/j' case-insensitive."
(let ((original-system-type system-type))
(unwind-protect
(progn
(setq system-type 'windows-nt) ; Temporarily set system-type to Windows
(apply orig-fun args))
(setq system-type original-system-type)))) ; Restore the original system-type
(advice-add 'eshell/j :around #'my/eshell-j-case-insensitive)