【问题标题】:Calling Emacs' Eshell's eshell-previous-matching-input-from-input from elisp从 elisp 调用 Emacs 的 Eshell 的 eshell-previous-matching-input-from-input
【发布时间】:2019-11-26 21:55:11
【问题描述】:

我想让我在 eshell 中的向上箭头键是 eshell-previous-matching-input-from-input,当点位于最大点时,原样,否则为上一行。我写过

(defun my-up-arrow-in-eshell() (交互式) (如果(=(点)(点最大)) (eshell-previous-matching-input-from-input) ;别的 (上一行) ) ) (add-hook 'eshell-mode-hook (拉姆达() (define-key eshell-mode-map (kbd "&ltup>") 'my-up-arrow-in-eshell)))

但这不对,因为 eshell-previous-matching-input-from-input 需要一个参数。我可以将其硬编码为 0,但这适用于单次按下向上箭头键(在最大点时)。我希望它在最高点时像开箱即用一样工作。我的论点是什么?

【问题讨论】:

    标签: emacs eshell


    【解决方案1】:

    eshell-previous-matching-input-from-input 的实现方式依赖于last-command 来正确浏览输入历史记录。将 up 绑定到然后调用 eshell-previous-matching-input-from-input 的新函数因此在当前实现中无法按预期工作。

    如果您不想完全重新实现eshell-previous-matching-input-from-input,您还可以建议现有功能如下:

    (advice-add 'eshell-previous-matching-input-from-input
            :before-until
            (lambda (&rest r)
              (when (and (eq this-command 'eshell-previous-matching-input-from-input)
                 (/= (point) (point-max)))
            (previous-line) t)))
    

    【讨论】:

    • 这是一个很好的答案!令人惊讶的是没有赞成票。我刚才给了+1!我查看了您的个人资料,发现您致力于 Area51 的蛋白质建模提案。很抱歉没有成功。我提出了一个Materials Modeling 网站,该网站涵盖蛋白质建模,还包括其他材料,如太阳能电池、光伏、储能材料、电池的新发展,
    • 以及用于汽车、飞机、宇宙飞船等的更轻或更坚固的材料。如果您能进入私人测试版,那就太好了!如果您认为这不会带来不便,请提交!
    【解决方案2】:

    您可以使用(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)))
    

    最后一个选项可能是条件绑定(参见 (elisp)Extended Menu Items),其中当点位于 point-max 时绑定 eshell-previous-matching-input-from-input

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

    【讨论】:

    • 我尝试了你的第一个和第二个,当第二次按下向上箭头键时,它们都没有正确移动到倒数第二个输入。
    • @SteveBiederman 我没有意识到它是如何工作的(连续调用的特殊行为)——请参阅更新
    猜你喜欢
    • 1970-01-01
    • 2011-07-28
    • 1970-01-01
    • 1970-01-01
    • 2017-10-09
    • 2011-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多