[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: let*: Wrong type argument: stringp, nil
From: |
Hongyi Zhao |
Subject: |
Re: let*: Wrong type argument: stringp, nil |
Date: |
Wed, 29 Sep 2021 11:02:39 +0800 |
On Wed, Sep 29, 2021 at 10:03 AM Hongyi Zhao <hongyi.zhao@gmail.com> wrote:
>
> On Wed, Sep 29, 2021 at 9:43 AM Hongyi Zhao <hongyi.zhao@gmail.com> wrote:
> >
> > On Tue, Sep 28, 2021 at 4:02 PM Yuri Khan <yuri.v.khan@gmail.com> wrote:
> > >
> > > On Tue, 28 Sept 2021 at 10:08, Hongyi Zhao <hongyi.zhao@gmail.com> wrote:
> > >
> > > > Now I'm trying another test code snippet based on the idea posted here
> > > > [1]:
> > > >
> > > > (while (not (file-exists-p ".python-version"))
> > > > (cd "..")
> > > > ))
> > > >
> > > > But when I test the above code in scratch buffer, it seems to be stuck
> > > > in an endless loop and running there all the time. Any hints for this
> > > > problem?
> > >
> > > You’re not handling the case here that you reached the root directory
> > > without finding a .python-version file.
> > >
> > > You will really get better results if you use locate-dominating-file.
> > > If you’re trying to learn, learn by reading that function. As a bonus,
> > > it does not mess with the buffer’s default directory.
> >
> > I work out the following code snippets using locate-dominating-file,
> > and it works as expected:
> >
> > (defun try/pyvenv-workon ()
> > (when (locate-dominating-file (buffer-file-name) ".python-version")
>
> The following form should be used here:
>
> (when (and (buffer-file-name) (locate-dominating-file
> (buffer-file-name) ".python-version"))
>
> >
> > ;https://emacs.stackexchange.com/questions/9474/let-statement-throws-error-on-assigning-a-form-to-a-variable
> > (let ((file (concat (locate-dominating-file (buffer-file-name)
> > ".python-version") ".python-version")))
> > (pyvenv-workon (with-temp-buffer
> > (insert-file-contents file)
> > (nth 0 (split-string (buffer-string))))))))
The complete code for this purpose is as following now:
(defun try/pyvenv-workon ()
(when (and (buffer-file-name)
(locate-dominating-file (buffer-file-name) ".python-version"))
(let ((file (concat (locate-dominating-file (buffer-file-name)
".python-version") ".python-version")))
(pyvenv-workon
(with-temp-buffer
(insert-file-contents file)
(nth 0 (split-string (buffer-string))))))))
But I wonder if I can solve this problem by using
`locate-dominating-file' only once?
HZ
- Re: let*: Wrong type argument: stringp, nil, (continued)
- Re: let*: Wrong type argument: stringp, nil, Hongyi Zhao, 2021/09/25
- Re: let*: Wrong type argument: stringp, nil, Hongyi Zhao, 2021/09/27
- Re: let*: Wrong type argument: stringp, nil, Emanuel Berg, 2021/09/27
- Re: let*: Wrong type argument: stringp, nil, Emanuel Berg, 2021/09/27
- Re: let*: Wrong type argument: stringp, nil, Hongyi Zhao, 2021/09/28
- Re: let*: Wrong type argument: stringp, nil, Emanuel Berg, 2021/09/28
- Re: let*: Wrong type argument: stringp, nil, Yuri Khan, 2021/09/28
- Re: let*: Wrong type argument: stringp, nil, Hongyi Zhao, 2021/09/28
- Re: let*: Wrong type argument: stringp, nil, Hongyi Zhao, 2021/09/28
- Re: let*: Wrong type argument: stringp, nil, Hongyi Zhao, 2021/09/28
- Re: let*: Wrong type argument: stringp, nil,
Hongyi Zhao <=
- Re: let*: Wrong type argument: stringp, nil, Emanuel Berg, 2021/09/28
- Re: let*: Wrong type argument: stringp, nil, Hongyi Zhao, 2021/09/29
- Re: let*: Wrong type argument: stringp, nil, Emanuel Berg, 2021/09/29
- Re: let*: Wrong type argument: stringp, nil, Hongyi Zhao, 2021/09/29
- Re: let*: Wrong type argument: stringp, nil, Emanuel Berg, 2021/09/29
- Re: let*: Wrong type argument: stringp, nil, Hongyi Zhao, 2021/09/29
- Re: let*: Wrong type argument: stringp, nil, Yuri Khan, 2021/09/29
- Re: let*: Wrong type argument: stringp, nil, Hongyi Zhao, 2021/09/29
- Re: let*: Wrong type argument: stringp, nil, Yuri Khan, 2021/09/29
- Re: let*: Wrong type argument: stringp, nil, Hongyi Zhao, 2021/09/29