Skip to content

Instantly share code, notes, and snippets.

@katspaugh
Created March 7, 2014 18:07
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save katspaugh/9416653 to your computer and use it in GitHub Desktop.
Save katspaugh/9416653 to your computer and use it in GitHub Desktop.
Displaying code completions through a graphical menu. Requires Emacs 24.4 and ido-at-point
(require 'ido-at-point)
(defun ido-at-point-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 ido-at-point-read (completions common)
(ido-at-point-x-prompt "Completions" completions))
(ido-at-point-mode t)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment