emacs-orgmode
[Top][All Lists]
Advanced

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

Re: [Orgmode] Re: Using yasnippet with org Mode


From: Sebastian Rose
Subject: Re: [Orgmode] Re: Using yasnippet with org Mode
Date: Tue, 25 Nov 2008 00:51:35 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux)

Ian,


this is my yasnippets setup:


.emacs
=> --->8----------------------------->8----------------------------->8---

(require 'yasnippet) ;; not yasnippet-bundle
(yas/initialize)
(yas/load-directory "/home/sebastian/emacs/snippets/")

;; I use the WIN key for my own bindings, since I didn't use Windows for
;; ages, and I don't plan to :-)
;; H-y is convenient on german keyboard (like M-z on english/US
;; keyboard):

(defun sr-yas-in-org ()
  "Define H-y as yas/expand in org"
  (define-key org-mode-map [(hyper ?y)] 'yas/expand))

(add-hook 'org-mode-hook 'sr-yas-in-org)

<= ---8<-----------------------------8<-----------------------------8<---



Setup of the snippets tree beneath /home/sebastian/emacs/snippets/:

.
`-- fundamental-mode
    |-- cc-mode
    |   |-- c++-mode
    |   `-- c-mode
    |-- css-mode
    |-- html-mode
    |-- java-mode
    |-- message-mode
    |-- org-mode
    |-- perl-mode
    |   `-- cperl-mode
    |-- php-mode
    `-- picture-mode


As you can see, all modes inherit the snippets from fundamental
mode.




Example:

There's a `box' snippet in fundamental-mode which I may use in all
modes. It lives in a file named `box' in fundamental-mode and produces
an output like this:

      ,---------------.
      ! this is a box |
      `---------------´

Since I have _no_ file named `box' in `org-mode', expanding "box" in an
Org-file looks just the same:

      ,----------------------.
      ! This is a box in org |
      `----------------------´


For some modes, I overwrite it, simply by adding a file name `box' in
the appropriate subdirectory. This is the result of expanding
`php-mode/box' in a Php-file:

// ------------- //
// This is a box //
// ------------- //


... and in `picture-mode/box':

: +-----------------------+
: | A box in picture-mode |
: +-----------------------+


The former is what used, if I expand the `org-mode/ditaa' snippet in an
org-file, and press C-c '


#+begin_ditaa asdf.png -o
: +-----------------------+
: | A box in picture-mode |
: +-----------------------+
#+end_ditaa




In picture-mode, I have several boxes. I may choose one using the arrow
keys, if all their filenames start  with 'box':

picture-mode/box:
 +------------------------+
 | A box in pictqure-mode |
 +------------------------+

picture-mode/box.stippled-rounded:
 /---------\
 | Rounded |
 \---------/

picture-mode/box.stippled:
 +--------=-+
 | Stippled |
 +----------+

picture-mode/box.stippled-rounded:
 /--------------------=-\
 | Rounded and stippled |
 \----------------------/




box:

=> --->8----------------------------->8----------------------------->8---
#name : ! box |
# --
      ,${1:$(make-string (string-width text) ?\-)}--.
      ! ${1:SubTitle} |
      \`${1:$(make-string (string-width text) ?\-)}--´
$0
<= ---8<-----------------------------8<-----------------------------8<---



picture-mode/box (you have to draw the closing `|' yourself):

=> --->8----------------------------->8----------------------------->8---
#name : | straight |
# --
+${1:$(make-string (string-width text) ?\-)}--+
| ${1:Entity} |$0
+${1:$(make-string (string-width text) ?\-)}--+
<= ---8<-----------------------------8<-----------------------------8<---



picture-mode/box.rounded:

=> --->8----------------------------->8----------------------------->8---
#name : | rounded |
# --
/${1:$(make-string (string-width text) ?\-)}--\\
| ${1:Entity} |$0
\\${1:$(make-string (string-width text) ?\-)}--/
<= ---8<-----------------------------8<-----------------------------8<---





One of my most used ones is this here in `php-mode/debug':

=> --->8----------------------------->8----------------------------->8---
#contributor : Sebastian Rose <address@hidden>
#name : echo "<pre>"; print_r( ...
# --
echo "<pre><b>\\\$$1:</b><br />"; print_r(\$$1); echo "<br />".__FILE__.", line 
".__LINE__."</pre>";$0 exit;
<= ---8<-----------------------------8<-----------------------------8<---




You get the idea...


Regards, 


   Sebastian


Ian Barton <address@hidden> writes:
>> As for using yasnippets with tab, the following successfully binds tab
>> to yas/expand when I start emacs with
>>
>>   emacs -Q  (skips loading customization)
>>
>> and then evaluate the following elisp to load yasnippets and org-mode
>>
>> (load "~/emacs/elisp/util/yasnippet.el")
>> (yas/initialize)
>> (yas/load-directory "~/emacs/snippets")
>> (add-to-list 'load-path "~/emacs/org")
>> (require 'org)
>> (add-hook 'org-mode-hook
>>        (lambda ()
>>          ;; yasnippet
>>          (make-variable-buffer-local 'yas/trigger-key)
>>          (setq yas/trigger-key [tab])
>>          (define-key yas/keymap [tab] 'yas/next-field-group)))
>>
>> This works for me using a fairly recent Emacs 23 from cvs.
>>
>
> Thanks, I have tried that, but it didn't work for me:) I am using Emacs 22.2.1
> (i486-pc-linux-gnu, X toolkit, Xaw3d scroll bars)
>  of 2008-09-05 on vernadsky, modified by Ubuntu. I have also tried binding
> Yasnippet to the F1 key, which isn't used by anything else. Whilst this works 
> in
> text mode, it doesn't in org mode.
>
> I'll ask in the Yasnippet list and see if they can suggest anything.
>
> Ian.
>
>
> _______________________________________________
> Emacs-orgmode mailing list
> Remember: use `Reply All' to send replies to the list.
> address@hidden
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode
>

--
Sebastian Rose, EMMA STIL - mediendesign, Niemeyerstr.6, 30449 Hannover

Tel.:  +49 (0)511 - 36 58 472
Fax:   +49 (0)1805 - 233633 - 11044
mobil: +49 (0)173 - 83 93 417
Http:  www.emma-stil.de




reply via email to

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