dotfiles

🎜 Clone'em, tweak'em, stick'em in your $HOME 🎝
git clone https://git.kevinlegouguec.net/dotfiles
Log | Files | Refs | README

commit a8924d1fa1e2ce5f921d3aa54bd3205a6ff3f5b7
parent 4fc04f6c0dcf574ac714ded5c01d2dd9627f665f
Author: KΓ©vin Le Gouguec <kevin.legouguec@gmail.com>
Date:   Wed, 22 Jan 2025 09:32:56 +0100

Ditch when-let

Obsoleted.  While in there, rewrite to taste:

- could just switch to when-let*, but I hear and-let* is more
idiomatic for code that returns values; when(-let) OTOH denotes
side-effects.

- project-root (singular) has been available since 28, which is in
Debian stable.  Good enough.

- I know about 𝓍-let*'s (VALUEFORM) shorthand now.

- β€œ(string-trim-right root "/")”? 🀭

Diffstat:
M.emacs | 24+++++++++++++++---------
1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/.emacs b/.emacs @@ -632,19 +632,25 @@ UPSTREAMS is a list of fetch URLs." ;;;; Frame title. (defun my/project-root () - (when-let ((project (project-current))) - (car (project-roots project)))) + (and-let* ((project (project-current))) + (project-root project))) (defun my/project-name () - (when-let ((root (my/project-root))) - (when (not (file-equal-p root "~")) - (file-name-nondirectory (string-trim-right root "/"))))) + (and-let* ((root (my/project-root)) + ;; Home is under VC to track dotfile changes. Not a + ;; "project" I want shown in the UI though. + ((not (file-equal-p root "~")))) + (file-name-nondirectory (directory-file-name root)))) (defun my/connection-name () - (when-let ((method (file-remote-p default-directory 'method))) - (if (string-match-p "sudo" method) - method - (format "%s:%s" method (file-remote-p default-directory 'host))))) + (let ((method (file-remote-p default-directory 'method))) + (pcase method + ;; No method: nil. + ('nil method) + ;; sudo(edit): just "METHOD". + ((pred (string-match-p "sudo")) method) + ;; Default: "METHOD:HOST". + (_ (format "%s:%s" method (file-remote-p default-directory 'host)))))) (defun my/frame-title-format () (let ((prefix