gnu-emacs-sources
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: snippet.el -- TextMate-like templates


From: Nic Ferrier
Subject: Re: snippet.el -- TextMate-like templates
Date: Mon, 27 Jun 2005 00:09:46 +0100
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux)

Pete Kazmier <address@hidden> writes:

> This is my first piece of elisp so I would appreciate any comments
> and/or feedback.  Its supposed to provide a very simple and easy to
> use template system similar to that of TextMate (an editor for OSX).
> It is heavily documented (description, use, and implementation).



> ;; Fortunately, this is easy to fix.  According to the documentation
> ;; for `define-abbrev', if the hook function is a symbol whose
> ;; `no-self-insert' property is non-nil, then hook can control whether
> ;; or not the insertion of the character that triggered the abbrev
> ;; expansion is inserted.  `insert-snippet' returns non-nil and thus
> ;; the proper way of defining the abbrev is as follows:
>
> ;;   (defun python-foo-expansion ()
> ;;     (snippet-insert "for $${element} in $${sequence}:"))
>
> ;;   (put 'python-foo-expansion 'no-self-insert t)
>
> ;;   (define-abbrev python-mode-abbrev-table    ; abbrev table
> ;;                  "for"                       ; name
> ;;                  ""                          ; expansion
> ;;                  'python-foo-expansion)      ; expansion hook
>
> ;; Unfortunately, this is a lot of work to define what should be a
> ;; simple abbrev.  For convenience, this package provides a macro
> ;; `snippet-abbrev' that can be used with much less effort:
>
> ;;   (snippet-abbrev python-mode-abbrev-table            ; table
> ;;                   "for"                               ; name
> ;;                   "for $${element} in $${sequence}:") ; template


This is not necessary. The more natural elisp would be this:

  (define-abbrev python-mode-abbrev-table
    "for"                  
    ""                     
    (let ((fn
           (lambda ()            
             (snippet-insert 
              "for $${element} in $${sequence}:"))))
      (put 'fn 'no-self-insert t)
      fn))

Which isn't *so* onerous.


Nic


reply via email to

[Prev in Thread] Current Thread [Next in Thread]