emacs - 该机制 iswtichb 用于显示完成情况

标签 emacs elisp

全部。

今天早上我决定破解 iswitchb,并发现了一件令人困惑的事情。

通常,当我们命令 iswitchb 时,我们会在迷你缓冲区中得到一些内容,例如:

iswitch {缓冲区1,缓冲区2 ...}

大括号中的是完成的内容,当我们输入它的数字时 正在萎缩。

而且我没有发现 iswitchb 在 hacking 时是如何实现这一点的 它的代码(抱歉我的迟钝)。

这是原始的 iswitchb-read-buffer,文档字符串已被撕毁 关闭:

(defun iswitchb-read-buffer (prompt &optional default require-match
                    start matches-set)
  (let
      (
       buf-sel
       iswitchb-final-text
       (icomplete-mode nil) ;; prevent icomplete starting up
       )

    (iswitchb-define-mode-map)
    (setq iswitchb-exit nil)
    (setq iswitchb-default
      (if (bufferp default)
          (buffer-name default)
        default))
    (setq iswitchb-text (or start ""))
    (unless matches-set
      (setq iswitchb-rescan t)
      (iswitchb-make-buflist iswitchb-default)
      (iswitchb-set-matches))
    (let
    ((minibuffer-local-completion-map iswitchb-mode-map)
     ;; Record the minibuffer depth that we expect to find once
     ;; the minibuffer is set up and iswitchb-entryfn-p is called.
     (iswitchb-minibuf-depth (1+ (minibuffer-depth)))
     (iswitchb-require-match require-match))
      ;; prompt the user for the buffer name
      (setq iswitchb-final-text (completing-read
                 prompt       ;the prompt
                 '(("dummy" . 1)) ;table
                 nil          ;predicate
                 nil ;require-match [handled elsewhere]
                 start  ;initial-contents
                 'iswitchb-history)))
    (if (and (not (eq iswitchb-exit 'usefirst))
         (get-buffer iswitchb-final-text))
    ;; This happens for example if the buffer was chosen with the mouse.
    (setq iswitchb-matches (list iswitchb-final-text)
          iswitchb-virtual-buffers nil))

    ;; If no buffer matched, but a virtual buffer was selected, visit
    ;; that file now and act as though that buffer had been selected.
    (if (and iswitchb-virtual-buffers
         (not (iswitchb-existing-buffer-p)))
    (let ((virt (car iswitchb-virtual-buffers))
          (new-buf))
      ;; Keep the name of the buffer returned by find-file-noselect, as 
      ;; the buffer 'virt' could be a symlink to a file of a different name.
      (setq new-buf (buffer-name (find-file-noselect (cdr virt))))
      (setq iswitchb-matches (list new-buf)
        iswitchb-virtual-buffers nil)))

    ;; Handling the require-match must be done in a better way.
    (if (and require-match
         (not (iswitchb-existing-buffer-p)))
    (error "Must specify valid buffer"))

    (if (or (eq iswitchb-exit 'takeprompt)
        (null iswitchb-matches))
    (setq buf-sel iswitchb-final-text)
      ;; else take head of list
      (setq buf-sel (car iswitchb-matches)))

    ;; Or possibly choose the default buffer
    (if  (equal iswitchb-final-text "")
    (setq buf-sel (car iswitchb-matches)))

    buf-sel))

这是 iswitchb-read 缓冲区的一部分,我认为 负责运行完成机制。

 (defun iswitchb-read-buffer (prompt &optional default require-match
                        start matches-set)
    (let
          (
           (iswitchb-minibuf-depth (1+ (minibuffer-depth)))
           )
       ;; prompt the user for the buffer name
       (completing-read
                 prompt       ;the prompt
                 '(("dummy" . 1)) ;table
                 nil          ;predicate
                 nil ;require-match [handled elsewhere]
                 start  ;initial-contents
                 'iswitchb-history)))

评估

 (iswitchb-read-buffer "Test: ")

结果

测试:{缓冲区1,缓冲区2,...}

所以,我认为我是对的。

所以,让我困惑的是sexp如何:

(iswitchb-minibuf-depth (1+ (minibuffer-depth)))

对迷你缓冲区中的回声有影响。评论这个 sexp,或将 iswitchb-minibuffer-深度 替换为另一个 变量,完成将消失。

有什么建议吗?

最佳答案

此变量在从 iswitchb-minibuffer-setup 调用的 iswitchb-entryfn-p 中使用

(defun iswitchb-minibuffer-setup ()
  "Set up minibuffer for `iswitchb-buffer'.
Copied from `icomplete-minibuffer-setup-hook'."
  (when (iswitchb-entryfn-p)
    (set (make-local-variable 'iswitchb-use-mycompletion) t)
    (add-hook 'pre-command-hook 'iswitchb-pre-command nil t)
    (add-hook 'post-command-hook 'iswitchb-post-command nil t)
    (run-hooks 'iswitchb-minibuffer-setup-hook)))

iswitchb-minibuf-depth为空时,iswitchb-entryfn-p为空并且设置未完成。

iswitchb-minibuffer-setup 是一个添加到 iswitchb-mode 的钩子(Hook)。

关于emacs - 该机制 iswtichb 用于显示完成情况,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9188968/

相关文章:

emacs - 在 emacs-ess 中启用暂存缓冲区以执行 R 代码

emacs - 如何删除 Emacs 中的空格和回车符?

emacs - Emacs lisp 中的 "exec"?

emacs - 强制 AUCTeX 解析整个文档

linux - 如何检查 Xorg 是否在 emacs lisp 中运行?

linux - 使用 mmap 的 Emacs 缓冲区分配

更新 python-mode 后,python virtualenv.el 不再在 emacs 中工作

emacs - emacs 中的 "Programmer shortcuts"是什么?

emacs - 在 Emacs Lisp 中逐步迭代列表

emacs - 使用 let-bound 变量穿透 `set-process-sentinel` 层次结构