@@ -550,32 +550,43 @@ When there is a possible unfinished ansi control sequence,
550550 (insert-before-markers (cadr ansi-color-context))
551551 (setq ansi-color-context nil )))
552552
553- (defvar cider-repl--root-ns-highlitht-template " \\ <%s [^$/: \t\n ]+"
553+ (defvar cider-repl--root-ns-highlitht-template " \\ <\\ (%s \\ ) [^$/: \t\n ]+"
554554 " Regexp used to highlight root ns in REPL buffers." )
555555
556556(defvar-local cider-repl--root-ns-regexp nil
557557 " Cache of root ns regexp in REPLs." )
558558
559+ (defvar-local cider-repl--ns-roots nil
560+ " List holding all past root namespaces seen during interactive eval." )
561+
562+ (defun cider-repl--cache-ns-roots (ns-form connection )
563+ " Given NS-FORM cache root ns in CONNECTION."
564+ (with-current-buffer connection
565+ (when (string-match " ^[ \t\n ]*\( ns[ \t\n ]+\\ ([^. \t\n ]+\\ )" ns-form)
566+ (let ((root (match-string-no-properties 1 ns-form)))
567+ (unless (member root cider-repl--ns-roots)
568+ (push root cider-repl--ns-roots)
569+ (let ((roots (mapconcat
570+ ; ; Replace _ or - with regexp patter to accommodate "raw" namespaces
571+ (lambda (r ) (replace-regexp-in-string " [_-]+" " [_-]+" r))
572+ cider-repl--ns-roots " \\ |" )))
573+ (setq cider-repl--root-ns-regexp
574+ (format cider-repl--root-ns-highlitht-template roots))))))))
575+
559576(defun cider-repl--apply-current-project-color (string )
560577 " Fontify project's root namespace to make stacktraces more readable.
561578Foreground of `cider-stacktrace-ns-face' is used to propertize matched
562579namespaces. STRING is REPL's output."
563- (if (null nrepl-project-dir)
564- string
565- (unless cider-repl--root-ns-regexp
566- (let ((root (file-name-nondirectory (directory-file-name nrepl-project-dir))))
567- (setq cider-repl--root-ns-regexp
568- ; ; Replace _ or - with regexp patter to accommodate "raw" namespaces
569- (format cider-repl--root-ns-highlitht-template
570- (replace-regexp-in-string " [_-]+" " [_-]+" root)))))
571- (let ((start 0 )
572- (end 0 ))
573- (while (setq start (string-match cider-repl--root-ns-regexp string end))
574- (setq end (match-end 0 ))
575- (let ((face-spec (list (cons 'foreground-color
576- (face-attribute 'cider-stacktrace-ns-face :foreground nil t )))))
577- (font-lock-prepend-text-property start end 'face face-spec string)))
578- string)))
580+ (if cider-repl--root-ns-regexp
581+ (let ((start 0 )
582+ (end 0 ))
583+ (while (setq start (string-match cider-repl--root-ns-regexp string end))
584+ (setq end (match-end 0 ))
585+ (let ((face-spec (list (cons 'foreground-color
586+ (face-attribute 'cider-stacktrace-ns-face :foreground nil t )))))
587+ (font-lock-prepend-text-property start end 'face face-spec string)))
588+ string)
589+ string))
579590
580591(defun cider-repl--emit-output-at-pos (buffer string output-face position &optional bol )
581592 " Using BUFFER, insert STRING (applying to it OUTPUT-FACE) at POSITION.
@@ -972,7 +983,7 @@ namespace to switch to."
972983Each element in the alist has the form (NAME REGEXP HIGHLIGHT VAR FILE
973984LINE), where NAME is the identifier of the regexp, REGEXP - regexp matching
974985a location, HIGHLIGHT - sub-expression matching region to highlight on
975- mouse-over, VAR - sub-expression giving Clojure VAR to look up. FILE is
986+ mouse-over, VAR - sub-expression giving Clojure VAR to look up. FILE is
976987currently only used when VAR is nil and must be full resource path in that
977988case."
978989 :type '(alist :key-type sexp)
0 commit comments