fix: extract title column from hermes sessions list, strip [Project] prefix for pre-fill

The hermes sessions list format is:
  Title    Preview    Last Active   ID

Session display (menu) = full line including Title+Preview+Time
Title pre-fill = first column only, [Project] prefix stripped

- Use split-string with 3+ whitespace to extract first column
- No longer try to strip source/timestamp from 'before'
- Cleaner titles alist: sid -> clean-title without project prefix
This commit is contained in:
2026-07-18 18:51:43 -04:00
parent 104a7b0764
commit 47d26a6a8d
3 changed files with 54 additions and 69 deletions

1
doom/.config/doom/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
*.bak

View File

@@ -993,7 +993,7 @@ Broken for now..
(truncate p1) (1+ (truncate p2)) nil
`(priority ,(setq elgantt-user-set-color-priority-counter
(1- elgantt-user-set-color-priority-counter))
:elgantt-user-overlay ,elgantt-org-id)))))))))))
:elgantt-user-overlay ,elgantt-org-id))))))))))
;; --- Rule 3: Blocker Lines ---
(elgantt-create-display-rule draw-blocker-lines
@@ -2175,48 +2175,40 @@ If SESSION-ID is empty, show a menu of recent sessions to browse."
(if (string-empty-p id)
(let* ((output (shell-command-to-string "hermes sessions list --limit 50 2>&1"))
(lines (split-string output "\n" t))
(data-lines (nthcdr 2 lines)) ; skip header + separator
(id-re "[0-9]\\{8\\}_[0-9]\\{6\\}_[a-f0-9]\\{6\\}")
(items (delq nil
(mapcar (lambda (line)
(when (string-match (concat id-re "$") line)
(let* ((id (match-string 0 line))
(before-id (substring line 0 (match-beginning 0)))
(full-preview (string-trim
(replace-regexp-in-string
"\\s-+[a-z][a-z0-9]*\\s-*$" "" before-id))))
(cons full-preview id)))
data-lines))
(data-lines (nthcdr 2 lines))
(id-regex "[0-9]\\{8\\}_[0-9]\\{6\\}_[a-f0-9]\\{6\\}")
(sessions (delq nil
(mapcar
(lambda (line)
(when (string-match (concat id-regex "$") line)
(let* ((sid (match-string 0 line))
(before (substring line 0 (match-beginning 0))))
(list (string-trim before) sid))))
data-lines)))
(items (mapcar (lambda (s) (cons (car s) (cadr s))) sessions))
(titles (delq nil
(mapcar (lambda (line)
(when (string-match (concat id-re "$") line)
(let* ((id (match-string 0 line))
(before-id (substring line 0 (match-beginning 0)))
(full (string-trim
(mapcar
(lambda (s)
(let* ((sid (cadr s))
(full (car s))
(title (car (split-string full "\\s-\\{3,\\}" t)))
(clean (string-trim
(replace-regexp-in-string
"\\s-+[a-z][a-z0-9]*\\s-*$" "" before-id)))
(clean (string-trim
(replace-regexp-in-string
"\\s-+\\(just now\\|[0-9]+[mhd] ago\\|[0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}\\)$"
"" full))))
(cons id clean)))
data-lines))))
"^\\[[^]]+\\]\\s-+" "" title))))
(when sid (cons sid clean))))
sessions))))
(if (null items)
(user-error "No recent sessions found")
(let* ((vertico-sort-function 'identity) ; keep vertico, no re-sort
(choice (completing-read "Session: " items nil t))
(sid (cdr (assoc choice items)))
(default-title (cdr (assoc sid titles))))
(list sid (read-string "Title: " default-title)))))
(user-error "No recent sessions found")
(let* ((vertico-sort-function 'identity)
(choice (completing-read "Session: " items nil t))
(sid (cdr (assoc choice items)))
(default-title (cdr (assoc sid titles))))
(list sid (read-string "Title: " default-title)))))
(list id (read-string "Title: ")))))
(pcase-let ((`(,root ,sfile ,name) (gortium/hermes--project-info)))
(gortium/hermes--rename-session id (format "[%s] %s" name title))
(gortium/hermes-append-session sfile id title)
(message "Session %s linked to project %s as \"%s\"" id name title)))
;; -------------------------------------------------------------------
;; Keybindings (under SPC p)
;; -------------------------------------------------------------------
(map! :leader
:desc "New Hermes session" "p h" #'gortium/hermes-start
:desc "Resume Hermes session" "p H" #'gortium/hermes-resume

View File

@@ -1371,48 +1371,40 @@ If SESSION-ID is empty, show a menu of recent sessions to browse."
(if (string-empty-p id)
(let* ((output (shell-command-to-string "hermes sessions list --limit 50 2>&1"))
(lines (split-string output "\n" t))
(data-lines (nthcdr 2 lines)) ; skip header + separator
(id-re "[0-9]\\{8\\}_[0-9]\\{6\\}_[a-f0-9]\\{6\\}")
(items (delq nil
(mapcar (lambda (line)
(when (string-match (concat id-re "$") line)
(let* ((id (match-string 0 line))
(before-id (substring line 0 (match-beginning 0)))
(full-preview (string-trim
(replace-regexp-in-string
"\\s-+[a-z][a-z0-9]*\\s-*$" "" before-id))))
(cons full-preview id)))
data-lines))
(data-lines (nthcdr 2 lines))
(id-regex "[0-9]\\{8\\}_[0-9]\\{6\\}_[a-f0-9]\\{6\\}")
(sessions (delq nil
(mapcar
(lambda (line)
(when (string-match (concat id-regex "$") line)
(let* ((sid (match-string 0 line))
(before (substring line 0 (match-beginning 0))))
(list (string-trim before) sid))))
data-lines)))
(items (mapcar (lambda (s) (cons (car s) (cadr s))) sessions))
(titles (delq nil
(mapcar (lambda (line)
(when (string-match (concat id-re "$") line)
(let* ((id (match-string 0 line))
(before-id (substring line 0 (match-beginning 0)))
(full (string-trim
(mapcar
(lambda (s)
(let* ((sid (cadr s))
(full (car s))
(title (car (split-string full "\\s-\\{3,\\}" t)))
(clean (string-trim
(replace-regexp-in-string
"\\s-+[a-z][a-z0-9]*\\s-*$" "" before-id)))
(clean (string-trim
(replace-regexp-in-string
"\\s-+\\(just now\\|[0-9]+[mhd] ago\\|[0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}\\)$"
"" full))))
(cons id clean)))
data-lines))))
"^\\[[^]]+\\]\\s-+" "" title))))
(when sid (cons sid clean))))
sessions))))
(if (null items)
(user-error "No recent sessions found")
(let* ((vertico-sort-function 'identity) ; keep vertico, no re-sort
(choice (completing-read "Session: " items nil t))
(sid (cdr (assoc choice items)))
(default-title (cdr (assoc sid titles))))
(list sid (read-string "Title: " default-title)))))
(user-error "No recent sessions found")
(let* ((vertico-sort-function 'identity)
(choice (completing-read "Session: " items nil t))
(sid (cdr (assoc choice items)))
(default-title (cdr (assoc sid titles))))
(list sid (read-string "Title: " default-title)))))
(list id (read-string "Title: ")))))
(pcase-let ((`(,root ,sfile ,name) (gortium/hermes--project-info)))
(gortium/hermes--rename-session id (format "[%s] %s" name title))
(gortium/hermes-append-session sfile id title)
(message "Session %s linked to project %s as \"%s\"" id name title)))
;; -------------------------------------------------------------------
;; Keybindings (under SPC p)
;; -------------------------------------------------------------------
(map! :leader
:desc "New Hermes session" "p h" #'gortium/hermes-start
:desc "Resume Hermes session" "p H" #'gortium/hermes-resume