0

I want to trigger running makefile from inside emacs. I followed this link and added to

(defun set-exec-path-from-shell-PATH ()
(let ((path-from-shell (replace-regexp-in-string
                        "[ \t\n]*$"
                        ""
                        (shell-command-to-string "$SHELL --login -i -c 'echo $PATH'"))))
(setenv "PATH" path-from-shell)
(setq eshell-path-env path-from-shell) ; for eshell users
(setq exec-path (split-string path-from-shell path-separator))))

(when window-system (set-exec-path-from-shell-PATH))

to init.el to make emacs see my .bashrc settings. When I invoke shell-command by pressing M-! and type:

make something

I run makefile with success. But I want to run the same command by keyboard shortcut so I added:

(defun make-sth-in-shell ()
(interactive)
(shell-command ("make something"))  ; 
)

(add-hook 'some-hook
(lambda ()
(local-set-key (kbd "\C-c\C-p") 'make-sth-in-shell))
)

and now, when pressing C-c C-p I get

Invalid function: "make something"

What am I doing wrong?

3 Answers 3

2

Emacs already has support for make.

The command is compile This will prompt you for the command line with the default being make -k

Just bind compile to a key using local-set-key or define-key

1
  • Thanks. Actually, your answer does not solve the problem that was stated but it helped me anyway. The problem with newbies like me and such overwhelming software as Emacs are those endless moments of groping for an answer in hopeless frustration and discovering that solution was in a completely different place than you were looking for. How can I pass my own argument directly to compile function? Now, I'm using recompile to avoid having to confirm make something each time I trigger my keyboard shortcut, but still I have to use compile at the beginning of the session.
    – equator
    May 23 at 13:16
2

To answer the original question: there are extraneous parens in your function. It should read:

(defun make-sth-in-shell ()
  (interactive)
  (shell-command "make something"))

Explanation: shell-command takes a string as argument. Wrapping that string in parens causes emacs to try and execute it, attempting to find a function called "make something".

That said, the accepted answer is totally the way to go: you can change the default that M-x compile offers by setting the compile-command variable:

(setq compile-command "make something")
1

One thing that you are doing wrong is this line in your make-sth-in-shell function:

...
(shell-command ("make something"))
...

In Lisp, when the interpreter see a list (f a b c), it interprets it as a function call: call the function f with arguments a, b and c. In your case, ("make something") is a function call with no arguments. Now "make something" is a string, not a function, hence the Invalid function error message.

What you should be doing is:

...
(shell-command "make something")
...

That calls the function shell-command with argument "make something".

Whether that does what you want, I don't know: I'm just identifying the error here. And as the other answer says, it's better to use M-x compile and adjust the command.

1
  • Ha! Fran Burstall beat me to the punch :-)
    – NickD
    May 23 at 17:13

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.