From mboxrd@z Thu Jan 1 00:00:00 1970 From: "numbchild@gmail.com" Subject: Re: [UPDATE] Re: ob-clojure evaluate error when Org-mode buffer has ns clojure code Date: Thu, 21 Dec 2017 18:15:27 +0800 Message-ID: References: <87zid7bd46.fsf@gmail.com> <87vanuayo1.fsf@gmail.com> <27402be3-a688-cd27-f7c5-f07ddff7a31c@gmail.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="001a113d54487457c80560d6fcbc" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:41270) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRxtW-0001Tn-AC for emacs-orgmode@gnu.org; Thu, 21 Dec 2017 05:16:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eRxtP-0001f7-AH for emacs-orgmode@gnu.org; Thu, 21 Dec 2017 05:16:01 -0500 Received: from mail-oi0-x235.google.com ([2607:f8b0:4003:c06::235]:39597) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eRxtP-0001eQ-1h for emacs-orgmode@gnu.org; Thu, 21 Dec 2017 05:15:59 -0500 Received: by mail-oi0-x235.google.com with SMTP id r63so16518885oia.6 for ; Thu, 21 Dec 2017 02:15:59 -0800 (PST) In-Reply-To: <27402be3-a688-cd27-f7c5-f07ddff7a31c@gmail.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: Tim Cross Cc: Org-mode --001a113d54487457c80560d6fcbc Content-Type: text/plain; charset="UTF-8" Finally found a solution. really hard. spend a lot of time on this issue. The discussion is at here: https://github.com/clojure-emacs/clojure-mode/pull/465 Here is my final source code. paste here as a copy. Hope can help someone want same thing. ;; auto start CIDER REPL session in a complete Leiningen project environment for Org-mode Babel by jack-in. (add-to-list 'org-babel-default-header-args:clojure '(:session . "*cider-repl ob-clojure*")) (progn (find-file (expand-file-name "~/.emacs.d/Org-mode/ob-clojure/src/ob_clojure/core.clj")) (cider-jack-in)) (defun ob-clojure-cider-do-not-find-ns () "Fix the issue that `cider-current-ns' try to invoke `clojure-find-ns' to extract ns from buffer." (with-current-buffer "*cider-repl ob-clojure*" (defvar ob-clojure-cider-repl-ns cider-buffer-ns) (setq-local cider-buffer-ns ob-clojuure-cider-repl-ns))) (add-hook 'org-mode-hook #'ob-clojure-cider-do-not-find-ns) [stardiviner] GPG key ID: 47C32433 IRC(freeenode): stardiviner Twitter: @numbchild Key fingerprint = 9BAA 92BC CDDD B9EF 3B36 CB99 B8C4 B8E5 47C3 2433 Blog: http://stardiviner.github.io/ On Tue, Dec 19, 2017 at 5:54 PM, stardiviner wrote: > I got new update on this issue. > > I think it is caused by `(clojure-find-ns)`. > Here is my found: > > I created a simple clojure project for used by all org-babel-clojure src > blocks. > ```elisp > (progn > (find-file (expand-file-name "~/.emacs.d/Org-mode/ob-clojur > e/src/ob_clojure/core.clj")) > (cider-jack-in)) > ``` > > I edebug the `org-babel-execute:clojure` process, > > `org-babel-execute:clojure' has a step: ~(clojure-find-ns)~ . > This is from ~clojure-mode~. It will find current clojure buffer possible > clojure namespace (even in org-mode). When I the following example org-mode > buffer, it will return "namespace-not-found" error in nrepl response dict. > Then src blcok has no error, not results. > > ```org > #+BEGIN_SRC clojure :session > (in-ns 'user-kk) > or > (ns user-kk) > #+END_SRC > > #+BEGIN_SRC clojure :results output > (print "hi") > #+END_SRC > ``` > > Here is a part of function `clojure-find-ns`: > > #+begin_src emacs-lisp > (when (or (re-search-backward clojure-namespace-name-regex nil t) > ;; Or any form at all. > (and (goto-char (point-min)) > (re-search-forward clojure-namespace-name-regex nil > t))) > (match-string-no-properties 4)) > #+end_src > > So I created an PR to disable find namespace in Org-mode buffer: > https://github.com/clojure-emacs/clojure-mode/pull/465 > --001a113d54487457c80560d6fcbc Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Finally found a solution. really hard. spend a lot of time on this issue. The discussion is at here: https://github.com/clojure-emacs/clojure-mode/pull/465= Here is my final source code. paste here as a copy. Hope can help someone= want same thing.
;; auto start CIDER REPL session in a complete Leiningen project env=
ironment for Org-mode Babel by jack-in.
(add-to-list 'org-babel-default-header-args:clojure
             '(:session . "*cider-repl ob-clojure*"))
(progn
  (find-file (expand-file-name "~/.emacs.d/Org-mode/ob-clojure/src/ob_=
clojure/core.clj"))
  (cider-jack-in))

(defun ob-clojure-cider-do-not-find-ns ()
  "Fix the issue that `cider-current-ns' try to invoke `clojure-fi=
nd-ns' to extract ns from buffer."
  (with-current-buffer "*cider-repl ob-clojure*"
    (defvar ob-clojure-cider-repl-ns cider-buffer-ns)
    (setq-local cider-buffer-ns ob-clojuure-cider-repl-ns)))
(add-hook 'org-mode-hook #'ob-clojure-cider-do-not-find-ns)
  

=
[stardiviner]=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 <Hack this world!>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 GPG = key ID: 47C32433
IRC(freeenode): stardiviner =C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0 Twitter:=C2=A0 @numbchild
Key fingerprint =3D 9BAA 92BC CDD= D B9EF 3B36=C2=A0 CB99 B8C4 B8E5 47C3 2433
Blog: http://stardiviner.github.io/
<= /div>

On Tue, Dec 19, 2017 at 5:54 PM, stardiviner= <numbchild@gmail.com> wrote:
I got new update on this issue.

I think it is caused by `(clojure-find-ns)`.
Here is my found:

I created a simple clojure project for used by all org-babel-clojure src bl= ocks.
```elisp
(progn
=C2=A0 (find-file (expand-file-name "~/.emacs.d/Org-mode/ob-clojure/src/ob_clojure/core.clj"))
=C2=A0 (cider-jack-in))
```

I edebug the `org-babel-execute:clojure` process,

`org-babel-execute:clojure' has a step: ~(clojure-find-ns)~ .
This is from ~clojure-mode~. It will find current clojure buffer possible c= lojure namespace (even in org-mode). When I the following example org-mode = buffer, it will return "namespace-not-found" error in nrepl respo= nse dict. Then src blcok has no error, not results.

```org
#+BEGIN_SRC clojure :session
(in-ns 'user-kk)
or
(ns user-kk)
#+END_SRC

#+BEGIN_SRC clojure :results output
(print "hi")
#+END_SRC
```

Here is a part of function `clojure-find-ns`:

=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 #+begin_src emacs-lisp
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (when (or (re-search-backward clojure-namesp= ace-name-regex nil t)
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 ;; Or any form at all.
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 (and (goto-char (point-min))
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (re-search-forward clojure-na= mespace-name-regex nil t)))
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (match-string-no-properties 4))<= br> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 #+end_src

So I created an PR to disable find namespace in Org-mode buffer:
https://github.com/clojure-emacs/clojure-= mode/pull/465

--001a113d54487457c80560d6fcbc--