[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master e7599b9 104/177: Merge pull request #466 from npostavs/no-
From: |
Jo�o T�vora |
Subject: |
[elpa] master e7599b9 104/177: Merge pull request #466 from npostavs/no-reverse |
Date: |
Sat, 28 Mar 2015 15:41:14 +0000 |
branch: master
commit e7599b9325d1a8b34e05e0a3e5ba62b4755eea2d
Merge: 4d220f7 43a501a
Author: João Távora <address@hidden>
Commit: João Távora <address@hidden>
Merge pull request #466 from npostavs/no-reverse
Avoid double choices reversing
---
yasnippet.el | 140 +++++++++++++++------------------------------------------
1 files changed, 37 insertions(+), 103 deletions(-)
diff --git a/yasnippet.el b/yasnippet.el
index b3b5157..f4b4751 100644
--- a/yasnippet.el
+++ b/yasnippet.el
@@ -1489,10 +1489,6 @@ Here's a list of currently recognized directives:
;;; Popping up for keys and templates
-(defvar yas--x-pretty-prompt-templates nil
- "If non-nil, attempt to prompt for templates like TextMate.")
-
-
(defun yas--prompt-for-template (templates &optional prompt)
"Interactively choose a template from the list TEMPLATES.
@@ -1504,13 +1500,11 @@ Optional PROMPT sets the prompt to use."
(sort templates #'(lambda (t1 t2)
(< (length (yas--template-name t1))
(length (yas--template-name t2))))))
- (if yas--x-pretty-prompt-templates
- (yas--x-pretty-prompt-templates "Choose a snippet" templates)
- (some #'(lambda (fn)
- (funcall fn (or prompt "Choose a snippet: ")
- templates
- #'yas--template-name))
- yas-prompt-functions))))
+ (some #'(lambda (fn)
+ (funcall fn (or prompt "Choose a snippet: ")
+ templates
+ #'yas--template-name))
+ yas-prompt-functions)))
(defun yas--prompt-for-keys (keys &optional prompt)
"Interactively choose a template key from the list KEYS.
@@ -1535,56 +1529,19 @@ Optional PROMPT sets the prompt to use."
(defun yas-x-prompt (prompt choices &optional display-fn)
"Display choices in a x-window prompt."
(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)
@@ -1594,46 +1551,22 @@ 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)))
- (if n
- (nth n filtered-choices)
+ (let* ((formatted-choices
+ (if display-fn (mapcar display-fn choices) choices))
+ (n (dropdown-list formatted-choices)))
+ (if n (nth n choices)
(keyboard-quit)))))
(defun yas-completing-prompt (prompt choices &optional display-fn
completion-fn)
- (let (formatted-choices
- filtered-choices
+ (let* ((formatted-choices
+ (if display-fn (mapcar display-fn choices) choices))
+ (chosen (funcall (or completion-fn #'completing-read)
+ prompt formatted-choices
+ nil 'require-match nil nil)))
+ (if (eq choices formatted-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))))
+ (nth (or (position chosen formatted-choices :test #'string=) 0)
+ choices))))
(defun yas-no-prompt (_prompt choices &optional _display-fn)
(first choices))
@@ -2247,8 +2180,8 @@ Prompt the user if TEMPLATES has more than one element,
else
expand immediately. Common gateway for
`yas-expand-from-trigger-key' and `yas-expand-from-keymap'."
(let ((yas--current-template (or (and (rest templates) ;; more than one
- (yas--prompt-for-template (mapcar #'cdr
templates)))
- (cdar templates))))
+ (yas--prompt-for-template (mapcar
#'cdr templates)))
+ (cdar templates))))
(when yas--current-template
(yas-expand-snippet (yas--template-content yas--current-template)
start
@@ -2801,10 +2734,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 83c174c 097/177: Merge pull request #464 from kidd/master, (continued)
- [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, 2015/03/28
- [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 <=
- [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
- [elpa] master b36a4f7 107/177: Properly closes #469: Don't use `yas--init-minor-keymap', Jo�o T�vora, 2015/03/28
- [elpa] master d809e88 106/177: Revert "Closes #469: Don't use `yas--init-minor-keymap'", Jo�o T�vora, 2015/03/28
- [elpa] master 599a262 113/177: Closes #474: fix cc-mode fontification conflict, Jo�o T�vora, 2015/03/28
- [elpa] master a80033d 115/177: Refactor yas-good-grace error handling, Jo�o T�vora, 2015/03/28
- [elpa] master 4d9eee9 111/177: Simpler, more effective .travis file, Jo�o T�vora, 2015/03/28
- [elpa] master 4473b4e 112/177: New test for cc-mode's fontification functions, Jo�o T�vora, 2015/03/28
- [elpa] master 8ced5c7 117/177: Remove type, expand-env from new snippet value, Jo�o T�vora, 2015/03/28
- [elpa] master 4ccf133 114/177: Merge pull request #476 from npostavs/cc-fontify2, Jo�o T�vora, 2015/03/28