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: Kevin Rodgers
Subject: Re: running function in hook dependent on value of a variable
Date: Thu, 13 Jun 2013 23:11:01 -0600
User-agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.4; en-US; rv:1.9.2.28) Gecko/20120306 Thunderbird/3.1.20

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 ...))

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")))

--
Kevin Rodgers
Denver, Colorado, USA




reply via email to

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