31

Before now I've just been cutting and pasting code into my .emacs file, but then I decided to add some maven functionality to emacs. Now, I don't see how I was able to mess this up, but last night I kept getting the error I put in the title when I run M-x jarl-mvn-exec. I slept on it, and came back the next day but I'm still not getting anywhere.

(defun jarl-get-pom ()
  (concat (locate-dominating-file 
       (buffer-file-name 
        (current-buffer))
       "pom.xml")
      "pom.xml"))

(defun jarl-visit-pom ()
  (interactive)
  (find-file (jarl-get-pom)))

(defun jarl-mvn-exec ()
  (interactive)
  (switch-to-buffer (get-buffer-create "maven"))
  (start-process-shell-command "mvn-exec" "maven" "mvn" "-f" (jarl-get-pom) "compile")
  (start-process-shell-command "mvn-exec" "maven" "mvn" "-f" (jarl-get-pom) "exec:exec"))
HahaHortness
  • 1,570
  • 1
  • 15
  • 16
  • 6
    Might be worth to mention that the error message "wrong type argument: stringp, nil" means that Emacs _expected_ a string but got a `nil` instead. – arvidj Oct 31 '18 at 12:52

2 Answers2

47

You'll need to provide more information to be sure. Try setting

(setq debug-on-error t)

which will give you a stack trace showing what function is complaining about the string being nil.

My guess is that buffer-file-name is returning nil, and that's where the problem lies (not all buffers have file names). Check out the debugging section of An Introduction To Programming in Emacs Lisp, or the debugging section of the Emacs Lisp manual.

Trey Jackson
  • 73,529
  • 11
  • 197
  • 229
  • My intention was to get the pom above the file for the current buffer in emacs, but I switched the buffer to a different one(one with no file) to see the results of my maven commands. – HahaHortness Mar 24 '11 at 03:29
  • Good answer. The link to the debugging section of An Introduction To Programming in Emacs Lisp is https://www.gnu.org/software/emacs/manual/html_node/eintr/Debugging.html#Debugging – bshanks Jul 18 '20 at 16:35
15

The secret to finding a problem in your init file is not a secret: binary search.

Use comment-region to comment out half your init file, then 3/4, 7/8,... It is very quick to identify the problem. comment-region also uncomments: C-h f comment-region RET.

Drew
  • 29,895
  • 7
  • 74
  • 104
  • Tho, in this instance, he needs to debug basically a "single chunk" of code, and he already knows which chunk it is, so there's really not much to be gained from binary search (which otherwise indeed usually works well for `~/.emacs` by virtue of it being mostly a sequence of independent instructions). – Stefan Sep 19 '18 at 12:26