1

This is my function,

(define-key global-map
  (kbd "µ")
  (display-message-or-buffer (message "`%s'" (eval '(solar-sunrise-sunset-string (calendar-current-date))))))

But, when I call it, through the alt+m keystroke the command literally outputs text where my cursor is, with the output.

For example, under my cursor, the text appears as so, enter image description here

How can I direct this message to my Echo Area?

1

1 Answer 1

2

What you are doing is defining the key to the result of the evaluation of the expression (display-message-or-buffer (message "`%s'" (eval '(solar-sunrise-sunset-string (calendar-current-date))))). When I evaluate that expression in my *scratch* buffer, I get the string "‘Sunrise 7:04am (EST), sunset 4:10pm (EST) at 42.4N, 71.2W (9:06 hrs daylight)’". IOW, what you did is equivalent to this:

(define-key global-map (kbd "µ") "‘Sunrise 7:04am (EST), sunset 4:10pm (EST) at 42.4N, 71.2W (9:06 hrs daylight)’")

Of course, geographical differences will give you a different string, but that is irrelevant to the main point.

If you want to define the key to run a command, you first define the function that you want to run and then you give the function to define-key - like this:

(defun my/func ()
  (interactive)
  (display-message-or-buffer (message "`%s'" (eval '(solar-sunrise-sunset-string (calendar-current-date)))))

(define-key global-map (kbd "µ") #'my/func)

BTW, you don't need the eval: (display-message-or-buffer (message "`%s'" (solar-sunrise-sunset-string (calendar-current-date)))) will work just as well (or better: explicit use of eval is generally frowned upon - see the first paragraph of the eval section of the Emacs Lisp manual, which you can get to with C-h v i g(elisp)eval).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.