From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Hongyi Zhao Newsgroups: gmane.emacs.help Subject: Re: Set the default-directory dynamically according to the buffer-file-name. Date: Thu, 30 Sep 2021 09:08:08 +0800 Message-ID: References: <87bl4b2y70.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="38253"; mail-complaints-to="usenet@ciao.gmane.io" Cc: help-gnu-emacs To: Tassilo Horn Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Thu Sep 30 03:09:03 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 1mVkZK-0009jp-TB for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 30 Sep 2021 03:09:02 +0200 Original-Received: from localhost ([::1]:49084 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mVkZJ-0002AK-SY for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 29 Sep 2021 21:09:01 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:41402) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mVkYg-00029w-3d for help-gnu-emacs@gnu.org; Wed, 29 Sep 2021 21:08:22 -0400 Original-Received: from mail-vs1-xe33.google.com ([2607:f8b0:4864:20::e33]:39761) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mVkYe-0005Qj-Na; Wed, 29 Sep 2021 21:08:21 -0400 Original-Received: by mail-vs1-xe33.google.com with SMTP id o124so5316757vsc.6; Wed, 29 Sep 2021 18:08:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=YZZ0Pe4Msens/Xu316Irp0ILqsTUMNaV2+GBS99xg2c=; b=pExv9RweojLT/0Rc26GHHAlaga8Jj4yZOz8i3/9SCYBMTflNxmKo0Auc9EJc0FCB0J 59KRiPNAPAf2gQmmfP+Od3MhzHs4sGNzVjxUtdy68Bno8SQR/qiqz7NVl6ENuwP2a6Xe kOKdh3MQ+VsYBsDH104RPePWOk/SMa4ycU+0CxYY4a++4lVX/6sLaWKSf/zibA2Hmt7f rzMjn9/Y6nV7o98k5IWaM/tYmBOisrSdFFLr45zuTMD/c1ztakLAZm6c1UFPqQbrsRl/ 6hlOATUwb83i/9czkUgJENRc/50PLQm8X1UaKtLyG+0YtJIWVbqtiLV80qiSKj6HLKLb c4gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=YZZ0Pe4Msens/Xu316Irp0ILqsTUMNaV2+GBS99xg2c=; b=mc4X3/Yc9VY2VGaxs4C1YqixGqkZtvqEZhk1qKi2C13IKeOjM+LbOM6CVl7fN2u+bn z76Jp8bdsry3iFBDHrb9C8Fm589aqxjO09Y8NaM8NVhW/H7l0hKgUVWFW0D8vpXyYpKL N0HEVMKhpifQ8A8TJ/Y2oNlFg5JMXFHNtiQwqFp4rbKIBTa+o/AYx8ixnw+SmbGGriFo /10pvniy1ddpPWKx11vthD5ItMvzXCJ0EPL5wAVGAZo4FJbYJ+ZHTGgMqqOLZmcVNzjR Zj9P2DY/Y+FEJ7+auCacRJhuT6ujet9OnRsxFprj6GgUll5cjXPiBvjxkTErHgpbxmk6 zfLw== X-Gm-Message-State: AOAM531Y6zTvNMAhBAI0Vd9lfYbm57q8PNOUlUGiY+LWQxSkH6pKcIAA pYjeTOBxRH7ETdyA24AoGv9mfEn416Pz9C+MNq2LnlXlmPGUxryt X-Google-Smtp-Source: ABdhPJxPtAunMzoC5epcQ3yQyXRUTAEMNbQ/ipscjA+l/nrSryxOKhQaqFVolGvEQwWZcWE8D16cTcUgZsUgqdZ3BMk= X-Received: by 2002:a67:3157:: with SMTP id x84mr1369222vsx.51.1632964099229; Wed, 29 Sep 2021 18:08:19 -0700 (PDT) In-Reply-To: <87bl4b2y70.fsf@gnu.org> Received-SPF: pass client-ip=2607:f8b0:4864:20::e33; envelope-from=hongyi.zhao@gmail.com; helo=mail-vs1-xe33.google.com 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_DNSWL_NONE=-0.0001, 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:133404 Archived-At: On Wed, Sep 29, 2021 at 11:34 PM Tassilo Horn wrote: > > Hongyi Zhao writes: > > > I wrote the following function to set the default-directory > > dynamically according to the buffer-file-name: > > > > (defun my/default-directory () > > (let ((file (buffer-file-name))) > > (if (not file) > > (message "no file name here.") > > (setq default-directory (file-name-directory (buffer-file-name)))))) > > > > Then I apply this function to specific hooks, say, python-mode-hook. > > This will make it easier for me to invoke files using the relative > > path of each project. I want to know if this is a good practice. > > Isn't that already the case that file-visiting buffers have > > (file-name-directory (buffer-file-name)) > > as `default-directory'? Yes, that's it. So, my code snippet is unnecessary. The problem I posted here should be relevant to and handled by Projectile, as I've noticed the following message: Projectile is initializing cache for /home/werner/ ... HZ