mirror of
https://github.com/joaotavora/yasnippet.git
synced 2025-10-13 13:13:03 +00:00
Merge pull request #466 from npostavs/no-reverse
Avoid double choices reversing
This commit is contained in:
commit
e7599b9325
140
yasnippet.el
140
yasnippet.el
@ -1489,10 +1489,6 @@ Here's a list of currently recognized directives:
|
|||||||
|
|
||||||
;;; Popping up for keys and templates
|
;;; 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)
|
(defun yas--prompt-for-template (templates &optional prompt)
|
||||||
"Interactively choose a template from the list TEMPLATES.
|
"Interactively choose a template from the list TEMPLATES.
|
||||||
|
|
||||||
@ -1504,13 +1500,11 @@ Optional PROMPT sets the prompt to use."
|
|||||||
(sort templates #'(lambda (t1 t2)
|
(sort templates #'(lambda (t1 t2)
|
||||||
(< (length (yas--template-name t1))
|
(< (length (yas--template-name t1))
|
||||||
(length (yas--template-name t2))))))
|
(length (yas--template-name t2))))))
|
||||||
(if yas--x-pretty-prompt-templates
|
(some #'(lambda (fn)
|
||||||
(yas--x-pretty-prompt-templates "Choose a snippet" templates)
|
(funcall fn (or prompt "Choose a snippet: ")
|
||||||
(some #'(lambda (fn)
|
templates
|
||||||
(funcall fn (or prompt "Choose a snippet: ")
|
#'yas--template-name))
|
||||||
templates
|
yas-prompt-functions)))
|
||||||
#'yas--template-name))
|
|
||||||
yas-prompt-functions))))
|
|
||||||
|
|
||||||
(defun yas--prompt-for-keys (keys &optional prompt)
|
(defun yas--prompt-for-keys (keys &optional prompt)
|
||||||
"Interactively choose a template key from the list KEYS.
|
"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)
|
(defun yas-x-prompt (prompt choices &optional display-fn)
|
||||||
"Display choices in a x-window prompt."
|
"Display choices in a x-window prompt."
|
||||||
(when (and window-system choices)
|
(when (and window-system choices)
|
||||||
(let ((chosen
|
(or
|
||||||
(let (menu d) ;; d for display
|
(x-popup-menu
|
||||||
(dolist (c choices)
|
(if (fboundp 'posn-at-point)
|
||||||
(setq d (or (and display-fn (funcall display-fn c))
|
(let ((x-y (posn-x-y (posn-at-point (point)))))
|
||||||
c))
|
(list (list (+ (car x-y) 10)
|
||||||
(cond ((stringp d)
|
(+ (cdr x-y) 20))
|
||||||
(push (cons (concat " " d) c) menu))
|
(selected-window)))
|
||||||
((listp d)
|
t)
|
||||||
(push (car d) menu))))
|
`(,prompt ("title"
|
||||||
(setq menu (list prompt (push "title" menu)))
|
,@(mapcar* (lambda (c d) `(,(concat " " d) . ,c))
|
||||||
(x-popup-menu (if (fboundp 'posn-at-point)
|
choices
|
||||||
(let ((x-y (posn-x-y (posn-at-point (point)))))
|
(if display-fn (mapcar display-fn choices) choices)))))
|
||||||
(list (list (+ (car x-y) 10)
|
(keyboard-quit))))
|
||||||
(+ (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))))
|
|
||||||
|
|
||||||
(defun yas-ido-prompt (prompt choices &optional display-fn)
|
(defun yas-ido-prompt (prompt choices &optional display-fn)
|
||||||
(when (and (fboundp 'ido-completing-read)
|
(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)
|
(defun yas-dropdown-prompt (_prompt choices &optional display-fn)
|
||||||
(when (fboundp 'dropdown-list)
|
(when (fboundp 'dropdown-list)
|
||||||
(let (formatted-choices
|
(let* ((formatted-choices
|
||||||
filtered-choices
|
(if display-fn (mapcar display-fn choices) choices))
|
||||||
d
|
(n (dropdown-list formatted-choices)))
|
||||||
n)
|
(if n (nth n choices)
|
||||||
(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)
|
|
||||||
(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
|
||||||
filtered-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
|
chosen
|
||||||
d
|
(nth (or (position chosen formatted-choices :test #'string=) 0)
|
||||||
(completion-fn (or completion-fn
|
choices))))
|
||||||
#'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))))
|
|
||||||
|
|
||||||
(defun yas-no-prompt (_prompt choices &optional _display-fn)
|
(defun yas-no-prompt (_prompt choices &optional _display-fn)
|
||||||
(first choices))
|
(first choices))
|
||||||
@ -2247,8 +2180,8 @@ Prompt the user if TEMPLATES has more than one element, else
|
|||||||
expand immediately. Common gateway for
|
expand immediately. Common gateway for
|
||||||
`yas-expand-from-trigger-key' and `yas-expand-from-keymap'."
|
`yas-expand-from-trigger-key' and `yas-expand-from-keymap'."
|
||||||
(let ((yas--current-template (or (and (rest templates) ;; more than one
|
(let ((yas--current-template (or (and (rest templates) ;; more than one
|
||||||
(yas--prompt-for-template (mapcar #'cdr templates)))
|
(yas--prompt-for-template (mapcar #'cdr templates)))
|
||||||
(cdar templates))))
|
(cdar templates))))
|
||||||
(when yas--current-template
|
(when yas--current-template
|
||||||
(yas-expand-snippet (yas--template-content yas--current-template)
|
(yas-expand-snippet (yas--template-content yas--current-template)
|
||||||
start
|
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."
|
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)))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user