Yasnippet is an extremely good system of 'boiler-plate' text for emacs which can be called on for inserting text at the cursor. So far, this post has used two snippets, 'New Post' and 'Lorem Ipsum'. 'Lorem ipsum' is simply dummy text of the printing and typesetting industry. It has been the industry's standard dummy text ever since the 1500s, and is being used here to demonstrate the use of snippets.

"Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius. Claritas est etiam processus

dynamicus, qui sequitur mutationem consuetudium lectorum. Mirum est notare quam littera gothica, quam nunc putamus parum claram, anteposuerit litterarum formas humanitatis per seacula quarta decima et quinta decima. Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum."

NewPost

The first snippet called is 'NewPost' which has this format -

# contributor: boudiccas
# name: New Post
# key
# --
#+DATE: [2014-03-15 Sat 11:41]
#+OPTIONS: toc:nil num:nil todo:nil pri:nil categories:nil ^:nil TeX:nil
#+TAGS: org2blog, emacs,
#+TITLE: Uncategorized, Hello

It is saved in -

~/.emacs.d/snippets/org-mode/New Post

and is called from the 'YASnippet' drop-down menu, and goes like this -

YASnippet -> org-mode -> New Post

Once you have installed 'YASnippet' from ELPA you put this code into your .emacs -

(require 'yasnippet)
 (yas-global-mode 1)
;; default TAB key is occupied by auto-complete
(global-set-key (kbd "C-c ; u") 'yas/expand)
;; default hotkey `C-c & C-s` is still valid
(global-set-key (kbd "C-c ; s") 'yas/insert-snippet)
;; give yas/dropdown-prompt in yas/prompt-functions a chance
(require 'dropdown-list)
;; use yas/completing-prompt when ONLY when `M-x yas/insert-snippet'
;; thanks to capitaomorte for providing the trick.
(defadvice yas/insert-snippet (around use-completing-prompt activate)
     "Use `yas/completing-prompt' for `yas/prompt-functions' but only here..."
       (let ((yas-prompt-functions '(yas/completing-prompt)))
             ad-do-it))

but I have found that when this text is put in your .emacs, highlighted and then using the menus -

Emacs-Lisp -> Evaluate region

this immediately makes it available and saves you either restarting emacs, or from 'evaluating the buffer'. It is more immediate, and puts the 'YASnippet' menu item in the menu-bar. From there you can just look down its available items, and seeing the very important item of 'Reload everything', which as it says restarts everything, including your snippets.

lorem ipsum

The 'lorem ipsum' snippet has this format -

# contributor: boudiccas
# name: Lorem ipsum
# key
# --
"Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore
magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis
nisl ut aliquip ex ea commodo consequat.

Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat
nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue
duis dolore te feugait nulla facilisi.

Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim
assum. Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem. Investigationes
demonstraverunt lectores legere me lius quod ii legunt saepius. Claritas est etiam processus dynamicus, qui sequitur
mutationem consuetudium lectorum.

Mirum est notare quam littera gothica, quam nunc putamus parum claram, anteposuerit litterarum formas humanitatis
per seacula quarta decima et quinta decima. Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in
futurum."

and is saved in the org-mode directory of snippets. It is installed and started exactly the same as the 'New Post' snippet.



Comments

comments powered by Disqus