[Top][All Lists]

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

Re: Is there a code better than the other?

From: Pascal J. Bourguignon
Subject: Re: Is there a code better than the other?
Date: Thu, 04 Jul 2013 20:48:19 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux)

"Sebastien Vauban" <> writes:

> Hello,
> When searching for info on the web, I found the following chunks of code to
> automatically reload snippets after saving.
> ;; 
>   (eval-after-load "yasnippet"
>     '(progn
>        (add-hook 'snippet-mode-hook
>                  (lambda ()
>                    (setq require-final-newline nil)
>                    (add-hook 'after-save-hook 'yas-recompile-all 'append 
> 'make-it-local)
>                    (add-hook 'after-save-hook 'yas-reload-all 'append 
> 'make-it-local)))))
> and
> ;; 
>   ;; automatically reload snippets after saving:
>   (defun reload-snippets ()
>     (interactive)
>     (yas-reload-all)
>     (yas-recompile-all)
>     (yas-reload-all)
>     (yas-recompile-all))
>   (defun snippet-mode-before-save ()
>     (interactive)
>     (when (eq major-mode 'snippet-mode) (reload-snippets)))
>   (add-hook 'after-save-hook 'snippet-mode-before-save)
> Except the small differences (2 x reload and 2 x recompile, or the "don't
> require final newline"), is there one better than the other?  There are
> differences on the "make it local" hook "after-save". Is there a writing that
> will be more portable (during time) than the other?

The later is better than the former, because it allow you to redefine
snippet-mode-before-save and have the new definition used in the hook
right away.  With the former,  you would have to search in the hook the
lambda, remove it, and add the new hook…

__Pascal Bourguignon__           
A bad day in () is better than a good day in {}.  
You know you've been lisping too long when you see a recent picture of George 
Lucas and think "Wait, I thought John McCarthy was dead!" -- Dalek_Baldwin

reply via email to

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