]> code.delx.au - gnu-emacs-elpa/commitdiff
Merge pull request #466 from npostavs/no-reverse
authorJoão Távora <joaotavora@gmail.com>
Thu, 6 Mar 2014 08:05:53 +0000 (08:05 +0000)
committerJoão Távora <joaotavora@gmail.com>
Thu, 6 Mar 2014 08:05:53 +0000 (08:05 +0000)
Avoid double choices reversing

1  2 
yasnippet.el

diff --cc yasnippet.el
index b3b51573b231d2a87bb0c97a68aee8881a45809a,1a87e3984518948e022adec2f78bbbb1be9ec217..f4b475146798873a1ba2eac2a74932d529022464
@@@ -1534,57 -1528,27 +1528,20 @@@ Optional PROMPT sets the prompt to use.
  
  (defun yas-x-prompt (prompt choices &optional display-fn)
    "Display choices in a x-window prompt."
 -  ;; FIXME: HACK: if we notice that one of the objects in choices is
 -  ;; actually a `yas--template', defer to `yas--x-prompt-pretty-templates'
 -  ;;
 -  ;; This would be better implemented by passing CHOICES as a
 -  ;; structured tree rather than a list. Modifications would go as far
 -  ;; up as `yas--all-templates' I think.
 -  ;;
    (when (and window-system choices)
-     (let ((chosen
-            (let (menu d) ;; d for display
-              (dolist (c choices)
-                (setq d (or (and display-fn (funcall display-fn c))
-                            c))
-                (cond ((stringp d)
-                       (push (cons (concat "   " d) c) menu))
-                      ((listp d)
-                       (push (car d) menu))))
-              (setq menu (list prompt (push "title" menu)))
-              (x-popup-menu (if (fboundp 'posn-at-point)
-                                (let ((x-y (posn-x-y (posn-at-point (point)))))
-                                  (list (list (+ (car x-y) 10)
-                                              (+ (cdr x-y) 20))
-                                        (selected-window)))
-                              t)
-                            menu))))
-       (or chosen
-           (keyboard-quit)))))
- (defun yas--x-pretty-prompt-templates (prompt templates)
-   "Display TEMPLATES, grouping neatly by table name."
-   (let ((organized (make-hash-table :test #'equal))
-         menu
-         more-than-one-table
-         prefix)
-     (dolist (tl templates)
-       (puthash (yas--template-table tl)
-                (cons tl
-                      (gethash (yas--template-table tl) organized))
-                organized))
-     (setq more-than-one-table (> (hash-table-count organized) 1))
-     (setq prefix (if more-than-one-table
-                      "   " ""))
-     (if more-than-one-table
-         (maphash #'(lambda (table templates)
-                      (push (yas--table-name table) menu)
-                      (dolist (tl templates)
-                        (push (cons (concat prefix (yas--template-name tl)) tl) menu))) organized)
-       (setq menu (mapcar #'(lambda (tl) (cons (concat prefix (yas--template-name tl)) tl)) templates)))
-     (setq menu (nreverse menu))
-     (or (x-popup-menu (if (fboundp 'posn-at-point)
-                           (let ((x-y (posn-x-y (posn-at-point (point)))))
-                             (list (list (+ (car x-y) 10)
-                                         (+ (cdr x-y) 20))
-                                   (selected-window)))
-                         t)
-                       (list prompt (push "title" menu)))
-         (keyboard-quit))))
+     (or
+      (x-popup-menu
+       (if (fboundp 'posn-at-point)
+           (let ((x-y (posn-x-y (posn-at-point (point)))))
+             (list (list (+ (car x-y) 10)
+                         (+ (cdr x-y) 20))
+                   (selected-window)))
+         t)
+       `(,prompt ("title"
+                  ,@(mapcar* (lambda (c d) `(,(concat "   " d) . ,c))
+                             choices
+                             (if display-fn (mapcar display-fn choices) choices)))))
+      (keyboard-quit))))
  
  (defun yas-ido-prompt (prompt choices &optional display-fn)
    (when (and (fboundp 'ido-completing-read)