{"action":"created","issue":{"url":"https://api.github.com/repos/clojure-emacs/cider/issues/1633","repository_url":"https://api.github.com/repos/clojure-emacs/cider","labels_url":"https://api.github.com/repos/clojure-emacs/cider/issues/1633/labels{/name}","comments_url":"https://api.github.com/repos/clojure-emacs/cider/issues/1633/comments","events_url":"https://api.github.com/repos/clojure-emacs/cider/issues/1633/events","html_url":"https://github.com/clojure-emacs/cider/issues/1633","id":143148961,"number":1633,"title":"*cider-scratch* buffer can switch namespace unexpectedly","user":{"login":"sanjayl","id":7213170,"avatar_url":"https://avatars.githubusercontent.com/u/7213170?v=3","gravatar_id":"","url":"https://api.github.com/users/sanjayl","html_url":"https://github.com/sanjayl","followers_url":"https://api.github.com/users/sanjayl/followers","following_url":"https://api.github.com/users/sanjayl/following{/other_user}","gists_url":"https://api.github.com/users/sanjayl/gists{/gist_id}","starred_url":"https://api.github.com/users/sanjayl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sanjayl/subscriptions","organizations_url":"https://api.github.com/users/sanjayl/orgs","repos_url":"https://api.github.com/users/sanjayl/repos","events_url":"https://api.github.com/users/sanjayl/events{/privacy}","received_events_url":"https://api.github.com/users/sanjayl/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2016-03-24T04:37:58Z","updated_at":"2016-03-26T14:54:35Z","closed_at":null,"body":"## Expected behavior\r\nThe active namespace in the `*cider-scratch*` buffer will not be changed until a namespace altering function is evaluated (eg, `in-ns`).\r\n## Actual behavior\r\nThe active *ns* of the scratch buffer is dependent on `cider-find-ns` by way of the `cider-current-ns` fn. `cider-find-ns` does not query the middleware to find the actual running namespace, instead, I think it parses the text around point to find the nearest ns form and it uses that as the `:ns` in subsequent `eval` calls. \r\n\r\nSee [the screencast of the bug](https://www.youtube.com/watch?v=ej89SeeFxQ4). Note that the `(in-ns 'clojure.set)` form was **not** evaluated in the scratch buffer, but `clojure.set/union` was still available to me.\r\n\r\nAs an aside, discovered while writing a hook to change to header line of the scratch buffer to the current namespace, also relying on `cider-current-ns`. As you can see in the video by following the header line, the active ns is changing while I type.\r\n\r\nAs a bonus aside, here's the code that I put in my setup in case anyone else might want to use it:\r\n```elisp\r\n(defun update-cider-scratch-header ()\r\n  (interactive)\r\n  (when (eq major-mode 'cider-clojure-interaction-mode)\r\n    (let* ((ww (window-width))\r\n           (ns (cider-current-ns))\r\n           (ns-len (length ns))\r\n           (mid-point (/ (- ww ns-len) 2))\r\n           (padding (make-string mid-point ? )))\r\n      (setq header-line-format (concat padding ns)))))\r\n\r\n(add-hook 'buffer-list-update-hook #'update-cider-scratch-header)\r\n```\r\n## Steps to reproduce the problem\r\nOpen a cider scratch buffer and do the following:\r\n```clojure\r\n(in-ns 'user) ; eval me\r\n(union #{3})  ; eval me, get a stacktrace\r\n\r\n(in-ns 'clojure.set) ; DO NOT eval this form\r\n(union #{3})  ; eval me, unexpected success!!\r\n```\r\n## Environment & Version information\r\nn/a\r\n### CIDER version information\r\nCIDER 0.12.0snapshot (package: 20160321.1158), nREPL 0.2.12\r\n;; Clojure 1.7.0, Java 1.8.0_74\r\n### Emacs version\r\n24.5.1\r\n### Operating system\r\nUbuntu Wily"},"comment":{"url":"https://api.github.com/repos/clojure-emacs/cider/issues/comments/201841990","html_url":"https://github.com/clojure-emacs/cider/issues/1633#issuecomment-201841990","issue_url":"https://api.github.com/repos/clojure-emacs/cider/issues/1633","id":201841990,"user":{"login":"Malabarba","id":453029,"avatar_url":"https://avatars.githubusercontent.com/u/453029?v=3","gravatar_id":"","url":"https://api.github.com/users/Malabarba","html_url":"https://github.com/Malabarba","followers_url":"https://api.github.com/users/Malabarba/followers","following_url":"https://api.github.com/users/Malabarba/following{/other_user}","gists_url":"https://api.github.com/users/Malabarba/gists{/gist_id}","starred_url":"https://api.github.com/users/Malabarba/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Malabarba/subscriptions","organizations_url":"https://api.github.com/users/Malabarba/orgs","repos_url":"https://api.github.com/users/Malabarba/repos","events_url":"https://api.github.com/users/Malabarba/events{/privacy}","received_events_url":"https://api.github.com/users/Malabarba/received_events","type":"User","site_admin":false},"created_at":"2016-03-26T14:54:35Z","updated_at":"2016-03-26T14:54:35Z","body":"Frankly, I don't even mind if it's on or off by default. I think having more than one ns form is pretty rare, so either behaviours are fine by me. "}}