[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 3744f92 098/177: avoid double choices reversing
From: |
João Távora |
Subject: |
[elpa] master 3744f92 098/177: avoid double choices reversing |
Date: |
Sat, 28 Mar 2015 15:41:12 +0000 |
branch: master
commit 3744f92ad21860ca2fa7e008e3e4311851117ace
Author: Noam Postavsky <address@hidden>
Commit: Noam Postavsky <address@hidden>
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.
---
yasnippet.el | 98 +++++++++++++++++++++++----------------------------------
1 files changed, 40 insertions(+), 58 deletions(-)
diff --git a/yasnippet.el b/yasnippet.el
index 608cccf..f585b88 100644
--- a/yasnippet.el
+++ b/yasnippet.el
@@ -1542,25 +1542,24 @@ Optional PROMPT sets the prompt to use."
;; 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)))))
+ (or
+ (let* ((display-fn (or display-fn #'identity))
+ (menu
+ (list prompt
+ (cons "title"
+ (mapcar (lambda (c)
+ (let ((d (funcall display-fn c)))
+ (cond ((stringp d) (cons (concat " " d)
c))
+ ((listp d) (car d)))))
+ choices)))))
+ (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))
+ (keyboard-quit))))
(defun yas--x-pretty-prompt-templates (prompt templates)
"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)
(when (fboundp 'dropdown-list)
- (let (formatted-choices
- filtered-choices
- d
- n)
- (dolist (choice choices)
- (setq d (or (and display-fn (funcall display-fn choice))
- choice))
- (when (stringp d)
- (push d formatted-choices)
- (push choice filtered-choices)))
-
- (setq n (and formatted-choices (dropdown-list formatted-choices)))
+ (let* ((formatted-choices (if display-fn (delete-if-not display-fn choices)
+ choices))
+ (filtered-choices (if display-fn (mapcar display-fn
filtered-choices)
+ choices))
+ (n (and formatted-choices
+ (dropdown-list formatted-choices))))
(if n
(nth n filtered-choices)
(keyboard-quit)))))
(defun yas-completing-prompt (prompt choices &optional display-fn
completion-fn)
- (let (formatted-choices
- filtered-choices
- chosen
- d
- (completion-fn (or completion-fn
- #'completing-read)))
- (dolist (choice choices)
- (setq d (or (and display-fn (funcall display-fn choice))
- choice))
- (when (stringp d)
- (push d formatted-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))))
+ (let* ((formatted-choices (if display-fn (delete-if-not display-fn choices)
+ choices))
+ (filtered-choices (if display-fn (mapcar display-fn filtered-choices)
+ choices))
+ (chosen (and formatted-choices
+ (funcall (or completion-fn #'completing-read)
+ prompt formatted-choices
+ nil 'require-match nil nil)))
+ (position (and chosen
+ (position chosen formatted-choices :test #'string=))))
+ (nth (or position 0) filtered-choices)))
(defun yas-no-prompt (_prompt choices &optional _display-fn)
(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."
(unless (or yas-moving-away-p
yas-modified-p)
- (setq possibilities (nreverse possibilities))
- (setq possibilities (if (listp (car possibilities))
- (append (reverse (car possibilities)) (rest
possibilities))
- possibilities))
+ (let* ((last-link (last possibilities))
+ (last-elem (car last-link)))
+ (when (listp last-elem)
+ (setcar last-link (car last-elem))
+ (setcdr last-link (cdr last-elem))))
(some #'(lambda (fn)
(funcall fn "Choose: " possibilities))
yas-prompt-functions)))
- [elpa] master 78c8b5e 090/177: yas--document-symbol: fix no transform case, (continued)
- [elpa] master 78c8b5e 090/177: yas--document-symbol: fix no transform case, João Távora, 2015/03/28
- [elpa] master e190b08 088/177: Rakefile: don't fail with EMACS=t env setting, João Távora, 2015/03/28
- [elpa] master df58222 089/177: yas--document-symbols: respect level arg, raise to 1, João Távora, 2015/03/28
- [elpa] master f94c38e 091/177: Merge pull request #449 from nibua-r/https-submodules, João Távora, 2015/03/28
- [elpa] master 3002043 093/177: Sync git submodule for yasmate repo, João Távora, 2015/03/28
- [elpa] master 0f8c2ab 094/177: Add `yas-after-reload-hook' and run it at the end of `yas-reload-all', João Távora, 2015/03/28
- [elpa] master 987942c 095/177: update snippets submodule, João Távora, 2015/03/28
- [elpa] master c128580 096/177: yasnippet templates don't add newlines, João Távora, 2015/03/28
- [elpa] master 83c174c 097/177: Merge pull request #464 from kidd/master, João Távora, 2015/03/28
- [elpa] master 12b7f82 092/177: Add Travis CI and update tests. Start a Changelog., João Távora, 2015/03/28
- [elpa] master 3744f92 098/177: avoid double choices reversing,
João Távora <=
- [elpa] master 1fc858f 099/177: Remove experimental Changelog file, João Távora, 2015/03/28
- [elpa] master 4d220f7 100/177: Remove an obsolete hack notice, João Távora, 2015/03/28
- [elpa] master 4470110 101/177: display-fn isn't actually used for filtering, João Távora, 2015/03/28
- [elpa] master c07db05 102/177: yas-x-prompt: remove dead code, João Távora, 2015/03/28
- [elpa] master 43a501a 103/177: remove yas--x-pretty-prompt-templates, João Távora, 2015/03/28
- [elpa] master 8e7295b 108/177: Closes #403: more uniform behaviour for `yas-use-menu', João Távora, 2015/03/28
- [elpa] master 498cbe4 105/177: Closes #469: Don't use `yas--init-minor-keymap', João Távora, 2015/03/28
- [elpa] master e7599b9 104/177: Merge pull request #466 from npostavs/no-reverse, João Távora, 2015/03/28
- [elpa] master a4e04f9 109/177: update doc for org 8.x, João Távora, 2015/03/28
- [elpa] master a0c2217 110/177: Merge pull request #473 from npostavs/org8, João Távora, 2015/03/28