1

Some programs take user inputs, for example by calling the interactive function `sunrise-sunset', two arguments are taken from the user. Assume that the inputs are 0.0098 and 51.4934 (these are longitude and latitude of Greenwich).

It would be interesting to call this function programmatically, but after evaluating the following

(call-interactively 'sunrise-sunset "0.0098" "51.4934")

one gets the error message Wrong type argument: vectorp.

How to correct this?

Drew
  • 75,699
  • 9
  • 109
  • 225
Name
  • 7,689
  • 4
  • 38
  • 84
  • 1
    `call-interactively` is for obtaining the argument values interactively, so passing it pre-determined argument values non-interactively makes no sense. `C-h f call-interactively` tells us that you're passing your strings as the RECORD-FLAG and KEYS arguments, the latter of which is expected to be a vector, hence that error. – phils Sep 03 '19 at 00:11

2 Answers2

3

The function sunrise-sunset is an interactive function takes a numeric prefix argument as a parameter. It does not take the latitude and longitude as parameters, which is what you're trying to pass into it. I suggest reading this emacs wiki article as well as of course the manual itself to learn more about prefix arguments. Also checking out the interactive codes might be helpful as well.

For getting the sunrise and sunset for a specific latitude and longitude I would suggest checking out the section in the manual on doing this. A quick read shows you need to specify the lat and long like this (as one example):

(setq calendar-latitude 40.1)
(setq calendar-longitude -88.2)
(setq calendar-location-name "Urbana, IL")

It seems like this sunrise-sunset is only meant to be called interactively. To get this information programatically as opposed to a displayed message I'd recommend looking at solar-sunrise-sunset which seems to return a list of times according to it's documentation:

"List of local times of sunrise, sunset, and daylight on Gregorian DATE. Corresponding value is nil if there is no sunrise/sunset."

The function is defined in /usr/share/emacs/26.2/lisp/calendar/solar.el.gz.

Aquaactress
  • 1,393
  • 8
  • 11
2

It looks like you can call it like this:

(let ((calendar-latitude 40.1)
      (calendar-longitude -88.2)
      (calendar-location-name "Urbana, IL"))
 (sunrise-sunset))

This does not prompt you for the latitude and longitude, and puts a message in the minibuffer for those variable values.

John Kitchin
  • 11,555
  • 1
  • 19
  • 41