wrong type argument: stringp, nil

人盡茶涼 提交于 2019-12-18 10:33:58

问题


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"))

回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/5413959/wrong-type-argument-stringp-nil

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!