@@ -411,6 +411,16 @@ ALIASES may be a list of strings or an alist of (alias . project-name)."
411411 (or (cdr (assoc alias project-aliases))
412412 alias))
413413
414+ (defun enkan-repl--merge-target-directories (primary fallback )
415+ " Return target directories from PRIMARY merged with FALLBACK.
416+ Entries in PRIMARY win when both lists contain the same alias. This keeps
417+ workspace-local imported paths authoritative while preserving the user's wider
418+ target directory registry across workspace loads."
419+ (append primary
420+ (cl-remove-if (lambda (entry )
421+ (assoc (car entry) primary))
422+ fallback)))
423+
414424(defun enkan-repl--projects-with-current-aliases (projects current-project project-aliases )
415425 " Return PROJECTS augmented with CURRENT-PROJECT's PROJECT-ALIASES.
416426Merge the current workspace's aliases into CURRENT-PROJECT's project
@@ -460,7 +470,9 @@ This function restores workspace state from the given plist."
460470 (setq enkan-repl-project-aliases (plist-get state :project-aliases )))
461471 (when (plist-member state :target-directories )
462472 (setq enkan-repl-target-directories
463- (plist-get state :target-directories ))))
473+ (enkan-repl--merge-target-directories
474+ (plist-get state :target-directories )
475+ enkan-repl-target-directories))))
464476
465477(defun enkan-repl--save-workspace-state (&optional workspace-id )
466478 " Save current globals into `enkan-repl--workspaces' under WORKSPACE-ID.
@@ -798,23 +810,29 @@ This ensures that directory lookups work correctly after workspace switch."
798810 ; ; Find project directories from files in standard locations
799811 (let ((dirs '()))
800812 ; ; Check standard project locations
801- (dolist (alias enkan-repl-project-aliases)
813+ (dolist (alias ( enkan-repl-- project-alias-names enkan-repl-project- aliases) )
802814 ; ; Try to find project directory from standard locations
803- (let* ((home-dir (expand-file-name " ~" ))
815+ (let* ((project-name
816+ (enkan-repl--project-name-for-alias
817+ alias enkan-repl-project-aliases))
818+ (home-dir (expand-file-name " ~" ))
804819 (common-paths (list
805- (expand-file-name (format " dev/self/%s " enkan-repl--current- project) home-dir)
806- (expand-file-name (format " dev/%s " enkan-repl--current- project) home-dir)
807- (expand-file-name (format " Documents/%s " enkan-repl--current- project) home-dir)
808- (expand-file-name (format " projects/%s " enkan-repl--current- project) home-dir)
809- (expand-file-name enkan-repl--current- project default-directory))))
820+ (expand-file-name (format " dev/self/%s " project-name ) home-dir)
821+ (expand-file-name (format " dev/%s " project-name ) home-dir)
822+ (expand-file-name (format " Documents/%s " project-name ) home-dir)
823+ (expand-file-name (format " projects/%s " project-name ) home-dir)
824+ (expand-file-name project-name default-directory))))
810825 ; ; Find first existing directory
811826 (dolist (path common-paths)
812827 (when (and (not (assoc alias dirs))
813828 (file-directory-p path))
814- (push (cons alias (cons enkan-repl--current- project path)) dirs)))))
829+ (push (cons alias (cons project-name path)) dirs)))))
815830 ; ; Update enkan-repl-target-directories if we found directories
816831 (when dirs
817- (setq enkan-repl-target-directories dirs)))))
832+ (setq enkan-repl-target-directories
833+ (enkan-repl--merge-target-directories
834+ (nreverse dirs)
835+ enkan-repl-target-directories))))))
818836
819837(defun enkan-repl--initialize-default-workspace ()
820838 " Initialize default workspace '01' with first available project.
@@ -1509,7 +1527,8 @@ COUNTER: session counter"
15091527
15101528(defun enkan-repl--setup-start-sessions (alias-list buffer-name )
15111529 " Start terminal sessions for each alias in ALIAS-LIST and log to BUFFER-NAME.
1512- Includes error handling for individual session failures."
1530+ Includes error handling for individual session failures.
1531+ Returns a plist with `:success-count' and `:failure-count' ."
15131532 (with-current-buffer buffer-name
15141533 (princ " 🚀 Starting terminal sessions:\n " ))
15151534 (let ((session-number 1 )
@@ -1533,7 +1552,9 @@ Includes error handling for individual session failures."
15331552 (setq failure-count (1+ failure-count))))
15341553 (setq session-number (1+ session-number)))
15351554 (with-current-buffer buffer-name
1536- (princ (format " \n 📊 Session start summary: %d success, %d failed\n\n " success-count failure-count)))))
1555+ (princ (format " \n 📊 Session start summary: %d success, %d failed\n\n " success-count failure-count)))
1556+ (list :success-count success-count
1557+ :failure-count failure-count)))
15371558
15381559(defun enkan-repl--setup-project-session (alias )
15391560 " Setup project session for given ALIAS.
@@ -1600,7 +1621,12 @@ Category: Session Controller"
16001621 (error " Project '%s ' not found " project-name))
16011622 (enkan-repl--setup-set-project-aliases project-name alias-list buffer-name)
16021623 ; ; Start sessions
1603- (enkan-repl--setup-start-sessions alias-list buffer-name))
1624+ (let ((start-result
1625+ (enkan-repl--setup-start-sessions alias-list buffer-name)))
1626+ (when (> (plist-get start-result :failure-count ) 0 )
1627+ (error " Failed to start %d of %d terminal session(s) "
1628+ (plist-get start-result :failure-count )
1629+ (length alias-list)))))
16041630 ; ; Set final project configuration
16051631 (enkan-repl--ws-set-current-project project-name)
16061632 (princ (format " \n ✅ Setup completed for project: %s \n " project-name))
0 commit comments