From a8924d1fa1e2ce5f921d3aa54bd3205a6ff3f5b7 Mon Sep 17 00:00:00 2001 From: Kévin Le Gouguec Date: Wed, 22 Jan 2025 09:32:56 +0100 Subject: Ditch when-let MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 "/")”? 🤭 --- .emacs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to '.emacs') diff --git a/.emacs b/.emacs index 788fbb8..fb10e12 100644 --- 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 -- cgit v1.2.3