1

eshell 内からの上矢印キーを、ポイントが point-max にあるときはそのまま eshell-previous-matching-input-from-input に、それ以外の場合は前の行にしたいと思います。私は書いた

    (defun my-up-arrow-in-eshell() (インタラクティブ)
      (if (= (ポイント) (ポイント最大))
          (eshell-previous-matching-input-from-input)
      ; そうしないと
        (前の行)
      )
    )

    (add-hook 'eshell-mode-hook
      (ラムダ ()
        (define-key eshell-mode-map (kbd "<up>") 'my-up-arrow-in-eshell)))

eshell-previous-matching-input-from-input には引数が必要なためです。これを 0 にハードコードすることはできますが、それは上矢印キーを 1 回押すだけで機能します (最大ポイントの場合)。ポイントマックスのときは、箱から出してすぐに使えるようにしたい。私は議論のために何を与えますか?

4

2 に答える 2

1

を使用して、引数をその形式(call-interactively #'eshell-previous-matching-input-from-input)に従って解釈することができます。interactive

(defun my-up-arrow-in-eshell ()
  (interactive) 
  (if (/= (point) (point-max))
      (previous-line)
    (setq this-command 'eshell-previous-matching-input-from-input)
    (call-interactively #'eshell-previous-matching-input-from-input)))

または、独自の引数を追加して渡すこともできます。

(defun my-up-arrow-in-eshell (arg)
  (interactive "p") 
  (if (= (point) (point-max)) 
      (progn
        (setq this-command 'eshell-previous-matching-input-from-input)
        (eshell-previous-matching-input-from-input arg))
    (previous-line arg)))

最後のオプションはeshell-previous-matching-input-from-input、ポイントがpoint-max

(define-key eshell-hist-mode-map (kbd "<up>")
  '(menu-item "maybe-hist"
              nil
              :filter
              (lambda (&optional _)
                (when (= (point) (point-max))
                  'eshell-previous-matching-input-from-input))))
于 2019-11-26T22:34:55.933 に答える