0

Under Linux, eshell-autojump will do case sensitive matching which I just find a nuisance. I've tried to circumvent this by advising eshell/j with a eshell-under-windows-p that always returns t but to my chagrin eshell-under-windows-p invoked in eshell/j is unaffected by cl-letf. I've modified my eshell/j a bit to give me some debug info:

;; 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))))

My init.el adds the advice to attempt to make eshell/j caseless by trying to trick it to think we are on 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)))))

But all I get in Messages buffer when I try to jump in eshell is:

;; 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

My rookie knowledge of elisp is not enough to wrestle with probable scoping issues here. Can anyone decode why eshell-under-window-p is unaffected when called from eshell/j here?

4

1 回答 1

0

我找到了答案。cl-letf不适用于字节编译函数。由于 eshell-autojump 是一个包,它在安装时会进行字节编译,而cl-letf不能用于修改它的内部行为。我不得不求助于重新定义eshell/j这是一个次优的解决方案。

于 2022-01-21T13:36:06.537 回答