* YAsnippet Emacs-Lisp Templates
@ 2008-09-25 7:14 Nordlöw
2008-09-25 8:26 ` Andy Stewart
0 siblings, 1 reply; 5+ messages in thread
From: Nordlöw @ 2008-09-25 7:14 UTC (permalink / raw)
To: help-gnu-emacs
Has anyone written any YAsnippet templates for emacs-lisp?
/Nordlöw
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: YAsnippet Emacs-Lisp Templates
2008-09-25 7:14 YAsnippet Emacs-Lisp Templates Nordlöw
@ 2008-09-25 8:26 ` Andy Stewart
2008-09-25 9:39 ` Nordlöw
0 siblings, 1 reply; 5+ messages in thread
From: Andy Stewart @ 2008-09-25 8:26 UTC (permalink / raw)
To: help-gnu-emacs
>>>>> "Nordlöw" == Nordlöw <per.nordlow@gmail.com> writes:
Hi, Nordlöw!
Nordlöw> Has anyone written any YAsnippet templates for emacs-lisp?
Nordlöw> /Nordlöw
This my YASnippet templates for emacs-lisp.
------------------------------> addal start <------------------------------
#name : (autoload '... "..." "..." ...)
# --
(autoload '${1:function-name} "${2:file-name}" "${3:document}" ${0:interactive})
------------------------------> addal end <------------------------------
------------------------------> addav start <------------------------------
#name : (defadvice ... ... ...)
# --
(defadvice ${1:function-name} (${2:args})
"${3:advice-document}"
(${0:advice-body})
)
------------------------------> addav end <------------------------------
------------------------------> addbk start <------------------------------
#name : (basic-set-key-alist ...)
# --
(basic-set-key-alist ${0:rest})
------------------------------> addbk end <------------------------------
------------------------------> addgk start <------------------------------
#name : (global-set-key (kbd "...") ...)
# --
(global-set-key (kbd "${1:some-key}") ${0:some-command})
------------------------------> addgk end <------------------------------
------------------------------> addhk start <------------------------------
#name : (dolist (hook (list ... )) (add-hook hook '...))
# --
(dolist (hook (list
${1:mode-list}
))
(add-hook hook '${0:mode-hook}))
------------------------------> addhk end <------------------------------
------------------------------> addhkd start <------------------------------
#name : (dolist (hooked (list ...)) (add-hook '... 'hooked))
# --
(dolist (hooked (list
${1:mode-list}
))
(add-hook '${0:mode-hook} 'hooked))
------------------------------> addhkd end <------------------------------
------------------------------> addlk start <------------------------------
#name : (define-key ... (kbd "...") ...)
# --
(define-key ${1:some-mode-map} (kbd "${2:some-key}") ${0:some-command})
------------------------------> addlk end <------------------------------
------------------------------> addpr start <------------------------------
#name : (provide '...)
# --
(provide '${0:library-name})
------------------------------> addpr end <------------------------------
------------------------------> addrq start <------------------------------
#name : (require '...)
# --
(require '${0:library-name})
------------------------------> addrq end <------------------------------
------------------------------> addse start <------------------------------
#name : (setq ... ...)
# --
(setq ${1:variable-name} ${0:variable-value})
------------------------------> addse end <------------------------------
------------------------------> deffu start <------------------------------
#name : (defun ... (...) "..." ...)
# --
(defun ${1:Function Name} ($2)
"${3:Function document}"
$0)
------------------------------> deffu end <------------------------------
------------------------------> defvr start <------------------------------
#name : (defvar ... ... "...")
# --
(defvar ${1:variable-name} ${2:variable-varlue} "${0:document}")
------------------------------> defvr end <------------------------------
------------------------------> evalal start <------------------------------
#name : (eval-after-load ... ...)
# --
(eval-after-load ${1:file-name}
${0:form})
------------------------------> evalal end <------------------------------
------------------------------> header start <------------------------------
#name : A elisp file header
# --
;;; ${1:filename}.el --- ${2:Simple description}
;; Author: ${3:Andy Stewart} ${4:<lazycat.manatee@gmail.com>}
;; Maintainer: ${5:Andy Stewart} ${6:<lazycat.manatee@gmail.com>}
;; Copyright (C) 2008, $3, all rights reserved.
;; Created: ${7:Created time}
;; Version: ${8:Current version}
;; Last-Updated: ${9:Update time}
;; URL: ${10:not distributed yet}
;; Keywords: ${11:keyword}
;; Compatibility: GNU Emacs ${12:Compatibility version}
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
;; Floor, Boston, MA 02110-1301, USA.
;; Features that might be requried by this library:
;;
;; ${13:None}
;;
;;; Installation:
;;
;; Copy $1.el to your load-path and add to your ~/.emacs
;;
;; (require '$1)
;;
;; ${14:No need more}
;;; Commentary:
;;
;; ${15:Comment}
;;
;;; Change log:
;;
;; ${16:Chang log}
;;
;;; Acknowledgements:
;;
;; $17
;;
;;; TODO
;;
;; $18
;;
;;; Require
$19
;;; Code:
$0
(provide '$1)
;;; $1.el ends here
------------------------------> header end <------------------------------
Enjoy!
Andy.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: YAsnippet Emacs-Lisp Templates
2008-09-25 8:26 ` Andy Stewart
@ 2008-09-25 9:39 ` Nordlöw
2008-09-25 10:53 ` Andy Stewart
2008-09-25 12:19 ` weber
0 siblings, 2 replies; 5+ messages in thread
From: Nordlöw @ 2008-09-25 9:39 UTC (permalink / raw)
To: help-gnu-emacs
On 25 Sep, 10:26, Andy Stewart <lazycat.mana...@gmail.com> wrote:
> >>>>> "Nordlöw" == Nordlöw <per.nord...@gmail.com> writes:
>
> Hi, Nordlöw!
>
> Nordlöw> Has anyone written any YAsnippet templates for emacs-lisp?
> Nordlöw> /Nordlöw
>
> This my YASnippet templates for emacs-lisp.
>
> ------------------------------> addal start <------------------------------
> #name : (autoload '... "..." "..." ...)
> # --
> (autoload '${1:function-name} "${2:file-name}" "${3:document}" ${0:interactive})
> ------------------------------> addal end <------------------------------
>
> ------------------------------> addav start <------------------------------
> #name : (defadvice ... ... ...)
> # --
> (defadvice ${1:function-name} (${2:args})
> "${3:advice-document}"
> (${0:advice-body})
> )
> ------------------------------> addav end <------------------------------
>
> ------------------------------> addbk start <------------------------------
> #name : (basic-set-key-alist ...)
> # --
> (basic-set-key-alist ${0:rest})
> ------------------------------> addbk end <------------------------------
>
> ------------------------------> addgk start <------------------------------
> #name : (global-set-key (kbd "...") ...)
> # --
> (global-set-key (kbd "${1:some-key}") ${0:some-command})
> ------------------------------> addgk end <------------------------------
>
> ------------------------------> addhk start <------------------------------
> #name : (dolist (hook (list ... )) (add-hook hook '...))
> # --
> (dolist (hook (list
> ${1:mode-list}
> ))
> (add-hook hook '${0:mode-hook}))
> ------------------------------> addhk end <------------------------------
>
> ------------------------------> addhkd start <------------------------------
> #name : (dolist (hooked (list ...)) (add-hook '... 'hooked))
> # --
> (dolist (hooked (list
> ${1:mode-list}
> ))
> (add-hook '${0:mode-hook} 'hooked))
> ------------------------------> addhkd end <------------------------------
>
> ------------------------------> addlk start <------------------------------
> #name : (define-key ... (kbd "...") ...)
> # --
> (define-key ${1:some-mode-map} (kbd "${2:some-key}") ${0:some-command})
> ------------------------------> addlk end <------------------------------
>
> ------------------------------> addpr start <------------------------------
> #name : (provide '...)
> # --
> (provide '${0:library-name})
> ------------------------------> addpr end <------------------------------
>
> ------------------------------> addrq start <------------------------------
> #name : (require '...)
> # --
> (require '${0:library-name})
> ------------------------------> addrq end <------------------------------
>
> ------------------------------> addse start <------------------------------
> #name : (setq ... ...)
> # --
> (setq ${1:variable-name} ${0:variable-value})
> ------------------------------> addse end <------------------------------
>
> ------------------------------> deffu start <------------------------------
> #name : (defun ... (...) "..." ...)
> # --
> (defun ${1:Function Name} ($2)
> "${3:Function document}"
> $0)
> ------------------------------> deffu end <------------------------------
>
> ------------------------------> defvr start <------------------------------
> #name : (defvar ... ... "...")
> # --
> (defvar ${1:variable-name} ${2:variable-varlue} "${0:document}")
> ------------------------------> defvr end <------------------------------
>
> ------------------------------> evalal start <------------------------------
> #name : (eval-after-load ... ...)
> # --
> (eval-after-load ${1:file-name}
> ${0:form})
> ------------------------------> evalal end <------------------------------
>
> ------------------------------> header start <------------------------------
> #name : A elisp file header
> # --
> ;;; ${1:filename}.el --- ${2:Simple description}
>
> ;; Author: ${3:Andy Stewart} ${4:<lazycat.mana...@gmail.com>}
> ;; Maintainer: ${5:Andy Stewart} ${6:<lazycat.mana...@gmail.com>}
> ;; Copyright (C) 2008, $3, all rights reserved.
> ;; Created: ${7:Created time}
> ;; Version: ${8:Current version}
> ;; Last-Updated: ${9:Update time}
> ;; URL: ${10:not distributed yet}
> ;; Keywords: ${11:keyword}
> ;; Compatibility: GNU Emacs ${12:Compatibility version}
>
> ;; This program is free software; you can redistribute it and/or modify
> ;; it under the terms of the GNU General Public License as published by
> ;; the Free Software Foundation; either version 2, or (at your option)
> ;; any later version.
>
> ;; This program is distributed in the hope that it will be useful,
> ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
> ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> ;; GNU General Public License for more details.
>
> ;; You should have received a copy of the GNU General Public License
> ;; along with this program; see the file COPYING. If not, write to
> ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
> ;; Floor, Boston, MA 02110-1301, USA.
>
> ;; Features that might be requried by this library:
> ;;
> ;; ${13:None}
> ;;
>
> ;;; Installation:
> ;;
> ;; Copy $1.el to your load-path and add to your ~/.emacs
> ;;
> ;; (require '$1)
> ;;
> ;; ${14:No need more}
>
> ;;; Commentary:
> ;;
> ;; ${15:Comment}
> ;;
>
> ;;; Change log:
> ;;
> ;; ${16:Chang log}
> ;;
>
> ;;; Acknowledgements:
> ;;
> ;; $17
> ;;
>
> ;;; TODO
> ;;
> ;; $18
> ;;
>
> ;;; Require
> $19
>
> ;;; Code:
>
> $0
>
> (provide '$1)
>
> ;;; $1.el ends here
> ------------------------------> header end <------------------------------
>
> Enjoy!
>
> Andy.
Great!
Is it possible to change the way these are are triggered (the keys I
believe YAsnippet calls them)?
I would like yasnippet to trigger on the real uses of them. For
example
"(defmacro " + TAB
expands defmacro-statement.
Thanks in advance,
Nordlöw
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: YAsnippet Emacs-Lisp Templates
2008-09-25 9:39 ` Nordlöw
@ 2008-09-25 10:53 ` Andy Stewart
2008-09-25 12:19 ` weber
1 sibling, 0 replies; 5+ messages in thread
From: Andy Stewart @ 2008-09-25 10:53 UTC (permalink / raw)
To: help-gnu-emacs
Nordlöw <per.nordlow@gmail.com> writes:
> On 25 Sep, 10:26, Andy Stewart <lazycat.mana...@gmail.com> wrote:
>> >>>>> "Nordlöw" == Nordlöw <per.nord...@gmail.com> writes:
> Great!
>
> Is it possible to change the way these are are triggered (the keys I
> believe YAsnippet calls them)?
>
> I would like yasnippet to trigger on the real uses of them. For
> example
>
> "(defmacro " + TAB
> expands defmacro-statement.
>
> Thanks in advance,
> Nordlöw
Hi, Nordlöw.
I think YAsnippet's mode is like this.
KEYWORD + TAB ==> Template completion
And I think YAsnippet can't understand below mode:
KEYWORD + SPACE + TAB
Because YAsnippet completion template just when cursor behind KEYWORD.
If you make cursor and KEYWORD have a SPACE, YAsnippet can't completion
template.
I have read your another post about YAsnippet with hippie-expand.
I recommend you split the key binding of those two command.
I binding TAB yas/expand, and binding M-/ hippie-expand.
So yas/expand don't conflict with hippie/expand.
BTW, hippie/expand is powerful, but not intuitionistic.
I use Company-mode to completion. It's a interactive completion style.
You can find it at:
http://nschum.de/src/emacs/company-mode/
Regards.
Andy.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: YAsnippet Emacs-Lisp Templates
2008-09-25 9:39 ` Nordlöw
2008-09-25 10:53 ` Andy Stewart
@ 2008-09-25 12:19 ` weber
1 sibling, 0 replies; 5+ messages in thread
From: weber @ 2008-09-25 12:19 UTC (permalink / raw)
To: help-gnu-emacs
On 25 set, 06:39, Nordlöw <per.nord...@gmail.com> wrote:
> On 25 Sep, 10:26, Andy Stewart <lazycat.mana...@gmail.com> wrote:
>
>
>
> > >>>>> "Nordlöw" == Nordlöw <per.nord...@gmail.com> writes:
>
> > Hi, Nordlöw!
>
> > Nordlöw> Has anyone written any YAsnippet templates for emacs-lisp?
> > Nordlöw> /Nordlöw
>
> > This my YASnippet templates for emacs-lisp.
>
> > ------------------------------> addal start <------------------------------
> > #name : (autoload '... "..." "..." ...)
> > # --
> > (autoload '${1:function-name} "${2:file-name}" "${3:document}" ${0:interactive})
> > ------------------------------> addal end <------------------------------
>
> > ------------------------------> addav start <------------------------------
> > #name : (defadvice ... ... ...)
> > # --
> > (defadvice ${1:function-name} (${2:args})
> > "${3:advice-document}"
> > (${0:advice-body})
> > )
> > ------------------------------> addav end <------------------------------
>
> > ------------------------------> addbk start <------------------------------
> > #name : (basic-set-key-alist ...)
> > # --
> > (basic-set-key-alist ${0:rest})
> > ------------------------------> addbk end <------------------------------
>
> > ------------------------------> addgk start <------------------------------
> > #name : (global-set-key (kbd "...") ...)
> > # --
> > (global-set-key (kbd "${1:some-key}") ${0:some-command})
> > ------------------------------> addgk end <------------------------------
>
> > ------------------------------> addhk start <------------------------------
> > #name : (dolist (hook (list ... )) (add-hook hook '...))
> > # --
> > (dolist (hook (list
> > ${1:mode-list}
> > ))
> > (add-hook hook '${0:mode-hook}))
> > ------------------------------> addhk end <------------------------------
>
> > ------------------------------> addhkd start <------------------------------
> > #name : (dolist (hooked (list ...)) (add-hook '... 'hooked))
> > # --
> > (dolist (hooked (list
> > ${1:mode-list}
> > ))
> > (add-hook '${0:mode-hook} 'hooked))
> > ------------------------------> addhkd end <------------------------------
>
> > ------------------------------> addlk start <------------------------------
> > #name : (define-key ... (kbd "...") ...)
> > # --
> > (define-key ${1:some-mode-map} (kbd "${2:some-key}") ${0:some-command})
> > ------------------------------> addlk end <------------------------------
>
> > ------------------------------> addpr start <------------------------------
> > #name : (provide '...)
> > # --
> > (provide '${0:library-name})
> > ------------------------------> addpr end <------------------------------
>
> > ------------------------------> addrq start <------------------------------
> > #name : (require '...)
> > # --
> > (require '${0:library-name})
> > ------------------------------> addrq end <------------------------------
>
> > ------------------------------> addse start <------------------------------
> > #name : (setq ... ...)
> > # --
> > (setq ${1:variable-name} ${0:variable-value})
> > ------------------------------> addse end <------------------------------
>
> > ------------------------------> deffu start <------------------------------
> > #name : (defun ... (...) "..." ...)
> > # --
> > (defun ${1:Function Name} ($2)
> > "${3:Function document}"
> > $0)
> > ------------------------------> deffu end <------------------------------
>
> > ------------------------------> defvr start <------------------------------
> > #name : (defvar ... ... "...")
> > # --
> > (defvar ${1:variable-name} ${2:variable-varlue} "${0:document}")
> > ------------------------------> defvr end <------------------------------
>
> > ------------------------------> evalal start <------------------------------
> > #name : (eval-after-load ... ...)
> > # --
> > (eval-after-load ${1:file-name}
> > ${0:form})
> > ------------------------------> evalal end <------------------------------
>
> > ------------------------------> header start <------------------------------
> > #name : A elisp file header
> > # --
> > ;;; ${1:filename}.el --- ${2:Simple description}
>
> > ;; Author: ${3:Andy Stewart} ${4:<lazycat.mana...@gmail.com>}
> > ;; Maintainer: ${5:Andy Stewart} ${6:<lazycat.mana...@gmail.com>}
> > ;; Copyright (C) 2008, $3, all rights reserved.
> > ;; Created: ${7:Created time}
> > ;; Version: ${8:Current version}
> > ;; Last-Updated: ${9:Update time}
> > ;; URL: ${10:not distributed yet}
> > ;; Keywords: ${11:keyword}
> > ;; Compatibility: GNU Emacs ${12:Compatibility version}
>
> > ;; This program is free software; you can redistribute it and/or modify
> > ;; it under the terms of the GNU General Public License as published by
> > ;; the Free Software Foundation; either version 2, or (at your option)
> > ;; any later version.
>
> > ;; This program is distributed in the hope that it will be useful,
> > ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
> > ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> > ;; GNU General Public License for more details.
>
> > ;; You should have received a copy of the GNU General Public License
> > ;; along with this program; see the file COPYING. If not, write to
> > ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
> > ;; Floor, Boston, MA 02110-1301, USA.
>
> > ;; Features that might be requried by this library:
> > ;;
> > ;; ${13:None}
> > ;;
>
> > ;;; Installation:
> > ;;
> > ;; Copy $1.el to your load-path and add to your ~/.emacs
> > ;;
> > ;; (require '$1)
> > ;;
> > ;; ${14:No need more}
>
> > ;;; Commentary:
> > ;;
> > ;; ${15:Comment}
> > ;;
>
> > ;;; Change log:
> > ;;
> > ;; ${16:Chang log}
> > ;;
>
> > ;;; Acknowledgements:
> > ;;
> > ;; $17
> > ;;
>
> > ;;; TODO
> > ;;
> > ;; $18
> > ;;
>
> > ;;; Require
> > $19
>
> > ;;; Code:
>
> > $0
>
> > (provide '$1)
>
> > ;;; $1.el ends here
> > ------------------------------> header end <------------------------------
>
> > Enjoy!
>
> > Andy.
>
> Great!
>
> Is it possible to change the way these are are triggered (the keys I
> believe YAsnippet calls them)?
>
> I would like yasnippet to trigger on the real uses of them. For
> example
>
> "(defmacro " + TAB
> expands defmacro-statement.
>
> Thanks in advance,
> Nordlöw
I did something like that, but after I just preferred using eldoc.
If you have any further questions please use the yasnippet group; the
package author is always helpful...
I'm pasting the code below...
HTH,
weber
;;; Hugo Schmitt (hugows@gmail.com) - Insert elisp function ARGS as a
;;; Yasnippet
;; 13-01-2008
;; Usage:
;; You've just entered a function name but forgot its arguments
(cursor is on ^):
;; (push ^)
;; then running lisp-snippet-insert will expand the snippet:
;; (push ${1:x} {2:place})
;; Note: I wasn't aware of Eldoc at the time, which ends up being
;; much easier to use than this.
(provide 'lisp-snippet-insert)
(require 'yasnippet)
(require 'cl)
(defun lisp-snippet-insert ()
"Insert args for 'current function' as a snippet."
(interactive)
(while (looking-back "\\s-") (backward-delete-char 1)) ; remove any
extra whitespace
(let* ((fun (function-called-at-point))
(args (unified-function-arglist fun)))
(insert " ")
(yas/expand-snippet (point) (point) (args-to-snippet args))))
(defun unified-function-arglist (fun)
"Return argument LIST for all kinds of functions (or so i hope)."
(let ((arglist (help-function-arglist fun)))
(if (or (stringp arglist) (listp arglist))
(split-string (substring (downcase (format "%S" (help-function-
arglist fun))) 1 -1))
(cdr (split-string (substring (downcase (car (help-split-fundoc
(documentation fun) "ignore"))) 1 -1))))))
(defun args-to-snippet (arglist)
"Convert string with space separated args to a snippet template.
Args like &optional will be removed."
(let* ((filterlist '("&optional" "&rest"))
(newlist (remove-if (lambda (x) (member x filterlist)) arglist))
(template (mapconcat (lambda (arg) (concat "${" arg "}")) newlist "
")))
template))
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2008-09-25 12:19 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-25 7:14 YAsnippet Emacs-Lisp Templates Nordlöw
2008-09-25 8:26 ` Andy Stewart
2008-09-25 9:39 ` Nordlöw
2008-09-25 10:53 ` Andy Stewart
2008-09-25 12:19 ` weber
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).