Code Monkey home page Code Monkey logo

multiliner's Introduction

Header image

Multiliner

An Xcode source extension to expand lengthy lines.

  • Super lightweight, it's like a script.
  • It expands long lines. That's it!
  • Works with:
    • Initializers
    • Function calls
    • Array literals
    • SwiftUI modifiers

Showcase

Multiliner.mp4

Installation

  1. Download the app directly or through Homebrew

    brew install hkamran80/things/multiliner

    Note: Multiliner requires macOS Monterey (12.3) or higher.

  2. Open the app

  3. Go to System Preferences → Extensions and check Multiliner

System Preferences

Usage

It's simple, just highlight the code that you want to format, then press EditorMultilinerFormat Selected Code. More details in the app.

Screenshot of the app

Shortcut

If you'd like to access Multiliner quicker, try adding a key binding. Go to XcodePreferencesKey Bindings, then search for "Multiliner":

Setting a key binding in Xcode

Author

Multiliner is made by aheze.

Contributing

All contributions are welcome. Just fork the repo, then make a pull request.

Need Help?

Open an issue or join the Discord server. You can also ping me on Twitter. Or read the source code, I added a bunch of comments.

License

MIT License

Copyright (c) 2022 A. Zheng

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

multiliner's People

Contributors

aheze avatar hkamran80 avatar orchetect avatar tkgka avatar weitieda avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

multiliner's Issues

How to use with macOS 13 Ventura & Xcode 14

Not an issue as I worked it out, but I thought others might look here to see how to enable this with the new System Settings app in macOS 13 Ventura.

  • Close Xcode & System Settings
  • Open the Multiliner app
  • Open System Settings
  • Go to Privacy & Security
  • Scroll down to the end and click Extensions
  • Click Xcode Source Editor and make sure Multiliner is toggled on

Now the option appears in the Xcode's Editor menu.

Add support to AppCode

I LOVE this tool and I use it literally everyday when I use Xcode, but I use AppCode a lot as well, and I really really miss it. do you think adding support to AppCode is something that can be done?

Preserve caret position after multi-lining selection

Currently, when using Multiliner to multi-line selection, the caret moves to the end of the file. When undoing, the whole file text is selected.

It would be great if the caret stays after the closing bracket of the formatted code.

I love this extension. Thank you for amazing work!

Suggestion: A second command to do the opposite - reformat a multiline function onto a single line

I'd love to have a second command that can do the opposite of Multiliner - reformat a multi-line call into a single line.

Background: Our company style guide says if a function call is under 120 chars it should be a single line, otherwise split up like Multiliner does. Often times when refactoring I'm deleting a bunch of parameters and the call would fit on a single line. I'd love a command to be able to reformat it quickly onto one line to check if it fits.

PS: This is incredible, I've been periodically searching for something like this for ages. Thank you so much for making it! You are going to save me a few minutes every day.

Syntax aware formatting

Currently when you select a chunk of code that contains parameters nested inside, formatting is weird:

Memberwise init generated by Xcode

This is because Multiliner splits parameters by commas , — this includes commas inside nested inits.

/// The text inside the braces.
let contentsString = text[openingContentIndex ..< closingContentIndex]
let contents = contentsString
.components(separatedBy: ",")

Possibly a split using Regex?

Closing parens of function returning a closure put onto wrong line

Played around with Multiliner a bit :)

Given this input:

func applyContentActions(action: AppAction, reducers: [TableActionReducer]) -> (_ documentState: DocumentState) -> DocumentState {
    ...
}

I expected somewhat along these lines::

func applyContentActions(
    action: AppAction,
    reducers: [TableActionReducer]
) -> (_ documentState: DocumentState) -> DocumentState {
    ...
}

Actual output did try to put the parens and the arrow onto a new line, but not the first occurrence:

func applyContentActions(
    action: AppAction,
    reducers: [TableActionReducer]) -> (_ documentState: DocumentState
) -> DocumentState {
    ...
}

Suggest adding key binding in Xcode, not System Preferences

Adding the keyboard shortcut via System Preferences has the downsides of being specific to each Xcode version (it seems to list every Xcode version I have installed, although I've not verified if they're all applied separately) and also requiring the exact name of the menu item.

Xcode's Preferences => Key Bindings includes the action from the menu and seems to avoid these issues, so it might be easier to direct users to using this option?

Screenshot 2022-07-11 at 23 26 15

Multiliner not showing up in Extensions

Despite having Multiliner (1.1.0) installed, it simply won't show up in System Settings -> Extensions. I've uninstalled, re-installed, restarted, etc. I'm running macOS 12.5 with Xcode 13.3.1.

Screen Shot 2022-08-12 at 9 38 55 AM

Support for brew

It would be nice to have an ability to install app using brew instead of having to do it manually.
What do you think?

p.s. awesome idea for an extension 🎉

Add preferences

That would be much better to add preferences for this utility

The most important one, as for me, to add the maximum allowed line length (e.g. 120)

If the line of code is shorter, there is no need to wrap it around and create multiple lines

With this feature, it would be possible to format the whole file, not only the selected few lines

Suggestion: add option for first parameter to be on same line

While I am actually a fan of Multiliner's current formatting behavior, some people might prefer not having a line-break between the method name and the first parameter.

Current Behavior

func sendAppStatus(
    to toNodes: [Node],
    name: String?,
    bundleID: String,
    state: Int32,
    isDockApp: Bool
) {
    // ...
}

Proposed opt-in behavior (as a preference)

First parameter starts on the same line, and closing parens trails immediately after the last parameter.

func sendAppStatus(to toNodes: [Node],
                   name: String?,
                   bundleID: String,
                   state: Int32,
                   isDockApp: Bool) {
    // ...
}

Does not support tabs indentation

If I indent with spaces:

spaces_1

result is OK:

spaces_2

But when tabs are used:

tabs_1

result is just a mess of tabs and spaces (which is never correct):

tabs_2

Update built-in docs

I just noticed that the GitHub docs / App Built-In Docs are out of sync.

  • GitHub README shows setting up a Key Binding in Xcode,
  • built-in docs of the MultilinerExtension app shows setting up an App Shortcut in System Preferences

Cheers, and thanks for your hard work

Improvement: Apply correct formatting on code with multiple lines

While it works perfectly on a one line function, if you already have code like this:

func foobar(_ foo: Foo,
                       bar: Bar)

and you apply multiliner, the result will be:

func foobar(
        _ foo: Foo,

                       bar: Bar
    )

which is not great. It would be awesome if it already detected new lines, and didn't apply new indentation. For the latter I don't know if it could re-use Xcode's reindent command for each line maybe, so you don't have to implement it yourself.

App won't install

I had v1.0 installed and working, however since installing v1.1 the Xcode Source Editor section of the System->Extensions has disappeared, as if there are no extensions.

I've tried reinstalling v1.0 and it's the same 🤷‍♂️

Is there an additional step needed?

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.