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

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

Re: running function in hook dependent on value of a variable


From: Rainer M Krug
Subject: Re: running function in hook dependent on value of a variable
Date: Fri, 14 Jun 2013 09:39:21 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Kevin Rodgers <kevin.d.rodgers@gmail.com> writes:

> On 6/13/13 8:26 AM, Rainer M Krug wrote:
>> Hi
>>
>> I want to run a function in a hook only if the value of a variable is
>> non-nil. I have gotten that far with my less then rudimentary lisp knowledge:
>>
>> ,----
>> | (defvar org-babel-tangle-run-postTangleScript nil
>> |   "If non-nil, postTangleScript.sh will be executed")
>> | (put 'org-babel-tangle-run-postTangleScript 'safe-local-variable 'booleanp)
>> |
>> | (defun org-babel-run-post-tangle-script ()
>> |   (if org-babel-tangle-run-postTangleScript
>> |       (    (message "running the postTangleScript.sh bash shell script")
>> |    (shell-command "bash ./postTangleScript.sh"))))
>> |
>> | (add-hook 'org-babel-post-tangle-hook 'org-babel-run-post-tangle-script)
>> `----
>>
>> But something is wrong with the function, as it does not work.
>
> The THEN clause of the `if' special form is a single expression, but you have
> a list of expressions: ((message ...) (shell-command ...))

Ah - makes sens now.

>
>> Any suggestions?
>
> (defun org-babel-run-post-tangle-script ()
>   (if org-babel-tangle-run-postTangleScript
>       (progn
>       (message "running the postTangleScript.sh bash shell script")
>       (shell-command "bash ./postTangleScript.sh"))))
>
> Or for old-school Lisp minimalists:
>
> (defun org-babel-run-post-tangle-script ()
>   (and org-babel-tangle-run-postTangleScript
>        (messagea "running the postTangleScript.sh bash shell script")
>        (shell-command "bash ./postTangleScript.sh")))
>
> Or for CLtL style aficianados like myself:
>
> (defun org-babel-run-post-tangle-script ()
>   (when org-babel-tangle-run-postTangleScript
>     (message "running the postTangleScript.sh bash shell script")
>     (shell-command "bash ./postTangleScript.sh")))

Thanks - I finally understood something more about (e)lisp.

I agree - the last one looks the most intuitive to me.

Thanks,

Rainer


-- 
Rainer M. Krug

email: RMKrug<at>gmail<dot>com

Attachment: pgpM2wmBCNh4a.pgp
Description: PGP signature


reply via email to

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