Giter Club home page Giter Club logo

cider-any's Introduction

Cider Any

Evaluate anything in cider.

Replaced by Oook

The Cider Any was replaced by Oook. We decided to get rid of the backend design of cider-any and have a simpler interface that just lets you evaluate XQuery documents.

XQuery

Installation

System requirements:

  • Clojure
  • Leiningen
  • Cider
  • Page break lines emacs lisp library
  • Uruk clojure library
  • MarkLogic server access

Load Emacs Lisp libraries in your configuration.

(require 'cider-any)
(require 'cider-any-uruk)

Enable cider-any in xquery-mode by default.

(add-hook 'xquery-mode-hook 'cider-any-mode)

Grain access to the MarkLogic account.

(setq cider-any-uruk-uri "xdbc://localhost:8889/"
      cider-any-uruk-user "proofit404"
      cider-any-uruk-password "<secret>")

Usage

Start cider repl in the leiningen project. Uruk library must be pinned in the project.clj in the dependencies section. When you hit C-c C-c XQuery buffer will be evaluated on MarkLogic server you grain access earlier. Result of this evaluation will be displayed in the buffer with corresponding major mode.

If you want to open result document in the web browser you can customize this behavior.

(setq cider-any-uruk-handler 'cider-any-uruk-browse)

cider-any's People

Contributors

proofit404 avatar hanshuebner avatar

Watchers

 avatar James Cloos avatar Dave Liepmann avatar  avatar

Forkers

m-g-r

cider-any's Issues

Name result buffer after the XQuery buffer

Instead of using *XQuery*<XX> as the name for the result buffer, with a new name assigned to each evaluation, the result buffer should be named after the XQuery buffer that has been evaluated (i.e. *XQuery-result-<name-of-xquery-buffer>*) and be overwritten for each evaluation.

Implement passing of external variables

XQuery allows the declaration of query parameters by the way of variables declared as "extern". We need to be able to set such variables when evaluating an XQuery buffer. My proposal would be:

  • When an XQuery buffer is evaluated, cider-any-uruk sends the query for analysis to a Clojure handler
  • The Clojure handler analyzes the query and returns the names of the query parameters
  • cider-any-uruk asks the user to input the values for each parameter. Previously entered parameter values should be remembered and be used by default. If the user wants to re-set the parameters, they need to use a prefix argument to C-c C-c (or something similar). Point being: By default, the XQuery should be evaluated with the previously entered parameters
  • cider-any-uruk evaluates the query, passing the parameters as function arguments to the handler.

repair hack, rewrite

Have a look at my latest commit. This has to be rewritten! I allowed myself to commit it nevertheless as it is an additional function that is only used by my newest xdbc-selector and nothing else.

The commit message is:
add a function cider-any-string->list that is basically like cider-any-string but returns a list of values.

This is seriously hackish and should be replaced as soon as possible!

See source code comments, especially:
+;; hackish without lexical let, should be improved!

  • (sleep-for 0 100) ;; ugh, cider-any-eval is asynchronous! -> BUG! -> TO FIX!

allow to give additional information to cider-any-eval

In a use case, I want to cider-any-eval a string (that contains an xquery). Now I need to pass additionally information to this call that can later be used by the display handler.

One example is the filename (or URI) in case the xquery returns a document.
(Currently, this is implemented via a hack, that is, cider-any-uruk-buffer-filename.
But this way has problems, e.g., when the XQuery actually fails cider-any-uruk-buffer-filename
will not be reset and actually used for the next successful XQuery. This is actually
a bug.) But another example, could be the information that the result of the XQuery is a
document listing. In this case, I might want to put the cursor on the line that contains the first
document URI and maybe install a key handler to retrieve this file when the user hits the
return key.

I have to admit that I should replace the display handler by a custom handler
for this latter use case (and maybe already to the file-handling stuff). But the
information passing has to happen somehow. I would propose an optional
argument for additional meta-information that is just handled through to the
display handler. Or do you have a better idea?

support empty results

Hi, cool thing! I noticed that it is not supported that an xquery might have an empty result (which is perfectly ok, if you do something like xdmp:document-load in MarkLogic).

In cider-any-uruk I get:
error in process filter: Wrong type argument: char-or-string-p, nil

Bye Max

Delimit results in a nicer way

When an XQuery returns multiple values (like "1;2;3"), they're currently delimited in the result buffer by "\n----\n". It would be nice if the delimiter was not just text, but an Emacs object that is rendered differently and also can't be edited like text.

make binary transfers work

An xquery might return a binary file (e.g., an gzip of an xml). Currently, this seems not to be handled.

Indenting if

If I enter this:

if ($facility-type = "GROUP") then

and then press TAB on the empty line (with auto-indent enabled), I would expect an indent of 2 characters, but the cursor stays flush left.

I'll write separate indentation issues for everything that I find.

cider-uruk-any fails to work with non-nil *print-length* or *print-level*

If one has non-standard settings for *print-length* or *print-level*, cider-uruk-any basically fails to work. I'm not actually sure if this can be fixed locally - Is the normal repl printing used to get the results from uruk? If that is the case, then the behavior would be hard to fix because one can't re-bind the variables that the repl has bound. If the printing is done separately, then (binding [*print-length* nil *print-level* nil] ...) should do.

multiple connection support

Hi,

I usually have several xdbc servers I want to talk to at the same time (as I want to upload to one db and see the contents of the other).

hm, maybe having a list of connections instead of just one and C-c C-c have considering arguments with C-u? Right now I work with just two connection, where one of them is just occasionally used, so it'd be nice to use the first connection as the default and be easily possible to occasionally switch to "the other connection". But it will be probably even more than just two connections, then it would be great if it is possible to address more than two connection easily.

And a pony. ;)

Cheers, Max

hook for xml pretty-printing

Hi, I currently use the function attached to pretty print xml buffers that have not even newlines (so that other auto-indentation does not work). It would be nice to have a hook somewhere in cider-any-uruk to add it. Right now, I temporarily added it to cider-any-uruk-display-buffer, but actually I would consider it to be some kind of content conversion filter that might be used regardless of the current handler (that is, in between eval and handle).

Of course, it would be nice to just call it in case of xml content, but right now cider-any seems to be content agnostic, right?

Consider this to be just a suggestion to think about! I'm not sure yet whether it is a good idea at all, to silently convert content. Maybe it is much better to just do the conversion always manually.

Thanks,
Max

nxml-pretty-format.el.txt

cider-uruk-any should be more helpful with errors

Right now, all exceptions are just printed using the standard cider exception handler:


  Show: Clojure Java REPL Tooling Duplicates All  (11 frames hidden)

1. Unhandled com.marklogic.xcc.exceptions.XQueryException
   com.marklogic.xcc.exceptions.XQueryException: XDMP-ARGTYPE:
   (err:XPTY0004)
   fn:substring((fn:doc("/tx-mpf/1597783.xml")/group/provider[1]/provider-group-membership[1]/group-tpisuffix-code,
   fn:doc("/tx-mpf/1597783.xml")/group/provider[1]/provider-group-membership[2]/group-tpisuffix-code),
   1, 7) -- arg1 is not of type xs:string?  [Session: user=restuser,
   cb=tx-mpf [ContentSource: user={none}, cb={none} [provider:
   address=localhost/127.0.0.1:8000, pool=1/64]]] [Client: XCC/8.0-5,
   Server: XDBC/8.0-4.2] in /eval, on line 19 expr:
   fn:substring((fn:doc("/tx-mpf/1597783.xml")/group/provider[1]/provider-group-membership[1]/group-tpisuffix-code,
   fn:doc("/tx-mpf/1597783.xml")/group/provider[1]/provider-group-membership[2]/group-tpisuffix-code),
   1, 7), in
   local:validate-with-tpi(fn:doc("/claims/10150330.xml")/c:claim/c:access-point/c:medicaid-id/text(),
   fn:doc("/claims/10150330.xml")/c:claim) in /eval, on line 63 expr:
   fn:substring((fn:doc("/tx-mpf/1597783.xml")/group/provider[1]/provider-group-membership[1]/group-tpisuffix-code,
   fn:doc("/tx-mpf/1597783.xml")/group/provider[1]/provider-group-membership[2]/group-tpisuffix-code),
   1, 7)

ServerExceptionHandler.java:   34  com.marklogic.xcc.impl.handlers.ServerExceptionHandler/handleResponse
EvalRequestController.java:   96  com.marklogic.xcc.impl.handlers.EvalRequestController/serverDialog

It would be nice if the XQuery stacktrace was displayed instead. and if there was an easy way to navigate to the XQuery error location from there.

Make key-bindings consistent with Cider and Slime

Hi Artem,

I think these to key-bindings are inconsistent with the bindings of other modes that we use (for Clojure and Common Lisp):

(defvar oook-mode-map
...
    (define-key map (kbd "C-c C-c") 'oook-eval-buffer)
    (define-key map (kbd "C-M-x") 'oook-eval-function)

In Cider and Slime C-c C-c is alwas eval the function / toplevel form at the cursor and C-c C-k is loading the whole buffer:

Cider (Clojure mode):

C-c C-c         cider-eval-defun-at-pointC-c C-c         cider-eval-defun-at-point
C-c C-k         cider-load-buffer

Slime (Common-Lisp mode):

C-c C-c	- Compile the top-level form at point.
C-c C-k	- Compile and load the current buffer's file.

So I'd propose to make a transition to:

    (define-key map (kbd "C-c C-k") 'oook-eval-buffer)
    (define-key map (kbd "C-c C-c") 'oook-eval-function)

Bye Max

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.