(setq load-path (cons (expand-file-name "~/site-lisp") load-path)
;;start smart-snippet stuff
(require 'smart-snippet)
;;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
Saptarshi Guha | saptars...@gmail.com | http://www.stat.purdue.edu/~sguha
What does "it" mean in the sentence "What time is it?"?
Saptarshi Guha | saptars...@gmail.com | http://www.stat.purdue.edu/~sguha
This novel is not to be tossed lightly aside, but to be hurled with
great force.
-- Dorothy Parker
My knowledge of abbrev-mode (which, i think, smart-snippet uses) is
that abbreviations are replaced whenever a 'punctuation character' is
inserted, however maybe there is a workaround.
Over to others.
Regards
Saptarshi
(defun indent-or-expand ()
(interactive)
(if (and
(or (bobp) (= ?w (char-syntax (char-before))))
(or (eobp) (not (= ?w (char-syntax (char-after))))))
(expand-abbrev)
(indent-according-to-mode)))
(defun my-tab-fix ()
(local-set-key [tab] 'indent-or-expand))
(add-hook 'python-mode-hook 'my-tab-fix)
This maps tab to abbrev completion yet still allowing for tab
completion/line indent etc. Reading the web page, we understand the it
uses the regular function "indent-according-to-mode" if not at a word
boundary.
So now you can start the activation with Tab but can't move between
fields.
However, there is one problem, it overrides smart-snippets's field
movement i.e can't to move to next field using TAB.
A fix would be to check for the current keymap, if it is snippet-map
then call the indent-according-to-mode or the regular snippet function.
Can anyone suggest a way?
Thanks
Saptarshi
Saptarshi Guha | saptars...@gmail.com | http://www.stat.purdue.edu/~sguha
if it GLISTENS, gobble it!!
Now you can tab to initiate.
Regards
Saptarshi
Saptarshi Guha | saptars...@gmail.com | http://www.stat.purdue.edu/~sguha
I live the way I type; fast, with a lot of mistakes.
("for" "for $${element} in $${sequence}:\n$>$." (not in-comment?))
more investigation shows that generally you only like `for' to
expand when type at the beginning of line (or only after some spaces),
so generally you like:
("for" "for $${element} in $${sequence}:\n$>$." bol?)
Thus, when you type
for
and press space it will get expanded, but when you type
# this is a comment for my program
the `for' won't get expanded. So you never think about when to press
TAB to expand your snippet. Emacs handles it for you (of course, you
should write the condition for a snippet smartly). Another example
is the double-quote character `"' in c-mode:
("\"" "\"$.\"" '(not (c-in-literal)))
("\"" "\\\"$." '(eq (c-in-literal) 'string))
You see, in normal case, it gets expanded into a pair of double-quote
""
But if I'm currently already inside a string, it get escaped:
"|"
^--< here is cursor, and I type `"', it gets
"\""
2008/2/6, Saptarshi Guha <saptars...@gmail.com>:
(memq (and snippet (snippet-bound snippet))
(overlays-at (point)))
returns non-nil, then you can determine you're currently inside a snippet
and invoke snippet-next-field.