Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs complaining with invalid function?

Tags:

emacs

elisp

When I press C-c c with the following code on a buffer, Emacs complains with Invalid function: (select-current-line). Why?

(defun select-current-line ()
  "Select the current line"
  (interactive)
  (end-of-line) ; move to end of line
  (set-mark (line-beginning-position)))

(defun my-isend ()
  (interactive)

  (if (and transient-mark-mode mark-active)
      (isend-send)

    ((select-current-line)
     (isend-send)))
)

(global-set-key (kbd "C-c c") 'my-isend)

Not that it matters, but for those interested isend-send is defined here.

like image 732
Amelio Vazquez-Reina Avatar asked Apr 08 '13 13:04

Amelio Vazquez-Reina


1 Answers

You are missing a progn form to group statements together:

(defun my-isend ()
  (interactive)

  (if (and transient-mark-mode mark-active)
      (isend-send)

    (progn
      (select-current-line)
      (isend-send))))

Without the progn form, ((select-current-line) (isend-send)) is interpreted as the (select-current-line) function applied to the result of calling isend-send without arguments. But (select-current-line) is not a valid function name. In other LISPs, such a construct could be valid if the return value of select-current-line was itself a function, which would then be applied to (isend-send). But this is not the case of Emacs LISP and this would not do what you wanted to achieve anyway...

like image 181
François Févotte Avatar answered Nov 03 '22 01:11

François Févotte