Pergunta

In emacs flyspell mode, sometimes the list of suggestions is really long, so that the pop-up menu is taller than the screen and requires vertical scrolling of the menu because the "Save word" option is at the bottom of the menu.

Is there a way to to do one of the following:

  1. Move "Save word" to the top of the menu?
  2. Put a hard limit on the number of suggestions displayed?
  3. Modify the threshold of a matching word?
Foi útil?

Solução

This code will limit all ispell solutions to a maximum of limit-ispell-choices-to, which gets the desired limit in 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)))))

Outras dicas

This will put "Save word" at the top. I just swapped two words in the source. It's a bit of a hack, but I can't see a better way.

(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)))))
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top