From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stephen Berman Newsgroups: gmane.emacs.help Subject: Re: let*: Wrong type argument: stringp, nil Date: Sat, 25 Sep 2021 16:45:48 +0200 Message-ID: <87a6k0sogz.fsf@gmx.net> References: <87lf3lrmos.fsf@gmx.net> <87ee9csyp0.fsf@gmx.net> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="7705"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: help-gnu-emacs To: Hongyi Zhao Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Sat Sep 25 16:46:38 2021 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mU8wo-0001oB-78 for geh-help-gnu-emacs@m.gmane-mx.org; Sat, 25 Sep 2021 16:46:38 +0200 Original-Received: from localhost ([::1]:57978 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mU8wn-0003jF-3u for geh-help-gnu-emacs@m.gmane-mx.org; Sat, 25 Sep 2021 10:46:37 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:41458) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mU8w6-0003iW-Hp for help-gnu-emacs@gnu.org; Sat, 25 Sep 2021 10:45:54 -0400 Original-Received: from mout.gmx.net ([212.227.17.21]:42083) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mU8w4-0000By-GM for help-gnu-emacs@gnu.org; Sat, 25 Sep 2021 10:45:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1632581150; bh=jGwjV3G71XbvuGKWKITKj1xrqc1ZsG7Bw7k13rOF01U=; h=X-UI-Sender-Class:From:To:Cc:Subject:References:Date:In-Reply-To; b=jGGfdP6RzRiPutx2ZWTmt4cgEHe/6OZw+WnVccHgDAGXjWOjBvXeAOx3t6j4O/KVn YtT2nFDhbNywz1o8fEGP9jvf6BBwKw3MBcH9uIPeM/Uehri1aK7hqXrNkfg5EExvXh e3kgcBusl1+0aat5SweBtAGs4UI4cAVLVDV5p0RY= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Original-Received: from strobelfs ([188.109.144.155]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MY6Cb-1mMBvv0XWv-00YRCe; Sat, 25 Sep 2021 16:45:50 +0200 In-Reply-To: (Hongyi Zhao's message of "Sat, 25 Sep 2021 21:49:38 +0800") X-Provags-ID: V03:K1:d8ijodi2mFVO7bgDj3F6i6+ADpmIgC0jTrlX1DVCBr7AQPBpfro Kaj0A1WXoV5KGsuxivi940MI321MF0K0JpaAOAfOcUAiIuRdufw1+Q+5HPhPlsNxETydegO WQDknSoXk+vhwxlrG74pVydV4uA73+qAxe92mgHRTnxORxKN7uxusBq9JpcsvRvp9kjO+rl 5krrCfWApxB7yF//4BfJw== X-UI-Out-Filterresults: notjunk:1;V03:K0:GaQ+xfk+oGw=:FJ2QhylFeSNZCdaah94APY M/PuqtZd55zGDUZQ320NuNtOil2GUGwJTZ/Om4WiesaIiRsW9+hIeXNngbUjzTFd+uXiltBBA MOaPkkinMyqBRWc2YwiGSsOvmq7JpNV7hSLhQDFcyZvwMFknoHy/CPhkeukFy+XFhfxtwBuPm L58fMu2HNT/B5yTFHTOvOlbllVl5o5Nw3B/gNvQ0yy+QIO1eqiQx7AOaa8E32LRQ0KuGySXKG YCc4cj7ISMX+gkqGGW2ZSi68GfpIDoquXV56tsFKKEJU7MvNT9kk4pVUVHVM8aw0nkG27LH4L roGRoJf7p0S2HXlyVKfpyt7MnYTeZ7J8ULemvkWfi4/gIMum/5aK8YGfiNFh3zYKYgKQvCbL4 HFH8NBv/PfTqnvy1dV6WWxKAifDZ6J7IIYKTUTBHhYmqHOc0bCJOT6urZTcibu1yqDzGogRyk MqjKiBjhJhhg1nALPtgVks8em06eJ+SrLjkMx2ieMnwnLG5+8OkTZEXoQv10kYtTCXDstmGob a1V8Jsnia6O7xVOJxieaHhQ3kG0JCZ4Y4ybvaP5IK8rMM46KZ1xJ2MgkZ2g1UA5g0PcBV1MbE /nkOsX2WGAj2ybu/W0rr6hpfHC3z3gc+EU/kH7G/sEhnP+HDaBL4S8OWJAg0HpNYNlVAUDIVi /eyDnViqrPoH+uxIA4c+Lrs9vnO7gvF5W2kJnFEmCNc68reldXYaS4WGBJXW/h7QWE2YbUQZ5 79dTT4tssBJTHA1eKpwGw/5dXloKacHFiBVe/nlqOV2nRkqTq/NnQm2In12uby7V41tjCujj Received-SPF: pass client-ip=212.227.17.21; envelope-from=stephen.berman@gmx.net; helo=mout.gmx.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:133238 Archived-At: On Sat, 25 Sep 2021 21:49:38 +0800 Hongyi Zhao wrote: [...] > But the actual demand exceeds the simple processing above, I mean, the > real project maybe located under a specific folder with multiple level > subdirectories. In this case, when I open a python file, the function > should do the following: Search the current directory and its parent > directories at all levels in turn. Once the ".python-version" file is > found, activate the corresponding environment and exit the cycle; > Otherwise, continue to search upwards until the certain top level > directory, say, $HOME. Based on the above requirements and the code > snippets given here [1-2], I finally figured out the following > solution: > > ------- > (defun parent-directory (dir) > (unless (equal (getenv "HOME") dir) > ;file-truename or directory-file-name > (file-name-directory (directory-file-name dir)))) > > > (defun find-file-in-heirarchy (current-dir fname) > "Search for a file named FNAME upwards through the directory > hierarchy, starting from CURRENT-DIR" > (let ((file (concat current-dir fname)) > (parent (parent-directory (expand-file-name current-dir)))) > (if (file-exists-p file) > file > (when parent > (find-file-in-heirarchy parent fname))))) > > > (defun try/pyvenv-workon () > (when (buffer-file-name) > (let ((file (find-file-in-heirarchy (buffer-file-name) > ".python-version"))) > (when (file-exists-p file) > (pyvenv-workon (with-temp-buffer > (insert-file-contents file) > (nth 0 (split-string > (buffer-string))))))))) > > (add-hook 'python-mode-hook 'try/pyvenv-workon) > ------- > > It works like a charm. But any suggestions/enhancements/comments will > be greatly appreciated. > > [1] https://stackoverflow.com/a/14096693 (*) > [2] http://sodaware.sdf.org/notes/emacs-lisp-find-file-upwards/ > > * Indicated that this is my main reference source code. Doesn't using the built-in Emacs function `locate-dominating-file', as mentioned in the stackoverflow thread, work just as well as `find-file-in-heirarchy'? Steve Berman