avoid double choices reversing

Both yas-choose-value the yas-prompt-functions were reversing
values (cancelling each other out), instead just keep the choices in
order the whole time.
This commit is contained in:
Noam Postavsky 2014-03-02 11:18:54 -05:00
parent 83c174c96c
commit 3744f92ad2

View File

@ -1542,25 +1542,24 @@ Optional PROMPT sets the prompt to use."
;; up as `yas--all-templates' I think. ;; up as `yas--all-templates' I think.
;; ;;
(when (and window-system choices) (when (and window-system choices)
(let ((chosen (or
(let (menu d) ;; d for display (let* ((display-fn (or display-fn #'identity))
(dolist (c choices) (menu
(setq d (or (and display-fn (funcall display-fn c)) (list prompt
c)) (cons "title"
(cond ((stringp d) (mapcar (lambda (c)
(push (cons (concat " " d) c) menu)) (let ((d (funcall display-fn c)))
((listp d) (cond ((stringp d) (cons (concat " " d) c))
(push (car d) menu)))) ((listp d) (car d)))))
(setq menu (list prompt (push "title" menu))) choices)))))
(x-popup-menu (if (fboundp 'posn-at-point) (x-popup-menu (if (fboundp 'posn-at-point)
(let ((x-y (posn-x-y (posn-at-point (point))))) (let ((x-y (posn-x-y (posn-at-point (point)))))
(list (list (+ (car x-y) 10) (list (list (+ (car x-y) 10)
(+ (cdr x-y) 20)) (+ (cdr x-y) 20))
(selected-window))) (selected-window)))
t) t)
menu)))) menu))
(or chosen (keyboard-quit))))
(keyboard-quit)))))
(defun yas--x-pretty-prompt-templates (prompt templates) (defun yas--x-pretty-prompt-templates (prompt templates)
"Display TEMPLATES, grouping neatly by table name." "Display TEMPLATES, grouping neatly by table name."
@ -1601,46 +1600,28 @@ Optional PROMPT sets the prompt to use."
(defun yas-dropdown-prompt (_prompt choices &optional display-fn) (defun yas-dropdown-prompt (_prompt choices &optional display-fn)
(when (fboundp 'dropdown-list) (when (fboundp 'dropdown-list)
(let (formatted-choices (let* ((formatted-choices (if display-fn (delete-if-not display-fn choices)
filtered-choices choices))
d (filtered-choices (if display-fn (mapcar display-fn filtered-choices)
n) choices))
(dolist (choice choices) (n (and formatted-choices
(setq d (or (and display-fn (funcall display-fn choice)) (dropdown-list formatted-choices))))
choice))
(when (stringp d)
(push d formatted-choices)
(push choice filtered-choices)))
(setq n (and formatted-choices (dropdown-list formatted-choices)))
(if n (if n
(nth n filtered-choices) (nth n filtered-choices)
(keyboard-quit))))) (keyboard-quit)))))
(defun yas-completing-prompt (prompt choices &optional display-fn completion-fn) (defun yas-completing-prompt (prompt choices &optional display-fn completion-fn)
(let (formatted-choices (let* ((formatted-choices (if display-fn (delete-if-not display-fn choices)
filtered-choices choices))
chosen (filtered-choices (if display-fn (mapcar display-fn filtered-choices)
d choices))
(completion-fn (or completion-fn (chosen (and formatted-choices
#'completing-read))) (funcall (or completion-fn #'completing-read)
(dolist (choice choices) prompt formatted-choices
(setq d (or (and display-fn (funcall display-fn choice)) nil 'require-match nil nil)))
choice)) (position (and chosen
(when (stringp d) (position chosen formatted-choices :test #'string=))))
(push d formatted-choices) (nth (or position 0) filtered-choices)))
(push choice filtered-choices)))
(setq chosen (and formatted-choices
(funcall completion-fn prompt
formatted-choices
nil
'require-match
nil
nil)))
(let ((position (or (and chosen
(position chosen formatted-choices :test #'string=))
0)))
(nth position filtered-choices))))
(defun yas-no-prompt (_prompt choices &optional _display-fn) (defun yas-no-prompt (_prompt choices &optional _display-fn)
(first choices)) (first choices))
@ -2808,10 +2789,11 @@ If found, the content of subexp group SUBEXP (default 0) is
The last element of POSSIBILITIES may be a list of strings." The last element of POSSIBILITIES may be a list of strings."
(unless (or yas-moving-away-p (unless (or yas-moving-away-p
yas-modified-p) yas-modified-p)
(setq possibilities (nreverse possibilities)) (let* ((last-link (last possibilities))
(setq possibilities (if (listp (car possibilities)) (last-elem (car last-link)))
(append (reverse (car possibilities)) (rest possibilities)) (when (listp last-elem)
possibilities)) (setcar last-link (car last-elem))
(setcdr last-link (cdr last-elem))))
(some #'(lambda (fn) (some #'(lambda (fn)
(funcall fn "Choose: " possibilities)) (funcall fn "Choose: " possibilities))
yas-prompt-functions))) yas-prompt-functions)))