help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: let*: Wrong type argument: stringp, nil


From: Stephen Berman
Subject: Re: let*: Wrong type argument: stringp, nil
Date: Sat, 25 Sep 2021 12:09:39 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

On Fri, 24 Sep 2021 22:52:45 +0800 Hongyi Zhao <hongyi.zhao@gmail.com> wrote:

> According to the idea represented here [1], I wrote the following
> function to activate the python virtual environment automatically
> using the content of the ".python-version" file located in the project
> directory of the current opened python file:
>
> (defun pyvenv-autoload ()
>     (require 'projectile)
>     (let* ((pdir (file-name-directory buffer-file-name)) (pfile
> (concat pdir ".python-version")))
>       (if (file-exists-p pfile)
>           (pyvenv-workon (with-temp-buffer
>                            (insert-file-contents pfile)
>                            (nth 0 (split-string (buffer-string))))))))
> (add-hook 'python-mode-hook 'pyvenv-autoload)
>
> It seems the corresponding python virtual environment can be activated
> automatically when I open the python file in Emacs. But when I try to
> evaluate the file, the following message will be triggered, and defeat
> the evaluate operation:
>
> let*: Wrong type argument: stringp, nil
>
> [1] https://github.com/jorgenschaefer/pyvenv/issues/51#issuecomment-253902450
>
> Any hints for fixing this problem?

Evidently buffer-file-name is nil when the sexp `(file-name-directory
buffer-file-name)' is evaluated, which indicates the current buffer when
that function is called is not visiting a file (e.g., you get the same
error when you evaluate `(file-name-directory buffer-file-name)' in
*scratch*).

Steve Berman



reply via email to

[Prev in Thread] Current Thread [Next in Thread]