|
Tutorial
IntroductionA tutorial that takes a bare Emacs install and shows all the things that need to be done to get smart-snippet working with various major mode files. This tutorial is originally posted by Saptarshi Guha to smart-snippet discussion group. Details Some very basic instructions.
Suppose you keep downloaded .el files in ~/site-lisp
then your .emacs should look like
(setq load-path (cons (expand-file-name "~/site-lisp") load-path)
;;start smart-snippet stuff
(require 'smart-snippet)
(setq save-abbrevs nil)
;;Following only works during html helper mode
(require 'html-helper-mode)
(smart-snippet-with-abbrev-tables (html-helper-mode-abbrev-table)
("href" "<a href=\"$$\">$.</a>" t) ;;(A)
)
;;For python
(smart-snippet-with-abbrev-tables (python-mode-abbrev-table) (
"for" "for $${element} in $${sequence}:\n$>$." 'bol?) ;;(B)
)
generally, the lines look like
1. (smart-snippet-with-abbrev-tables (MODENAME-mode-abbrev-table)
2. The snippet and activation code look like
("ACTIVATION" "REPLACEMENT" CONDITION)
So in (A)
typing href starts the smart snippet and replaces it with <a href="$
$">$.</a>
a)The $$ wont be seen actually, it is a dummy for a variable, i.e you
it will be highlighted waiting for your input. Press TAB to move to
next parameter or out of the paramater
b)\" places " in the replacement text
c)The $. is the place to keep the cursor at the end
d)the 't' informs smart snippet to activate all the time as opposed
to bol (see (B))
In (B)
a)for triggers the smart snippet
b)$${element} is a named parameter, which you can use again in the
snippet replacement. So when the user changes the value the first time
it is reflected everywhere else the $${element} is used. Press TAB to
move to next parameter.
c)$> indents, which is required for python
d)'bol? evaluates to true only when you type for at the logical
beginning of the line, since e.g you don't want for to be expanded in
a comment
It is helpful reading the source.
Hope this helps.
Regards
Saptarshi I forgot to mention that you need to add the following
lines just after (require 'smart-snippet)
(dolist (hook '(python-mode-hook
;;html-helper-mode-hook
;;LaTeX-mode-hook
;;ruby-mode-hook
;;emacs-lisp-mode-hook
;;text-mode-hook
))
(add-hook hook (lambda () (abbrev-mode 1) )))
This turns on abbrev-mode (abbrev-mode 1) for the modes listed in the
dolist list.
I have commented out the lines you might not need (as of now).
|
► Sign in to add a comment