unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* running function in hook dependent on value of a variable
@ 2013-06-13 14:26 Rainer M Krug
  2013-06-14  5:11 ` Kevin Rodgers
  0 siblings, 1 reply; 5+ messages in thread
From: Rainer M Krug @ 2013-06-13 14:26 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 1234 bytes --]

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. 

Any suggestions?

The idea is to be able to enable and disable the execution of this
postTangleScript.sh file on a per-file-basis using file-local-variables.

Ultimately, I would like to be able to execute a script whose name is
stored in the variable org-babel-tangle-run-postTangleScript and not
hardcoded. 

Also, if the variable and the function should follow a certain naming
convention, please let me know.

Thanks,

Rainer

-- 
Rainer M. Krug

email: RMKrug<at>gmail<dot>com

[-- Attachment #2: Type: application/pgp-signature, Size: 489 bytes --]

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

* Re: running function in hook dependent on value of a variable
       [not found] <mailman.1558.1371133630.22516.help-gnu-emacs@gnu.org>
@ 2013-06-13 15:18 ` Barry Margolin
  2013-06-14  7:45   ` Rainer M Krug
  0 siblings, 1 reply; 5+ messages in thread
From: Barry Margolin @ 2013-06-13 15:18 UTC (permalink / raw)
  To: help-gnu-emacs

In article <mailman.1558.1371133630.22516.help-gnu-emacs@gnu.org>,
 Rainer M Krug <Rainer@krugs.de> 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. 
> 
> 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"))))

-- 
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***


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

* Re: running function in hook dependent on value of a variable
  2013-06-13 14:26 Rainer M Krug
@ 2013-06-14  5:11 ` Kevin Rodgers
  2013-06-14  7:39   ` Rainer M Krug
  0 siblings, 1 reply; 5+ messages in thread
From: Kevin Rodgers @ 2013-06-14  5:11 UTC (permalink / raw)
  To: help-gnu-emacs

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




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

* Re: running function in hook dependent on value of a variable
  2013-06-14  5:11 ` Kevin Rodgers
@ 2013-06-14  7:39   ` Rainer M Krug
  0 siblings, 0 replies; 5+ messages in thread
From: Rainer M Krug @ 2013-06-14  7:39 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 2044 bytes --]

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 #2: Type: application/pgp-signature, Size: 489 bytes --]

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

* Re: running function in hook dependent on value of a variable
  2013-06-13 15:18 ` running function in hook dependent on value of a variable Barry Margolin
@ 2013-06-14  7:45   ` Rainer M Krug
  0 siblings, 0 replies; 5+ messages in thread
From: Rainer M Krug @ 2013-06-14  7:45 UTC (permalink / raw)
  To: help-gnu-emacs

Barry Margolin <barmar@alum.mit.edu> writes:

> In article <mailman.1558.1371133630.22516.help-gnu-emacs@gnu.org>,
>  Rainer M Krug <Rainer@krugs.de> 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. 
>> 
>> 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"))))
<#secure method=pgpmime mode=sign>

Thanks,

Rainer

-- 
Rainer M. Krug

email: RMKrug<at>gmail<dot>com




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

end of thread, other threads:[~2013-06-14  7:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.1558.1371133630.22516.help-gnu-emacs@gnu.org>
2013-06-13 15:18 ` running function in hook dependent on value of a variable Barry Margolin
2013-06-14  7:45   ` Rainer M Krug
2013-06-13 14:26 Rainer M Krug
2013-06-14  5:11 ` Kevin Rodgers
2013-06-14  7:39   ` Rainer M Krug

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).