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: Hongyi Zhao
Subject: Re: let*: Wrong type argument: stringp, nil
Date: Wed, 29 Sep 2021 14:15:47 +0800

On Wed, Sep 29, 2021 at 11:58 AM Emanuel Berg via Users list for the
GNU Emacs text editor <help-gnu-emacs@gnu.org> wrote:
>
> Hongyi Zhao wrote:
>
> >   (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))))))))
>
> Use `let' so you don't have to hard-code the same data three
> times.

The code I’ve modified looks like this:

  (defun try/pyvenv-workon ()
    (when (buffer-file-name)
      (let ((file (concat (locate-dominating-file (buffer-file-name)
".python-version") ".python-version")))
        (when (file-exists-p file)
          (pyvenv-workon
            (with-temp-buffer
              (insert-file-contents file)
              (nth 0 (split-string (buffer-string)))))))))

Any further improvement tips?

HZ



reply via email to

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