Skip to content

Commit 34a6af6

Browse files
[sesman] Link a newly opened file with the current buffer's session
1 parent 588c579 commit 34a6af6

File tree

1 file changed

+70
-63
lines changed

1 file changed

+70
-63
lines changed

cider-common.el

Lines changed: 70 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -375,69 +375,76 @@ is treated as such. Finally, if URL is relative, it is expanded within each
375375
of the open Clojure buffers till an existing file ending with URL has been
376376
found."
377377
(require 'arc-mode)
378-
(cond ((string-match "^file:\\(.+\\)" url)
379-
(when-let* ((file (cider--url-to-file (match-string 1 url)))
380-
(path (cider--file-path file)))
381-
(find-file-noselect path)))
382-
((string-match "^\\(jar\\|zip\\):\\(file:.+\\)!/\\(.+\\)" url)
383-
(when-let* ((entry (match-string 3 url))
384-
(file (cider--url-to-file (match-string 2 url)))
385-
(path (cider--file-path file))
386-
(name (format "%s:%s" path entry))
387-
(avfs (format "%s%s#uzip/%s"
388-
(expand-file-name (or (getenv "AVFSBASE") "~/.avfs/"))
389-
path entry)))
390-
(cond
391-
;; 1) use avfs
392-
((file-exists-p avfs)
393-
(find-file-noselect avfs))
394-
;; 2) already uncompressed
395-
((find-buffer-visiting name))
396-
;; 3) on remotes use Emacs built-in archiving
397-
((tramp-tramp-file-p path)
398-
(find-file path)
399-
(goto-char (point-min))
400-
;; anchor to eol to prevent eg. clj matching cljs.
401-
(re-search-forward (concat entry "$"))
402-
(let ((archive-buffer (current-buffer)))
403-
(archive-extract)
404-
(kill-buffer archive-buffer))
405-
(current-buffer))
406-
;; 4) Use external zip program to extract a single file
407-
(t
408-
(with-current-buffer (generate-new-buffer
409-
(file-name-nondirectory entry))
410-
;; Use appropriate coding system for bytes read from unzip cmd to
411-
;; display Emacs native newlines regardless of whether the file
412-
;; uses unix LF or dos CRLF line endings.
413-
;; It's important to avoid spurious CR characters, which may
414-
;; appear as `^M', because they can confuse clojure-mode's symbol
415-
;; detection, e.g. `clojure-find-ns', and break `cider-find-var'.
416-
;; `clojure-find-ns' uses Emacs' (thing-at-point 'symbol) as
417-
;; part of identifying a file's namespace, and when a file
418-
;; isn't decoded properly, namespaces can be reported as
419-
;; `my.lib^M' which `cider-find-var' won't know what to do with.
420-
(let ((coding-system-for-read 'prefer-utf-8))
421-
(archive-zip-extract path entry))
422-
(set-visited-file-name name)
423-
(setq-local default-directory (file-name-directory path))
424-
(setq-local buffer-read-only t)
425-
(set-buffer-modified-p nil)
426-
(set-auto-mode)
427-
(current-buffer))))))
428-
(t (if-let* ((path (cider--file-path url)))
429-
(find-file-noselect path)
430-
(unless (file-name-absolute-p url)
431-
(let ((cider-buffers (cider-util--clojure-buffers))
432-
(url (file-name-nondirectory url)))
433-
(or (cl-loop for bf in cider-buffers
434-
for path = (with-current-buffer bf
435-
(expand-file-name url))
436-
if (and path (file-exists-p path))
437-
return (find-file-noselect path))
438-
(cl-loop for bf in cider-buffers
439-
if (string= (buffer-name bf) url)
440-
return bf))))))))
378+
(let ((buffer
379+
(cond ((string-match "^file:\\(.+\\)" url)
380+
(when-let* ((file (cider--url-to-file (match-string 1 url)))
381+
(path (cider--file-path file)))
382+
(find-file-noselect path)))
383+
((string-match "^\\(jar\\|zip\\):\\(file:.+\\)!/\\(.+\\)" url)
384+
(when-let* ((entry (match-string 3 url))
385+
(file (cider--url-to-file (match-string 2 url)))
386+
(path (cider--file-path file))
387+
(name (format "%s:%s" path entry))
388+
(avfs (format "%s%s#uzip/%s"
389+
(expand-file-name (or (getenv "AVFSBASE") "~/.avfs/"))
390+
path entry)))
391+
(cond
392+
;; 1) use avfs
393+
((file-exists-p avfs)
394+
(find-file-noselect avfs))
395+
;; 2) already uncompressed
396+
((find-buffer-visiting name))
397+
;; 3) on remotes use Emacs built-in archiving
398+
((tramp-tramp-file-p path)
399+
(find-file path)
400+
(goto-char (point-min))
401+
;; anchor to eol to prevent eg. clj matching cljs.
402+
(re-search-forward (concat entry "$"))
403+
(let ((archive-buffer (current-buffer)))
404+
(archive-extract)
405+
(kill-buffer archive-buffer))
406+
(current-buffer))
407+
;; 4) Use external zip program to extract a single file
408+
(t
409+
(with-current-buffer (generate-new-buffer
410+
(file-name-nondirectory entry))
411+
;; Use appropriate coding system for bytes read from unzip cmd to
412+
;; display Emacs native newlines regardless of whether the file
413+
;; uses unix LF or dos CRLF line endings.
414+
;; It's important to avoid spurious CR characters, which may
415+
;; appear as `^M', because they can confuse clojure-mode's symbol
416+
;; detection, e.g. `clojure-find-ns', and break `cider-find-var'.
417+
;; `clojure-find-ns' uses Emacs' (thing-at-point 'symbol) as
418+
;; part of identifying a file's namespace, and when a file
419+
;; isn't decoded properly, namespaces can be reported as
420+
;; `my.lib^M' which `cider-find-var' won't know what to do with.
421+
(let ((coding-system-for-read 'prefer-utf-8))
422+
(archive-zip-extract path entry))
423+
(set-visited-file-name name)
424+
(setq-local default-directory (file-name-directory path))
425+
(setq-local buffer-read-only t)
426+
(set-buffer-modified-p nil)
427+
(set-auto-mode)
428+
(current-buffer))))))
429+
(t (if-let* ((path (cider--file-path url)))
430+
(find-file-noselect path)
431+
(unless (file-name-absolute-p url)
432+
(let ((cider-buffers (cider-util--clojure-buffers))
433+
(url (file-name-nondirectory url)))
434+
(or (cl-loop for bf in cider-buffers
435+
for path = (with-current-buffer bf
436+
(expand-file-name url))
437+
if (and path (file-exists-p path))
438+
return (find-file-noselect path))
439+
(cl-loop for bf in cider-buffers
440+
if (string= (buffer-name bf) url)
441+
return bf))))))))
442+
(sesman-session (sesman-current-session 'CIDER)))
443+
;; After finding a Clojure file, link it with the same session that we
444+
;; jumped from.
445+
(when sesman-session
446+
(sesman-link-with-buffer buffer sesman-session))
447+
buffer))
441448

442449
(defun cider--open-other-window-p (arg)
443450
"Test prefix value ARG to see if it indicates displaying results in other window."

0 commit comments

Comments
 (0)