Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Beautify selection as another language #1202

Closed
oschwald opened this issue Sep 17, 2016 · 4 comments
Closed

Beautify selection as another language #1202

oschwald opened this issue Sep 17, 2016 · 4 comments
Assignees

Comments

@oschwald
Copy link

As far as I can tell, there is no way to currently beautify a selection of code in a specific language that is different than the file's language. My primary use case for this feature would be beautifying SQL that is embedded in string literals, although I imagine it could also be useful for beautifying other embedded code or markup.

@prettydiff
Copy link
Collaborator

Could you also provide a tiny code sample? It will give us something to test against.

@oschwald
Copy link
Author

oschwald commented Sep 18, 2016

Sure, here are two made up examples where I'd like to be able to beautify the SQL within the other code.

Perl

my $sql = <<'SQL';
SELECT fname, lname 
FROM people 
WHERE id >= ? AND id < ?
SQL

my $sth = $dbh->prepare($sql);
$sth->execute(1, 10);
while (my @row = $sth->fetchrow_array) {
   print "fname: $row[0]  lname: $row[1]\n";
}

Go

package main

import (
    "database/sql"
    "log"

    _ "github.com/go-sql-driver/mysql"
)

func main() {
    var (
        id   int
        name string
    )

    db, err := sql.Open("mysql",
        "user:password@tcp(127.0.0.1:3306)/hello")
    if err != nil {
        log.Fatal(err)
    }
    defer db.Close()

    sql := `
SELECT id,
       name
FROM "user"
WHERE name='Bob'
AND   date='2014-01-10'
`

    rows, err := db.Query(sql)

    if err != nil {
        log.Fatal(err)
    }
    defer rows.Close()
    for rows.Next() {
        err := rows.Scan(&id, &name)
        if err != nil {
            log.Fatal(err)
        }
        log.Println(id, name)
    }
    err = rows.Err()
    if err != nil {
        log.Fatal(err)
    }
}

@prettydiff
Copy link
Collaborator

Perhaps a right click option Beautify As... that open a list of grammars.

@Glavin001
Copy link
Owner

Closing as duplicate of #27

@Glavin001 Glavin001 self-assigned this May 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants