popup menu at a proper place

This commit is contained in:
Zhang Chiyuan 2008-03-06 16:10:08 +00:00
parent f1e3d81609
commit 3950440f12

View File

@ -560,18 +560,27 @@ an example:
(defun yas/fake-keymap-for-popup (templates) (defun yas/fake-keymap-for-popup (templates)
"Create a fake keymap for popup menu usage." "Create a fake keymap for popup menu usage."
(cons 'keymap (cons 'keymap
(cons "Select a template:"
(mapcar (lambda (pair) (mapcar (lambda (pair)
(let* ((template (cdr pair)) (let* ((template (cdr pair))
(name (yas/template-name template)) (name (yas/template-name template))
(content (yas/template-content template))) (content (yas/template-content template)))
(list content 'menu-item name t))) (list content 'menu-item name t)))
templates)))) templates)))
(defun yas/point-to-coord (&optional point)
"Get the xoffset/yoffset information of POINT.
If POINT is not given, default is to current point."
(let* ((pn (posn-at-point (or point (point))))
(x-y (posn-x-y pn))
(x (car x-y))
(y (cdr x-y))
(coord (list (list (+ x 80) (+ y 20)) (selected-window))))
coord))
(defun yas/popup-for-template (templates) (defun yas/popup-for-template (templates)
"Show a popup menu listing templates to let the user select one." "Show a popup menu listing templates to let the user select one."
(if window-system (if window-system
(car (x-popup-menu t (yas/fake-keymap-for-popup templates))) (car (x-popup-menu (yas/point-to-coord) (yas/fake-keymap-for-popup templates)))
;; no window system, simply select the first one ;; no window system, simply select the first one
(cdar templates))) (cdar templates)))