I have the following snippet in .emacs file:
(defvar gid-command "gid" "The command run by the gid function.")
(defun gid-select (args)
"Run gid, with user-specified ARGS, and collect output in a buffer.
While gid runs asynchronously, you can use the \\[next-error] command to
find the text that gid hits refer to. The command actually run is
defined by the gid-command variable."
(interactive (list
(read-input (concat "Run " gid-command " (with args): ") ;confirmation
;(word-around-point)
))
)
;; Preserve the present compile-command
(let (compile-command
(gid-buffer ;; if gid for each symbol use: compilation-buffer-name-function
(lambda (mode) (concat "*gid " args "*"))))
;; For portability between v18 & v19, use compile rather than compile-internal
(compile (concat gid-command " " args))))
How is it possible to highlight the token I am looking for in the gid compilation window.
I tried applying Iqbal's solution to highlight regex in igrep window but couldn't find comparable grep-setup-hook in gid.
Here is my original answer modified to work for gid searches
;;;; Code for highlighting the matches
(defface my-gid-highlight `((t :background "blue" :foreground "white")) "Face to highlight grep matches with")
(defvar my-current-id-regexp nil)
(defun my-highlight-regexp ()
;; compilation-filter-start is bound to the start of inserted line
(goto-char compilation-filter-start)
;; Highlight from start of line to end, this assumes the lines
;; output by grep are of the format <filename>:<line_no>:matches
;; Thanks a lot Drew Adams for this awesome function, it allows
;; us to highlight just a group of given regexp
(hlt-highlight-regexp-to-end my-current-id-regexp 'my-gid-highlight nil nil 1))
(defun my-gid-highlight-setup (buffer)
;; Setup a hook so that we are called back every time a line
;; is inserted in *compilation* buffer
(add-hook 'compilation-filter-hook 'my-highlight-regexp t t))
;;;; Your original code with some modifications
(defvar gid-command "gid" "The command run by the gid function.")
(defun gid-select (args)
"Run gid, with user-specified ARGS, and collect output in a buffer.
While gid runs asynchronously, you can use the \\[next-error] command to
find the text that gid hits refer to. The command actually run is
defined by the gid-command variable."
(interactive (list (read-input (concat "Run " gid-command " (with args): "))))
;; Dynamically set the compilation-start-hook to setup gid highlighting
(let* ((compilation-start-hook '(my-gid-highlight-setup))
;; Assuming the token to be searched is at the end of
;; args
(search-token (car (last (split-string args)))))
;; Set the regexp used to highlight the token (use in "my-highlight-regexp")
(setq my-current-id-regexp (format ":[0-9]+:.*\\(%s\\)" search-token))
;; Start gid
(compilation-start (concat gid-command " " args))))
Related
It is quite common that when I use grep-find in emacs I want to search for the text I have selected. My current workaround to this is to select the text, then M-x grep-find and paste the selection. How do I make a keybinding that does this automatically?
Here's a modified grep-find - if the region is active, search of region
contents. It seems to work on my system:
(defun grep-find (command-args)
"Run grep via find, with user-specified args COMMAND-ARGS.
Collect output in a buffer.
While find runs asynchronously, you can use the \\[next-error] command
to find the text that grep hits refer to.
This command uses a special history list for its arguments, so you can
easily repeat a find command."
(interactive
(progn
(grep-compute-defaults)
(if grep-find-command
(list
(read-shell-command
"Run find (like this): "
(if (region-active-p)
(let ((str
(buffer-substring-no-properties
(region-beginning)
(region-end))))
(cons (replace-regexp-in-string
" {}"
(concat str " {}")
(car grep-find-command))
(+ (cdr grep-find-command)
(length str))))
grep-find-command) 'grep-find-history))
;; No default was set
(read-string
"compile.el: No `grep-find-command' command available. Press RET.")
(list nil))))
(when command-args
(let ((null-device nil))
(grep command-args))))
I have set this in my .emacs file:
(add-hook 'TeX-mode-hook
(lambda ()
(setq TeX-command-default "LaTeX"))
(add-hook 'LaTeX-mode-hook
(lambda ()
(setq TeX-command-default "LaTeX"))
I see that C-c C-c is bound to TeX-command-master, which calls TeX-command-query. But since my (TeX-master-file) is "<none>", I expect the default command to be called, but keeps wanting to invoke "View" instead of "LaTeX".
If you check the source for TeX-command-query you'll find that it checks the modification date of the tex (lines 4-9) and bbl (lines 10-19) files involved in your document. Unless those files are more recent than the output file and there is no known next command to be performed (lines 20-22) it will use the "View" command as default (line 23).
This behaviour is of course sensible because normally you don't want to recompile unless there are changes (modified tex files). Apart from "patching" the command [posted below, would not really recommend to use because it will not receive automatic updates ;-) ] there isn't really anything you can do.
If you decide to use the patched command, just put is somewhere in your init file after the original command has been loaded. You could for example wrap it into (replace ;; BODY by code)
(eval-after-load "tex-buf"
'(progn
;; BODY
))
Here comes the patched command:
(defun TeX-command-query (name)
"Query the user for what TeX command to use."
(let* ((default
(cond ((if (string-equal name TeX-region)
(TeX-check-files (concat name "." (TeX-output-extension))
(list name)
TeX-file-extensions)
(TeX-save-document (TeX-master-file)))
TeX-command-default)
((and (memq major-mode '(doctex-mode latex-mode))
;; Want to know if bib file is newer than .bbl
;; We don't care whether the bib files are open in emacs
(TeX-check-files (concat name ".bbl")
(mapcar 'car
(LaTeX-bibliography-list))
(append BibTeX-file-extensions
TeX-Biber-file-extensions)))
;; We should check for bst files here as well.
(if LaTeX-using-Biber TeX-command-Biber TeX-command-BibTeX))
((TeX-process-get-variable name
'TeX-command-next
;; HERE COMES THE PATCH
;; was TeX-command-View
TeX-command-default))
;; END OF PATCH
(TeX-command-Show)))
(completion-ignore-case t)
(answer (or TeX-command-force
(completing-read
(concat "Command: (default " default ") ")
(TeX-mode-specific-command-list major-mode) nil t
nil 'TeX-command-history))))
;; If the answer is "latex" it will not be expanded to "LaTeX"
(setq answer (car-safe (TeX-assoc answer TeX-command-list)))
(if (and answer
(not (string-equal answer "")))
answer
default)))
Where can I find the all Emacs' elisp scripts? I don't mean scripts users developed or installed themselves, but the common elisp script already there.
For example,
if I have a function like describe-char or insert-file, how can I find the file contained these functions?
Ctrl-h f will tell a function's explanation and where it is contained.
And if you want a function to do this automaticlly, here's a draft:
(defun my-find-lisp-object-file-name (function)
"Display the lisp file name of FUNCTION (a symbol)."
(interactive
(let ((fn (function-called-at-point))
(enable-recursive-minibuffers t)
val)
(setq val (completing-read (if fn
(format "Describe function (default %s): " fn)
"Describe function: ")
obarray 'fboundp t nil nil
(and fn (symbol-name fn))))
(list (if (equal val "")
fn (intern val)))))
(if (null function)
(message "You didn't specify a function")
(setq object-file-name (find-lisp-object-file-name function (symbol-function function)))
(if (eq object-file-name 'C-source)
(message "%s is in %s" function "C source code")
(setq buff (find-function-search-for-symbol function nil object-file-name))
(setq buf-name (buffer-name(car buff)))
(setq buf-pos (cdr buff))
(switch-to-buffer (car buff))
(message "%s is in %s(%s, %d)" function object-file-name buf-name buf-pos))))
I guess M-x locate-library RET <libname> RET could be an answer tho it needs the library name rather than the function name. Else, M-x find-function-other-window will not just tell you where the file is, but instead will open the file, after which you can use M-x pwd to know where you are.
One more thing: you can do C-h v load-path RET to see the directories that Emacs uses to find its libraries, so that should give you a good idea of where all the bundled Elisp files reside.
INITIAL DRAFT (March 25, 2014): First rough draft.
EDIT (March 26, 2014): Added a global-set-key. Added one more car to the final message in order to fully extract the path of the file name from the list of button text properties. Added some colorization to the initial and final messages. Added return cursor to beginning of buffer at the end of the function. Added options for find-variable-other-window and find-function-other-window. Added conditions so that no messages are generated if there is no file name.
Here is a fun little function that I whipped up -- it displays a message with a file path if an *.el file is displayed in the *Help* buffer.
(global-set-key (kbd "C-h z") 'lawlist-describe-find-function-variable)
(defun lawlist-describe-find-function-variable ()
"Describe or find a function / variable. Displays the path of filename."
(interactive)
(message (concat
(propertize "Describe" 'face 'font-lock-keyword-face)
" ["
(propertize "f" 'face 'font-lock-warning-face)
"]unction / ["
(propertize "v" 'face 'font-lock-warning-face)
"]ariable | "
(propertize "Find" 'face 'font-lock-keyword-face)
" ["
(propertize "F" 'face 'font-lock-warning-face)
"]unction / ["
(propertize "V" 'face 'font-lock-warning-face)
"]ariable"))
(let* (
(select-f-or-v (read-char-exclusive))
function
variable)
(cond
((eq select-f-or-v ?f)
(setq function (read (read-string "Please enter a function name: ")))
(describe-function function)
(select-window (get-buffer-window "*Help*")))
((eq select-f-or-v ?v)
(setq variable (read (read-string "Please enter a variable name: ")))
(describe-variable variable)
(select-window (get-buffer-window "*Help*")))
((eq select-f-or-v ?F)
(setq function (read (read-string "Please enter a function name: ")))
(find-function-other-window function)
(when buffer-file-name
(message (propertize buffer-file-name 'face 'font-lock-warning-face))))
((eq select-f-or-v ?V)
(setq variable (read (read-string "Please enter a variable name: ")))
(find-variable-other-window variable)
(when buffer-file-name
(message (propertize buffer-file-name 'face 'font-lock-warning-face))))
(t
(message "Thanks and come again!")))
(when (and
(equal (buffer-name) "*Help*")
(save-excursion
(goto-char (point-max))
(re-search-backward "\\(`*[.]el'\\)" nil t)))
(goto-char (point-max))
(re-search-backward "\\(`*[.]el'\\)" nil t)
(message
(propertize
(car (cdr (car (nthcdr 1 (text-properties-at (point))))))
'face 'font-lock-warning-face) )
(goto-char (point-min))) ))
If you use lispy minor mode:
You can open the definition of current function by positioning the point
on the open paren of that function and pressing F.
You can open the definition of current variable by marking it and
pressing F.
You can find all definitions in current directory with g.
You get a helm completion interface for all tags in all Elisp files.
Each line will have the tag in the first column and the file in the second.
My installation's base Elisp directory has 19838 tags, and the completion is fast enough.
You can find all definitions in current directory and its sub-directories
with lispy-goto-recursive. It takes minutes to parse and seconds to bring
up the completion interface. But it allows to interactively search through
all the files in the Emacs source - that's 89675 tags.
A sample search: there are 55 top-level tags that contain insert-file spread
around about 20 files.
Most of them are functions, but the top-level tag (define-key ctl-x-map "i" 'insert-file)
is also matched and can be viewed without opening the file.
You can grab the source of Emacs (if you installed Emacs you probably have .elc files - which are compiled elisp files), and search for the function, if you're on Unix like system you can use ack or find/grep all lisp files are in lisp directory
cd Emacs-24.4/lisp
ack 'defun some-function'
find . -name '*.el' | xargs grep 'defun some-function'
I'm remodeling my toolchain away from R + TeXShop to what I hope is a more efficient Sweave -> LaTeX -> SyncteX -> pdfview (skim) through emacs (Aquamacs, to be specific) AUCTeX-mode (with emacs-speaks-statsitics' sweave minor-mode). Everything works great with SyncteX from the AUCTeX -> pdfview chain, and everything works fine compiling from Sweave to .pdf.
The trouble comes in when I add Sweave as the first step. The .Rnw file now becomes the principal original document, and the .tex file it generates is just an intermediate step. Of course, it's the .tex file that SyncteX locks to.
The only changes I've made to my .emacs file are to register two new commands to build the .pdf from the .Rnw.
Can anyone offer advice on how to get emacs to use SyncteX to sync the output .pdf to the .Rnw, instead of the .tex?
Thanks!
Edit 1: Warning: This ended up being a summary of my fumbling around all afternoon. I get very close to the solution but foiled by an error at the very end that I cannot find documentation for. Warning 2: Today was the first time I've ever looked anywhere near this deep into emacs' inner workings. There's bound to be errors or inefficiencies.
VitoshKa's answer got me most of the way there. Adding his recommendation to my .emacs (well, Preferences.el, but functionally the same) file caused an Symbol’s value as variable is void: noweb-minor-mode-map error on launch because Aquamacs seems to load the .emacs file before the rest of its init files.
I fixed this by adding (require 'ess-site) (require 'ess-eldoc) immediately before VitoshKa's (define-key noweb-minor-mode-map (kbd "\C-c \C-c") 'Rnw-command-master). Unfortunately, Aquamacs ships with the ess-swv.elc file already in binary and forces the M-n P reader to be acroread. So I added the following edits of a portion of the ess-swv.el file to the bottom of my own .emacs:
(defun ess-makePDFandView ()
(interactive)
(setq namestem (substring (buffer-name) 0 (search ".Rnw" (buffer-name))))
(setq tex-filename (concat "\"" namestem "\".tex"))
(setq my-command-string (concat "pdflatex -synctex=1" tex-filename))
(shell-command my-command-string)
(setq my-command-string (concat "/Applications/Skim.app/Contents/MacOS/Skim \"" namestem ".pdf\" &"))
(shell-command my-command-string))
(define-key noweb-minor-mode-map "\M-nv" 'ess-makePDFandView)
Now emacs will launch skim with the correct pdf name from emacs with either M-n v or C-c C-c View RET. There's still one more snag to get through...
Command-Shift-Click in emacs tries to sync to filename.Rnw.pdf (but discarding the error message at least still causes a correct sync in the pdfviewer).
Command-Shift-Click in the pdfviewer to search back to the source forces emacs to open the filename.tex file and syncs to that. Fortunately, Cameron Bracken has a fix for that. He just doesn't quite go all the way to emacs integration.
So I added this further hack of ess-swv.el to my .emacs:
(defun ess-swv-latex-rnw-sync ()
"Run LaTeX on the product of Sweave()ing the current file."
(interactive)
(save-excursion
(let* ((namestem (file-name-sans-extension (buffer-file-name)))
(latex-filename (concat namestem ".tex"))
(synctex-filename (concat namestem ".synctex.gz"))
(tex-buf (get-buffer-create " *ESS-tex-output*"))
(patchDVI-command-string (concat "Rscript -e \"library('patchDVI');patchSynctex('" synctex-filename "')\"")))
(message "synctex string: %s" patchDVI-command-string)
(message "Running LaTeX on '%s' ..." latex-filename)
(switch-to-buffer tex-buf)
(call-process "latex" nil tex-buf 1 "-synctex=1 " latex-filename)
(switch-to-buffer (buffer-name))
(display-buffer tex-buf)
(message "Finished running LaTeX" )
(message "Running patchDVI...")
(shell-command patchDVI-command-string))))
(define-key noweb-minor-mode-map "\M-nq" 'ess-swv-latex-rnw-sync)
With the thinking that it was the lack patching the DVI and syncing it in... but no! Same behaviour on Command-Shift-Click as above... Back to hacking up ess-swv. I removed the ess-makePDFandView function, and instead added the following to my .emacs:
(defun ess-swv-PDF-rnw-sync (&optional pdflatex-cmd)
"From LaTeX file, create a PDF (via 'texi2pdf' or 'pdflatex', ...), by
default using the first entry of `ess-swv-pdflatex-commands' and display it."
(interactive
(list
(let ((def (elt ess-swv-pdflatex-commands 0)))
(completing-read (format "pdf latex command (%s): " def)
ess-swv-pdflatex-commands ; <- collection to choose from
nil 'confirm ; or 'confirm-after-completion
nil nil def))))
(let* ((buf (buffer-name))
(namestem (file-name-sans-extension (buffer-file-name)))
(latex-filename (concat namestem ".tex"))
(tex-buf (get-buffer-create " *ESS-tex-output*"))
(pdfviewer (ess-get-pdf-viewer))
(pdf-status)
(cmdstr-win (format "start \"%s\" \"%s.pdf\""
pdfviewer namestem))
(cmdstr (format "\"%s\" \"%s.pdf\" &" pdfviewer namestem)))
;;(shell-command (concat "pdflatex " latex-filename))
(message "Running '%s' on '%s' ..." pdflatex-cmd latex-filename)
(switch-to-buffer tex-buf)
(setq pdf-status
(call-process pdflatex-cmd nil tex-buf 1 "-synctex=1 "
(if (string= "texi2" (substring pdflatex-cmd 0 5))
;; workaround (bug?): texi2pdf or texi2dvi *fail* to work with full path:
(file-name-nondirectory latex-filename)
latex-filename)))
(if (not (= 0 pdf-status))
(message "** OOPS: error in '%s' (%d)!" pdflatex-cmd pdf-status)
;; else: pdflatex probably ok
(shell-command
(concat (if (and ess-microsoft-p (w32-shell-dos-semantics))
cmdstr-win
cmdstr))))
(switch-to-buffer buf)
(display-buffer tex-buf)))
(define-key noweb-minor-mode-map "\M-nv" 'ess-swv-PDF-rnw-sync)
Getting closer and closer, but we still need to tell auctex what filenames to pass through to skim. So I bit the bullet and edited auctex-config.el. I commented out the existing aquamacs-call-viewer function definition and replaced it with my own:
(defun aquamacs-call-viewer (line source)
"Display current output file as PDF at LINE (as in file SOURCE).
Calls `aquamacs-tex-pdf-viewer' to display the PDF file using the
Skim AppleScript protocol."
(cond
((string= (file-name-extension (TeX-active-master)) "Rnw")
(let* ((full-file-name
(expand-file-name
;; as in TeX-view
;; C-c C-c view uses %o (from TeX-expand-list), which
;; is the same.
(concat (file-name-sans-extension (TeX-active-master)) "." (TeX-output-extension))
default-directory))
(full-source-name
(expand-file-name
(concat (file-name-sans-extension (source)) ".Rnw") ;; this is relative to the master
(file-name-directory (full-file-name)))))
(message "full pdf name: %s" full-file-name)
(message "full rnw sournce name: %s" full-source-name)
(do-applescript
(format
"
set theSink to POSIX file \"%s\"
set theSource to POSIX file \"%s\"
tell application \"%s\"
activate
open theSink
tell front document to go to TeX line %d from theSource%s
end tell
"
full-file-name full-source-name aquamacs-tex-pdf-viewer line
;; do not say "showing reading bar false" so users can override in future
(cond ((eq t aquamacs-skim-show-reading-bar)
" showing reading bar true")
((eq nil aquamacs-skim-show-reading-bar)
" showing reading bar false")
(t ""))))))
(t
(let* ((full-file-name
(expand-file-name
;; as in TeX-view
;; C-c C-c view uses %o (from TeX-expand-list), which
;; is the same.
(TeX-active-master (TeX-output-extension))
default-directory))
(full-source-name
(expand-file-name
source ;; this is relative to the master
(file-name-directory full-file-name))))
(message "IN OTHERWISE!! WAT: %s" (file-name-extension (TeX-active-master)))
(do-applescript
(format
"
set theSink to POSIX file \"%s\"
set theSource to POSIX file \"%s\"
tell application \"%s\"
activate
open theSink
tell front document to go to TeX line %d from theSource%s
end tell
"
full-file-name full-source-name aquamacs-tex-pdf-viewer line
;; do not say "showing reading bar false" so users can override in future
(cond ((eq t aquamacs-skim-show-reading-bar)
" showing reading bar true")
((eq nil aquamacs-skim-show-reading-bar)
" showing reading bar false")
(t ""))))))))
And one more final test (notice I changed the keybindings of the toolchain to: M-n s -> M-n q -> M-n v in that order for sweave -> latex -> view [note that for this last step you have to use pdflatex and not texi2pdf]), everything builds, no errors, launching viewer...
"Skim" "/Users/myname/text/testing/myfile.pdf": exited abnormally with code 127.
And now I'm completely lost again. Anyone sufficiently familiar with Skim?
Edit 2: Well, error 127 is simply file-not-found on the binary. Somewhere in there I must have clobbered the path. So I added (setenv "PATH" (concat (getenv "PATH") ":" "/Applications/Skim.app/Contents/MacOS")) near the top of my auctex-config.el. Now everything compiles and launches with no errors ... but Command-Shift-Click on emacs does not get Skim to respond (at least it gives no errors). Command-Shift-Click on Skim still forces emacs to open the .tex file.
I guess this has now become a very Aquamacs + Skim specific question, since most of the rest of the interaction is in applescript, unless I missed something obvious in the key lines of lisp pointed out above.
To clarify. You want C-c C-c from Rnw files to run AUCTeX commands on the output of Sweave (M-n s).
The problem is that Auctex doesn't know that it has to act on a different file. This is how to make it aware of that:
(defun Rnw-command-master (&optional override-confirm)
"Run command on the current document.
If a prefix argument OVERRIDE-CONFIRM is given, confirmation will
depend on it being positive instead of the entry in `TeX-command-list'."
(interactive "P")
(let ((TeX-transient-master (concat
(file-name-sans-extension (buffer-file-name))
".tex"))
(TeX-master nil))
(TeX-command (TeX-command-query (TeX-master-file)) 'TeX-master-file
override-confirm)))
(define-key noweb-minor-mode-map (kbd "\C-c \C-c") 'Rnw-command-master)
To make Auctex run sweave first it would require a bit of additional work. Noweb support is now actively rewritten in ESS and by next version you will have a completely new system with AucTeX integration and many other useful things activated by default.
I'm working on autocompletion implementation in emacs for haxe programming language.
I already figured out how to obtain list of autocompletions which I wants to present. The list is in format:
'((name1 type1 desc1)
(name2 type2 desc2) ...
I want to display to user list containing text in format "name1 type1" after cursor position (like in autocomplete-mode) and desc for currently selected item in minibuffer. User should be able to select completion or give up like in auto-complete mode.
When user select something, name1 should be inserted at cursor position.
What is the best/easiest way to do this? Is there some standard emacs way to do this, or I should code something on my own?
EDIT: I have functions to get the list of autocomplete candidates based on buffer. Now I'm struggling how to integrate that to autocomplete-mode. Since get-completes is heavy operation, I would like to trigger it only if cursor is on "." character.
Here's the code I have.
(defun get-completes-from-haxe (hxml-file file pos)
(let* ((completion-buffer (get-buffer-create "*haxe-completions*"))
(cmd (concat "cd " (file-name-directory hxml-file) "; haxe " hxml-file " --display " file "#" (number-to-string pos))))
(ignore-errors
(shell-command cmd completion-buffer)
(let ((clist (xml-parse-region 1 (buffer-size completion-buffer) completion-buffer))
(completes nil))
(dolist (s (cddar clist))
(when (listp s)
(let* ((item (cdr s))
(name (cdaar item))
(type (car (cddadr item)))
(desc (cdddr item)))
(setf completes (cons name completes)))))
completes))))
(defun file-find-upwards (buffer file-name)
;; Chase links in the source file and search in the dir where it points.
(setq dir-name (or (and (buffer-file-name buffer)
(file-name-directory (file-chase-links
(buffer-file-name buffer))))
default-directory))
;; Chase links before visiting the file. This makes it easier to
;; use a single file for several related directories.
(setq dir-name (file-chase-links dir-name))
(setq dir-name (expand-file-name dir-name))
;; Move up in the dir hierarchy till we find a change log file.
(let ((file1 (concat dir-name file-name))
parent-dir)
(while (and (not (file-exists-p file1))
(progn (setq parent-dir
(file-name-directory
(directory-file-name
(file-name-directory file1))))
;; Give up if we are already at the root dir.
(not (string= (file-name-directory file1)
parent-dir))))
;; Move up to the parent dir and try again.
(setq file1 (expand-file-name file-name parent-dir)))
;; If we found the file in a parent dir, use that. Otherwise,
;; return nil
(if (or (get-file-buffer file1) (file-exists-p file1))
file1
nil)))
(defun get-candidate-list (buffer pos)
(get-completes-from-haxe
(file-find-upwards buffer "compile.hxml")
(buffer-file-name buffer)
pos))
I'd suggest the excellent package AutoComplete: http://www.emacswiki.org/emacs/AutoComplete
You can define custom sources for autocomplete and it seems fairly straight forward.
Why keep reinventing wheels? company-mode has support for a few languages
The ido-completing-read from ido.el is another way to do it.
An useful feature of it is that you can use regular expressions to filter out the candidates, and you can toggle this feature on and off on the fly. See ido.el for more details.
ido package has convenient completion functionality called 'ido-completing-read'. For example, here's a simple tweak to make it show lists in a line-by-line basis:
(defun x-ido-completing-read
(prompt choices &optional predicate require-match initial-input hist def)
(let* ((indent (concat "\n" (make-string (length prompt) ? )))
(ido-decorations
`("" "" ,indent ,(concat indent "...")
"[" "]" " [No match]" " [Matched]" " [Not readable]" " [Too big]")))
(ido-completing-read prompt choices predicate require-match initial-input hist def)))
Inside the yasnippet code, available from google code, they use 'dropdown-list.el' by Jaeyoun Chung to display the possible snippets that could be used at point. This gives a popup (tooltip-like) menu at the cursor position you can select with the arrow keys and enter or you can select by number.
http://www.emacswiki.org/emacs/dropdown-list.el