all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* wrong number of arguments when launched interactively...
@ 2018-11-25 13:35 Jean-Christophe Helary
  2018-11-25 14:06 ` Stephen Berman
  0 siblings, 1 reply; 3+ messages in thread
From: Jean-Christophe Helary @ 2018-11-25 13:35 UTC (permalink / raw)
  To: help-gnu-emacs

(beginner warning)

I'm trying to automate the creation of html templates to avoid link mistakes and I wrote this code today:

(defun dailyIndex (myDate)
  (interactive (list
                (read-number "Date: " (string-to-number (format-time-string "%d")))))
  (setq baseCSSLink (format "../../../css/%s/baseCSS.css" (format-time-string "%Y")))
  (setq dailyCSSLink (format "../../../css/%s/DailyCSS%s%s.css" (format-time-string "%Y") (format-time-string "%m") myDate))
  (setq previousDay (- myDate 1))
  (setq previousDate (format "%s%s" (format-time-string "%m") previousDay))
  (setq previousDayLink (format "../../%s/%s/index.html" (format-time-string "%m") previousDay))
  (setq nextDay (+ myDate 1))
  (setq nextDate (format "%s%s" (format-time-string "%m") nextDay))
  (setq nextDayLink (format "../../%s/%s/index.html" (format-time-string "%m") nextDay))
  (setq todayDate (format "%s/%s/%s" (format-time-string "%Y") (format-time-string "%m") myDate))
  (setq todayTemplate
	(format "<html>
    <head>
	<title>%s</title>
	<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\" class=\"baseCSS\"/>
        <link rel=\"stylesheet\" type=\"text/css\" href=\"%s\" class=\"dailyCSS\"/>
    </head>
    <body>
	We're not there yet...
	<p class=\"navigation\">
	    <a href=\"%s\" hreflang=\"en\" rel=\"prev\">%s</a>
	    <a href=\"../../../index.html\" hreflang=\"en\">index</a>
	    <a href=\"%s\" hreflang=\"en\" rel=\"next\">%s</a>
	</p> 
	<p>%s, %s </p>
	<p>
	<h1>%s</h1>
	<h2>%s</h2>	

	<p class=\"navigation\">
	    <a href=\"%s\" hreflang=\"en\" rel=\"prev\">%s</a>
	    <a href=\"../../../index.html\" hreflang=\"en\">index</a>
	    <a href=\"%s\" hreflang=\"en\" rel=\"next\">&s</a>
	</p>
    </body>
</html>"
		"titre" baseCSSLink dailyCSSLink previousDayLink previousDate nextDayLink nextDate todayDate "..." "titre" "sous-titre" previousDayLink previousDate nextDayLink nextDate todayDate))

(write-region (dailyIndex) nil "~/Desktop/index.html"))

When run interactively, I always get a "wrong number of arguments" error. When I evaluate the internal expressions one by one, I never get this. I have no idea what is going on...


Jean-Christophe Helary
-----------------------------------------------
http://mac4translators.blogspot.com @brandelune





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

* Re: wrong number of arguments when launched interactively...
  2018-11-25 13:35 wrong number of arguments when launched interactively Jean-Christophe Helary
@ 2018-11-25 14:06 ` Stephen Berman
  2018-11-25 14:36   ` Jean-Christophe Helary
  0 siblings, 1 reply; 3+ messages in thread
From: Stephen Berman @ 2018-11-25 14:06 UTC (permalink / raw)
  To: Jean-Christophe Helary; +Cc: help-gnu-emacs

On Sun, 25 Nov 2018 22:35:33 +0900 Jean-Christophe Helary <brandelune@gmail.com> wrote:

> (beginner warning)
>
> I'm trying to automate the creation of html templates to avoid link mistakes and I wrote this code today:
>
> (defun dailyIndex (myDate)
[...]
> (write-region (dailyIndex) nil "~/Desktop/index.html"))
>
> When run interactively, I always get a "wrong number of arguments"
> error. When I evaluate the internal expressions one by one, I never
> get this. I have no idea what is going on...

You've defined a function, dailyIndex, that takes one obligatory
argument, myDate, but the last line of the function definition calls the
function without argument, that's the error.  Did you mean to make that
line part of the function definition (and hence make it recursive)?

Steve Berman



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

* Re: wrong number of arguments when launched interactively...
  2018-11-25 14:06 ` Stephen Berman
@ 2018-11-25 14:36   ` Jean-Christophe Helary
  0 siblings, 0 replies; 3+ messages in thread
From: Jean-Christophe Helary @ 2018-11-25 14:36 UTC (permalink / raw)
  To: help-gnu-emacs



> On Nov 25, 2018, at 23:06, Stephen Berman <stephen.berman@gmx.net> wrote:
> 
> You've defined a function, dailyIndex, that takes one obligatory
> argument, myDate, but the last line of the function definition calls the
> function without argument, that's the error.  Did you mean to make that
> line part of the function definition (and hence make it recursive)?

Wow, thank you Stephen.

1) there is a problem with the parens, the defun stops at the last format
2) I was expecting (wrongly) that the (write-region (dailyIndex) nil "~/Desktop/index.html") expression would use the default value I had set. So instead I'm calling (write-region todayTemplate nil "~/Desktop/index.html") and that seems to work.

Thank you again. I spent a whole day putting all this together. That was quite an education. I'm glad there are sites like stackoverflow and the like because only with the elisp reference I was totally lost.

For ex, the description of (interactive) is absolutely not clear at all when you want a default value for code characters that do not include one, similarly, I was not at all considering (write-region) to get the result on a file...

But I'm glad I'm finishing the day with something that works.



Jean-Christophe Helary
-----------------------------------------------
http://mac4translators.blogspot.com @brandelune




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

end of thread, other threads:[~2018-11-25 14:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-11-25 13:35 wrong number of arguments when launched interactively Jean-Christophe Helary
2018-11-25 14:06 ` Stephen Berman
2018-11-25 14:36   ` Jean-Christophe Helary

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.