Giter VIP home page Giter VIP logo

Comments (12)

DanRibbens avatar DanRibbens commented on May 28, 2024 14

@securit To set up the macro?
Preselect a block of text in your editor like a query (doesn't matter for just setting it up)
Edit -> Macros -> Start Recording
Edit -> Join Lines
Edit -> Copy
Edit -> Undo
Edit -> Macross -> Stop Recording
Give it a name to save it

Then set it a hotkey in your keymap settings:
image

Now to use the macro you just highlight everything you want to toss in to tinker and hit your new hotkey.

from tinker.

AleksandarSavic95 avatar AleksandarSavic95 commented on May 28, 2024 13

Thanks to @DanRibbens for his genius idea! 🙂 🎉
In PhpStorm, join lines command has a default shortcut - CTRL + SHIFT + J (on a mac it looks like this: ^ + ⬆️ + J ).

from tinker.

DanRibbens avatar DanRibbens commented on May 28, 2024 4

Came here trying to figure out the same issue. Instead of changing terminal input behaviour I decided to add a macro for copying joined lines. With this I can select a block of code, press the hotkey assigned to the macro, then paste in the terminal.

In PHPStorm it looks like this:
image

from tinker.

abdelaziz321 avatar abdelaziz321 commented on May 28, 2024 1

Same idea of @DanRibbens but With Atom:
we can select multiple lines and join them as one line using ctrl + j

from tinker.

bobthecow avatar bobthecow commented on May 28, 2024

Tinker does support multi-line statements.

from tinker.

GrahamCampbell avatar GrahamCampbell commented on May 28, 2024

:)

from tinker.

securit avatar securit commented on May 28, 2024

Nope!!! I always need to remove linebreaks.

>>> $d = DeviceCamera::with([
...     'device'  => function ($query) {
...         $query->select(
...             'devices.id as device_id', 'name as camera_name', 'slug as webcam_name'
...         )->groupBy('devices.id');
...     },
...     'device.device' => function ($query) {
...         $query->select(
...             'id', 'id as camera_id', 'camera_lens_type_id', 'settings',
PHP Parse error: A trailing comma is not allowed here on line 9
>>>             DB::raw("cast(settings->>'viewport_order' as int) as viewport_order")
=> Illuminate\Database\Query\Expression {#1375}
>>>         )->groupBy('id');
PHP Parse error: Syntax error, unexpected ')' on line 1
>>>     },
PHP Parse error: Syntax error, unexpected '}', expecting EOF on line 1
>>>     'deployments' => function ($query) {
PHP Parse error: Syntax error, unexpected T_DOUBLE_ARROW on line 1
>>>         $query->select(
...             'deployments.id as deployment_id', 'vessel_id'

from tinker.

bobthecow avatar bobthecow commented on May 28, 2024

Ahhhh. It lets you paste the first few lines 😄

Trailing commas in function calls, though.

I just pushed a fix to the develop branch on PsySH. Do you mind checking that out and confirming that it fixes your issue?

from tinker.

securit avatar securit commented on May 28, 2024

from tinker.

bobthecow avatar bobthecow commented on May 28, 2024

Hmm. You're getting into places that PsySH / tinker can't help you as much :)

By default PsySH doesn't require semicolons to execute code, as long as the code is syntactically complete, valid PHP. In your case, the line before ->whereHas is a valid and complete statement, so PsySH just goes for it.

If you were typing this in yourself, you wouldn't be super surprised to see that this happened, and you could just use $_->whereHas to use the return value of the last line to keep going. But in this case, you're pasting and can't adapt on the fly. Unfortunately, with PHP's libedit implementation, I don't believe it's possible to completely solve for paste.

There is this awesome thing called "bracketed paste" that might help here. It makes pasting into readline much saner. If you're using PHP-with-readline, and it's a new enough readline version, and your terminal app supports it, and the stars align just right :)

Unfortunately it often doesn't work, and when it doesn't it spews escape codes all over the place, so it's not going to be enabled by default, at least for now.

So you have a couple of options:

  1. Download the latest dev branch and add "useBracketedPaste" => true to your PsySH config.

  2. If that doesn't work, and you're using PHP with readline (not libedit)… update your .inputrc to tell readline you like to paste:

    set enable-bracketed-paste on
    

If neither of those work:

  1. Switch your coding style to end lines with -> instead of starting the next line. This will keep a given line from being syntactically complete, and will keep the input buffer open.

  2. Add slashes to the end of ambiguous lines like this to keep them from executing. In PsySH, if you end a line in \, it forces it to keep the input going on the next line. This is kind of a pain, but maybe not as much as removing all the newlines?

  3. Disable implicit semicolon support. Add "requireSemicolons" => true to your PsySH config. This will keep pastes from executing as soon as you've finished a syntactically complete line. Unfortunately, this is a global setting, so if you change it, you'll have to type 1 + 1; to get 1 + 1 to get things to execute the rest of the time.

  4. Switch to a PHP with readline instead of libedit and use bracketed paste!

from tinker.

securit avatar securit commented on May 28, 2024

from tinker.

mufeel avatar mufeel commented on May 28, 2024

within your tinker session type the keyword "edit" which would open an editor to write your code. Once your done exit out and the code will execute. You will be able to see the output

from tinker.

Related Issues (20)

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.