summaryrefslogtreecommitdiff
path: root/.emacs
diff options
context:
space:
mode:
authorKΓ©vin Le Gouguec <kevin.legouguec@gmail.com>2025-01-22 09:32:56 +0100
committerKΓ©vin Le Gouguec <kevin.legouguec@gmail.com>2025-01-22 23:53:24 +0100
commita8924d1fa1e2ce5f921d3aa54bd3205a6ff3f5b7 (patch)
treee2d406fc69e30389ed3afd90ee3e35cd9c02250e /.emacs
parent4fc04f6c0dcf574ac714ded5c01d2dd9627f665f (diff)
downloaddotfiles-a8924d1fa1e2ce5f921d3aa54bd3205a6ff3f5b7.tar.xz
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 (limited to '.emacs')
-rw-r--r--.emacs24
1 files changed, 15 insertions, 9 deletions
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