【问题标题】:How to limit the number of "suggestions" that flyspell gives?如何限制flyspell给出的“建议”的数量?
【发布时间】:2013-10-04 16:29:35
【问题描述】:

在emacs flyspell模式下,有时建议列表真的很长,以至于弹出菜单比屏幕高,需要垂直滚动菜单,因为“保存单词”选项位于菜单底部.

有没有办法执行以下操作之一:

  1. 将“保存单词”移到菜单顶部?
  2. 对显示的建议数量进行硬性限制?
  3. 修改匹配词的阈值?

【问题讨论】:

标签: emacs menu flyspell


【解决方案1】:

此代码会将所有 ispell 解决方案限制为最大 limit-ispell-choices-to,这将在 flyspell 中获得所需的限制。

(defvar limit-ispell-choices-to 5
  "Number indicating the maximum number of choices to present")

(defadvice ispell-parse-output (after limit-ispell-choices activate)
  (when (and (listp ad-return-value)
             ad-return-value)
    (let* ((miss-list-end (nthcdr (- limit-ispell-choices-to 1) 
                                  (nth 2 ad-return-value)))
           (guess-list-end (nthcdr (- limit-ispell-choices-to 1) 
                                   (nth 3 ad-return-value))))
      (when miss-list-end (setcdr miss-list-end nil))
      (when guess-list-end (setcdr guess-list-end nil)))))

【讨论】:

    【解决方案2】:

    这会将“保存单词”放在顶部。我只是在源代码中交换了两个词。 这有点小技巧,但我找不到更好的方法。

    (defun flyspell-emacs-popup (event poss word)
      "The Emacs popup menu."
      (unless window-system
        (error "This command requires pop-up dialogs"))
      (if (not event)
          (let* ((mouse-pos  (mouse-position))
             (mouse-pos  (if (nth 1 mouse-pos)
                     mouse-pos
                   (set-mouse-position (car mouse-pos)
                               (/ (frame-width) 2) 2)
                   (mouse-position))))
        (setq event (list (list (car (cdr mouse-pos))
                    (1+ (cdr (cdr mouse-pos))))
                  (car mouse-pos)))))
      (let* ((corrects   (if flyspell-sort-corrections
                 (sort (car (cdr (cdr poss))) 'string<)
                   (car (cdr (cdr poss)))))
         (cor-menu   (if (consp corrects)
                 (mapcar (lambda (correct)
                       (list correct correct))
                     corrects)
                   '()))
         (affix      (car (cdr (cdr (cdr poss)))))
         show-affix-info
         (base-menu  (let ((save (if (and (consp affix) show-affix-info)
                         (list
                          (list (concat "Save affix: " (car affix))
                            'save)
                          '("Accept (session)" session)
                          '("Accept (buffer)" buffer))
                       '(("Save word" save)
                         ("Accept (session)" session)
                         ("Accept (buffer)" buffer)))))
                   (if (consp cor-menu)
                   (append save (cons "" cor-menu))
                 save)))
         (menu       (cons "flyspell correction menu" base-menu)))
        (car (x-popup-menu event
                   (list (format "%s [%s]" word (or ispell-local-dictionary
                                ispell-dictionary))
                     menu)))))
    

    【讨论】:

      猜你喜欢
      • 2019-09-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-17
      • 2020-10-28
      • 1970-01-01
      相关资源
      最近更新 更多