This page will show you how to setup a C++ documentation lookup for a word under the cursor with Emacs. It relies on the package xah-lookup. Have a look at the Xah’s page for more general information.

Install xah-lookup via Melpa:

M-x package-install [RET] xah-lookup [RET]

Add this snippet in your Emacs’ init file:

;; Uncomment the below line to use eww (Emacs Web Wowser)
;; (setq xah-lookup-browser-function 'eww)

(defun xah-lookup-cppreference (&optional word)
  "Lookup definition of current word or text selection in URL."
  (interactive)
  (xah-lookup-word-on-internet
   word
   ;; Use word02051 as a placeholder in the query URL.
   "http://en.cppreference.com/mwiki/index.php?search=word02051"
   xah-lookup-browser-function))

(require 'cc-mode)

;; Add shortcut for c++-mode
(define-key c++-mode-map (kbd "C-c d") #'xah-lookup-cppreference)

;; Another example with http://www.boost.org
(defun xah-lookup-boost (&optional word)
  (interactive)
  (xah-lookup-word-on-internet
   word
   "https://cse.google.com/cse?cx=011577717147771266991:jigzgqluebe&q=word02051"
   xah-lookup-browser-function))
(define-key c++-mode-map (kbd "C-c b") #'xah-lookup-boost)

Happy browsing!

Further reading

  • Modern C++ Font Lock for GNU Emacs ⋅ Melpa - Git

  • STL algorithm mnemonics for GNU Emacs ⋅ YASnippet - Git

Note

If you have any questions or suggestions that you would share with me, write me an email. For typographical errors or dead links, send me a pull request.