From aacd40d6adbf9bfb510e40b7ddb93678e7cecbcd Mon Sep 17 00:00:00 2001 From: TCCQ Date: Wed, 9 Apr 2025 19:53:47 -0700 Subject: emacs to add single top header and move some (global) info there --- emacs/site-lisp/my-funcs.el | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'emacs/site-lisp/my-funcs.el') diff --git a/emacs/site-lisp/my-funcs.el b/emacs/site-lisp/my-funcs.el index 8bed290..01bf5cc 100644 --- a/emacs/site-lisp/my-funcs.el +++ b/emacs/site-lisp/my-funcs.el @@ -143,3 +143,16 @@ BEG and END define the region." (defun dired-do-find-marked-files () (interactive) (seq-do 'find-file (dired-get-marked-files))) + +(defun shorten-path (path) + "Shortens each directory in PATH except for the last directory to its first character." + (let* ((components (split-string path "/")) ; Split the path into components + (last-component (-last (lambda (s) (not (string-empty-p s))) components)) ; Extract the last component + (shortened-components ; Shorten all components except the last + (mapcar (lambda (comp) + (if (or (string-equal comp last-component) (string-empty-p comp)) + comp + (substring comp 0 1))) + components))) + (mapconcat 'identity shortened-components "/"))) ; Recombine components into a path + -- cgit v1.2.3