sorting fixed, sort of

This commit is contained in:
capitaomorte 2010-04-09 15:31:58 +00:00
parent f36ca47f69
commit f90394827f

View File

@ -1424,11 +1424,17 @@ Here's a list of currently recognized variables:
TEMPLATES is a list of `yas/template'." TEMPLATES is a list of `yas/template'."
(when templates (when templates
(some #'(lambda (fn) (setq templates
(funcall fn (or prompt "Choose a snippet: ") (sort templates #'(lambda (t1 t2)
templates (< (length (yas/template-name t1))
#'yas/template-name)) (length (yas/template-name t2))))))
yas/prompt-functions))) (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))))
(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."
@ -1456,28 +1462,28 @@ TEMPLATES is a list of `yas/template'."
;; ;;
(when (and window-system choices) (when (and window-system choices)
(let ((chosen (let ((chosen
(if (yas/template-p (first choices)) (let (menu d) ;; d for display
(yas/x-prompt-pretty-templates prompt choices) (dolist (c choices)
(let (menu d) ;; d for display (setq d (or (and display-fn (funcall display-fn c))
(dolist (c choices) c))
(setq d (or (and display-fn (funcall display-fn c)) (cond ((stringp d)
c)) (push (cons (concat " " d) c) menu))
(cond ((stringp d) ((listp d)
(push (cons (concat " " d) c) menu)) (push (car d) menu))))
((listp d) (setq menu (list prompt (push "title" menu)))
(push (car d) menu)))) (x-popup-menu (if (fboundp 'posn-at-point)
(setq menu (list prompt (push "title" menu))) (let ((x-y (posn-x-y (posn-at-point (point)))))
(x-popup-menu (if (fboundp 'posn-at-point) (list (list (+ (car x-y) 10)
(let ((x-y (posn-x-y (posn-at-point (point))))) (+ (cdr x-y) 20))
(list (list (+ (car x-y) 10) (selected-window)))
(+ (cdr x-y) 20)) t)
(selected-window))) menu))))
t)
menu)))))
(or chosen (or chosen
(keyboard-quit))))) (keyboard-quit)))))
(defun yas/x-prompt-pretty-templates (prompt templates) (defvar yas/x-pretty-prompt-templates nil
"If non-nil, attempt to prompt for templates like TextMate.")
(defun yas/x-pretty-prompt-templates (prompt templates)
"Display TEMPLATES, grouping neatly by table name." "Display TEMPLATES, grouping neatly by table name."
(let ((props (list)) (let ((props (list))
menu menu
@ -2032,8 +2038,9 @@ Skip any submenus named \"parent mode\""
uuidhash) uuidhash)
:table table :table table
:uuid (second e))))) :uuid (second e)))))
;; (if (string= (second e) "944F1410-188C-4D70-8340-CECAA56FC7F2")
;; (debug))
(define-key keymap (vector (gensym)) (define-key keymap (vector (gensym))
;; '(menu-item "shit" 'ding)
(car (yas/snippet-menu-binding-pair-get-create template :stay))))) (car (yas/snippet-menu-binding-pair-get-create template :stay)))))
;; ((eq (first e) 'yas/external-item) ;; ((eq (first e) 'yas/external-item)
;; (let ((template (some #'(lambda (table) ;; (let ((template (some #'(lambda (table)
@ -2050,7 +2057,7 @@ Skip any submenus named \"parent mode\""
;; (message "[yas] external menu item %s not found anywhere!" (second e))))) ;; (message "[yas] external menu item %s not found anywhere!" (second e)))))
((eq (first e) 'yas/submenu) ((eq (first e) 'yas/submenu)
(let ((subkeymap (make-sparse-keymap))) (let ((subkeymap (make-sparse-keymap)))
(define-key keymap (vector (make-symbol (second e))) (define-key keymap (vector (gensym))
`(menu-item ,(second e) ,subkeymap)) `(menu-item ,(second e) ,subkeymap))
(yas/define-menu-1 table subkeymap (third e) uuidhash))) (yas/define-menu-1 table subkeymap (third e) uuidhash)))
((eq (first e) 'yas/separator) ((eq (first e) 'yas/separator)