I was wondering if are existing tools or package to write C++ (or other langage) code from lisp.

For example, this afternoon I needed to create 4 basic classes:

    class D{
    class C{
    class B{
    class A{

Using lisp it would be fairly easy to create a function that takes as an argument the class name and generate the template code from one instance:

    class $TAG{

where $TAG is going to be replaced by the class name.

I am not really looking at the exact lisp code to produce this because I can code it myself but rather at a package about this philosophy and with extra stuff I haven't thought of.

1 Answer 1


It sounds like a job for YASnippet

The philosophy behind it is to shorten the amount of keystrokes to enter frequently used structures and to not repeat yourself while writing the boilerplate code.

YASnippet comes with a lot of useful snippets preloaded for many major modes. In case of C++ it means that you can type for example cls and Tab and it will expand to

class Name
  virtual ~Name();

The cursor will be positioned on Name and as you type your name it will replace all occurrences of Name to create a valid C++ class.

To initialize YASnippet I use the following code:

(use-package yasnippet
  :ensure    yasnippet
  :init      (setq yas-verbosity 1)
  :config    (progn
               (yas-global-mode 1)
               (let* ((yas-elpa-snippets-folder (car (file-expand-wildcards
                                                      (concat user-emacs-directory "elpa/yasnippet-*/snippets"))))
                      (yas-folder-candidates  `(,yas-elpa-snippets-folder
                                                ,(concat user-emacs-directory "snippets"))))

                 (cl-loop for p in yas-folder-candidates
                          unless (file-exists-p p)
                          do (cl-delete p yas-folder-candidates))

                 (setq yas-snippet-dirs yas-folder-candidates))
               (define-key yas-minor-mode-map (kbd "C-c <tab>") 'yas/insert-snippet))
  :diminish  yas-minor-mode)

I've adapted it from what I found on the internet, probably from emacs-rimero-setup. It uses the wonderful use-package to install and initialize YASnippet.

  • Great that's exactly what I was looking for!
    – wizmer
    Commented Apr 6, 2016 at 12:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.