all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Is there a code better than the other?
@ 2013-07-04 15:07 Sebastien Vauban
  2013-07-04 18:48 ` Pascal J. Bourguignon
  0 siblings, 1 reply; 3+ messages in thread
From: Sebastien Vauban @ 2013-07-04 15:07 UTC (permalink / raw)
  To: help-gnu-emacs-mXXj517/zsQ

Hello,

When searching for info on the web, I found the following chunks of code to
automatically reload snippets after saving.

--8<---------------cut here---------------start------------->8---
;; https://github.com/vderyagin/dotemacs/blob/master/conf/yasnippet-configuration.el

  (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)))))
--8<---------------cut here---------------end--------------->8---

and

--8<---------------cut here---------------start------------->8---
;; https://earthserver.com/Setting_up_a_C%2B%2B11_development_environment_on_Linux_with_Clang_and_Emacs

  ;; 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)
--8<---------------cut here---------------end--------------->8---

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?

Best regards,
  Seb

-- 
Sebastien Vauban


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Is there a code better than the other?
  2013-07-04 15:07 Is there a code better than the other? Sebastien Vauban
@ 2013-07-04 18:48 ` Pascal J. Bourguignon
  2013-07-05  8:46   ` Sebastien Vauban
  0 siblings, 1 reply; 3+ messages in thread
From: Pascal J. Bourguignon @ 2013-07-04 18:48 UTC (permalink / raw)
  To: help-gnu-emacs

"Sebastien Vauban" <sva-news@mygooglest.com> writes:

> Hello,
>
> When searching for info on the web, I found the following chunks of code to
> automatically reload snippets after saving.
>
> ;; https://github.com/vderyagin/dotemacs/blob/master/conf/yasnippet-configuration.el
>
>   (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
>
> ;; https://earthserver.com/Setting_up_a_C%2B%2B11_development_environment_on_Linux_with_Clang_and_Emacs
>
>   ;; 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__                     http://www.informatimago.com/
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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Is there a code better than the other?
  2013-07-04 18:48 ` Pascal J. Bourguignon
@ 2013-07-05  8:46   ` Sebastien Vauban
  0 siblings, 0 replies; 3+ messages in thread
From: Sebastien Vauban @ 2013-07-05  8:46 UTC (permalink / raw)
  To: help-gnu-emacs-mXXj517/zsQ

Hello Pascal,

"Pascal J. Bourguignon" wrote:
> "Sebastien Vauban" <sva-news-D0wtAvR13HarG/iDocfnWg@public.gmane.org> writes:
>
>> ;; https://github.com/vderyagin/dotemacs/blob/master/conf/yasnippet-configuration.el
>>
>>   (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
>>
>> ;; https://earthserver.com/Setting_up_a_C%2B%2B11_development_environment_on_Linux_with_Clang_and_Emacs
>>
>>   ;; 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…

Good argument... Thanks for your answer!

Best regards,
  Seb

-- 
Sebastien Vauban


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-07-05  8:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-07-04 15:07 Is there a code better than the other? Sebastien Vauban
2013-07-04 18:48 ` Pascal J. Bourguignon
2013-07-05  8:46   ` Sebastien Vauban

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.